Skip to content

Commit d0b8fa6

Browse files
committed
win build?
1 parent c448502 commit d0b8fa6

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

jsrc/mt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
#if PYXES
55
#ifndef __APPLE__
66
#include <pthread.h>
7+
#if SY_WIN32
8+
struct timezone {
9+
int tz_minuteswest;
10+
int tz_dsttime;
11+
};
12+
13+
// Tip o'hat to Michaelangel007 on StackOverflow
14+
// MSVC defines this in winsock2.h!?
15+
typedef struct timeval {
16+
long tv_sec;
17+
long tv_usec;
18+
} timeval;
19+
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
20+
#endif
721
typedef pthread_mutex_t jtpthread_mutex_t;
822
static inline void jtpthread_mutex_init(jtpthread_mutex_t *m,B recursive){
923
if(likely(!recursive)){pthread_mutex_init(m,0);}
@@ -18,8 +32,14 @@ static inline C jtpthread_mutex_lock(J jt,jtpthread_mutex_t *m,I self){
1832
if(r==EDEADLK)R EVCONCURRENCY;
1933
R EVFACE;}
2034
static inline I jtpthread_mutex_timedlock(J jt,jtpthread_mutex_t *m,UI ns,I self){
35+
#if _WIN32
36+
struct timeval now;gettimeofday(&now,0);
37+
struct timespec t;
38+
t.tv_sec=now.tv_sec+ns/1000000000;t.tv_nsec=1000*now.tv_usec+ns%1000000000;if(t.tv_nsec>=1000000000){t.tv_sec++;t.tv_nsec-=1000000000;}
39+
#else
2140
struct timespec t;clock_gettime(CLOCK_REALTIME,&t);
2241
t.tv_sec+=ns/1000000000;t.tv_nsec+=ns%1000000000;if(t.tv_nsec>=1000000000){t.tv_sec++;t.tv_nsec-=1000000000;}
42+
#endif
2343
I4 r=pthread_mutex_timedlock(m,&t);
2444
if(r==0)R 0;
2545
if(r==ETIMEDOUT)R -1;

0 commit comments

Comments
 (0)