diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2018-07-02 20:14:31 +0100 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2018-08-28 18:57:22 +0100 |
commit | 440e6736fe136ab79d9e2f9236e33f4557aa47aa (patch) | |
tree | 5ee4d84d5220f8713df361f4e63cfeba979624c5 | |
parent | 140258abeaa9584e3a5996b0788ab9d7b838d1d1 (diff) |
os: Use 64-bit tick count on Windows
On Windows, GetTickCount() returns a value that wraps after 49.7 days.
Windows Vista and later offer GetTickCount64(), which does not have that
issue.
In places that can make use of more than 32 bits from the tick counter, use
a 64-bit counter.
Based on a patch by Jeff Smith <whydoubt@gmail.com>
Also include Xwindows.h to make prototype available
Unfortunately, the variable LockFile collides with a Win32 API function of
the same name, so rename it slightly.
-rw-r--r-- | os/utils.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/os/utils.c b/os/utils.c index a04cc7da7..eb2c3b8e8 100644 --- a/os/utils.c +++ b/os/utils.c @@ -55,11 +55,10 @@ OR PERFORMANCE OF THIS SOFTWARE. #ifdef __CYGWIN__ #include <stdlib.h> #include <signal.h> -/* - Sigh... We really need a prototype for this to know it is stdcall, - but #include-ing <windows.h> here is not a good idea... -*/ -__stdcall unsigned long GetTickCount(void); +#define _WIN32_WINNT 0x0600 +#include <X11/Xwindows.h> +#include <assert.h> /* defines made by windows.h prevent misc.h from including assert.h */ +#undef WIN32 /* for the benefit of the conditionals in this file */ #endif #if defined(WIN32) && !defined(__CYGWIN__) @@ -249,7 +248,7 @@ UnlockServer(void) {} #else /* LOCK_SERVER */ static Bool StillLocking = FALSE; -static char LockFile[PATH_MAX]; +static char lockFile[PATH_MAX]; Bool nolock = FALSE; /* @@ -276,10 +275,10 @@ LockServer(void) len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) : strlen(LOCK_TMP_PREFIX); len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1; - if (len > sizeof(LockFile)) + if (len > sizeof(lockFile)) FatalError("Display name `%s' is too long\n", port); (void) sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port); - (void) sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); + (void) sprintf(lockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port); /* * Create a temporary file containing our PID. Attempt three times @@ -322,7 +321,7 @@ LockServer(void) i = 0; haslock = 0; while ((!haslock) && (i++ < 3)) { - haslock = (link(tmp, LockFile) == 0); + haslock = (link(tmp, lockFile) == 0); if (haslock) { /* * We're done. @@ -333,17 +332,17 @@ LockServer(void) /* * Read the pid from the existing file */ - lfd = open(LockFile, O_RDONLY | O_NOFOLLOW); + lfd = open(lockFile, O_RDONLY | O_NOFOLLOW); if (lfd < 0) { unlink(tmp); - FatalError("Can't read lock file %s\n", LockFile); + FatalError("Can't read lock file %s\n", lockFile); } pid_str[0] = '\0'; if (read(lfd, pid_str, 11) != 11) { /* * Bogus lock file. */ - unlink(LockFile); + unlink(lockFile); close(lfd); continue; } @@ -360,7 +359,7 @@ LockServer(void) /* * Stale lock file. */ - unlink(LockFile); + unlink(lockFile); continue; } else if (((t < 0) && (errno == EPERM)) || (t == 0)) { @@ -371,13 +370,13 @@ LockServer(void) FatalError ("Server is already active for display %s\n%s %s\n%s\n", port, "\tIf this server is no longer running, remove", - LockFile, "\tand start again."); + lockFile, "\tand start again."); } } } unlink(tmp); if (!haslock) - FatalError("Could not create server lock file: %s\n", LockFile); + FatalError("Could not create server lock file: %s\n", lockFile); StillLocking = FALSE; } @@ -393,7 +392,7 @@ UnlockServer(void) if (!StillLocking) { - (void) unlink(LockFile); + (void) unlink(lockFile); } } #endif /* LOCK_SERVER */ @@ -449,7 +448,7 @@ GetTimeInMillis(void) CARD64 GetTimeInMicros(void) { - return (CARD64) GetTickCount() * 1000; + return (CARD64) GetTickCount64() * 1000; } #else CARD32 |