summaryrefslogtreecommitdiff
path: root/win32/time.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2004-07-29 02:59:44 +0000
committerWez Furlong <wez@php.net>2004-07-29 02:59:44 +0000
commitcde7423cde3c8c2c3e28ceb108485a6c67f2bf0a (patch)
tree4dd09505a39b3da287575bedc2ad4b9e9ccfc55e /win32/time.c
parentc7f22e5aca1e7e4a8c08a16cbae213e122c2f166 (diff)
downloadphp-git-cde7423cde3c8c2c3e28ceb108485a6c67f2bf0a.tar.gz
Misc. win32 thread safety fixes.
Diffstat (limited to 'win32/time.c')
-rw-r--r--win32/time.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/win32/time.c b/win32/time.c
index 9a3e004a4d..693f074185 100644
--- a/win32/time.c
+++ b/win32/time.c
@@ -33,6 +33,7 @@
#include <winbase.h>
#include <mmsystem.h>
#include <errno.h>
+#include "php_win32_globals.h"
int getfilesystemtime(struct timeval *time_Info)
{
@@ -51,64 +52,61 @@ __int64 ff;
PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Info)
{
-
- static struct timeval starttime = {0, 0};
- static __int64 lasttime = 0;
- static __int64 freq = 0;
__int64 timer;
LARGE_INTEGER li;
BOOL b;
double dt;
+ TSRMLS_FETCH();
/* Get the time, if they want it */
if (time_Info != NULL) {
- if (starttime.tv_sec == 0) {
+ if (PW32G(starttime).tv_sec == 0) {
b = QueryPerformanceFrequency(&li);
if (!b) {
- starttime.tv_sec = -1;
+ PW32G(starttime).tv_sec = -1;
}
else {
- freq = li.QuadPart;
+ PW32G(freq) = li.QuadPart;
b = QueryPerformanceCounter(&li);
if (!b) {
- starttime.tv_sec = -1;
+ PW32G(starttime).tv_sec = -1;
}
else {
- getfilesystemtime(&starttime);
+ getfilesystemtime(&PW32G(starttime));
timer = li.QuadPart;
- dt = (double)timer/freq;
- starttime.tv_usec -= (int)((dt-(int)dt)*1000000);
- if (starttime.tv_usec < 0) {
- starttime.tv_usec += 1000000;
- --starttime.tv_sec;
+ dt = (double)timer/PW32G(freq);
+ PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000);
+ if (PW32G(starttime).tv_usec < 0) {
+ PW32G(starttime).tv_usec += 1000000;
+ --PW32G(starttime).tv_sec;
}
- starttime.tv_sec -= (int)dt;
+ PW32G(starttime).tv_sec -= (int)dt;
}
}
}
- if (starttime.tv_sec > 0) {
+ if (PW32G(starttime).tv_sec > 0) {
b = QueryPerformanceCounter(&li);
if (!b) {
- starttime.tv_sec = -1;
+ PW32G(starttime).tv_sec = -1;
}
else {
timer = li.QuadPart;
- if (timer < lasttime) {
+ if (timer < PW32G(lasttime)) {
getfilesystemtime(time_Info);
- dt = (double)timer/freq;
- starttime = *time_Info;
- starttime.tv_usec -= (int)((dt-(int)dt)*1000000);
- if (starttime.tv_usec < 0) {
- starttime.tv_usec += 1000000;
- --starttime.tv_sec;
+ dt = (double)timer/PW32G(freq);
+ PW32G(starttime) = *time_Info;
+ PW32G(starttime).tv_usec -= (int)((dt-(int)dt)*1000000);
+ if (PW32G(starttime).tv_usec < 0) {
+ PW32G(starttime).tv_usec += 1000000;
+ --PW32G(starttime).tv_sec;
}
- starttime.tv_sec -= (int)dt;
+ PW32G(starttime).tv_sec -= (int)dt;
}
else {
- lasttime = timer;
- dt = (double)timer/freq;
- time_Info->tv_sec = starttime.tv_sec + (int)dt;
- time_Info->tv_usec = starttime.tv_usec + (int)((dt-(int)dt)*1000000);
+ PW32G(lasttime) = timer;
+ dt = (double)timer/PW32G(freq);
+ time_Info->tv_sec = PW32G(starttime).tv_sec + (int)dt;
+ time_Info->tv_usec = PW32G(starttime).tv_usec + (int)((dt-(int)dt)*1000000);
if (time_Info->tv_usec > 1000000) {
time_Info->tv_usec -= 1000000;
++time_Info->tv_sec;
@@ -116,7 +114,7 @@ PHPAPI int gettimeofday(struct timeval *time_Info, struct timezone *timezone_Inf
}
}
}
- if (starttime.tv_sec < 0) {
+ if (PW32G(starttime).tv_sec < 0) {
getfilesystemtime(time_Info);
}
@@ -144,6 +142,7 @@ void usleep(unsigned int useconds)
CloseHandle(timer);
}
+#if 0 /* looks pretty ropey in here */
#ifdef HAVE_SETITIMER
@@ -225,3 +224,5 @@ PHPAPI int setitimer(int which, const struct itimerval *value, struct itimerval
}
#endif
+#endif
+