Skip to content

Commit b44200d

Browse files
committed
Merge branch 'master' of jsoftware.com:jsource
2 parents 27811d5 + d0b8fa6 commit b44200d

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

jsrc/j.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,12 +1943,12 @@ if(likely(type _i<3)){z=(I)&oneone; z=type _i>1?(I)_zzt:z; _zzt=type _i<1?(I*)z:
19431943
#include "ja.h"
19441944
#include "jc.h"
19451945
#include "jtype.h"
1946-
#include "mt.h"
1946+
#include "jerr.h"
19471947
#include "m.h"
19481948
#include "jt.h"
1949+
#include "mt.h"
19491950
#include "jlib.h"
19501951
#include "je.h"
1951-
#include "jerr.h"
19521952
#include "va.h"
19531953
#include "vq.h"
19541954
#include "vx.h"

jsrc/mt.h

Lines changed: 21 additions & 1 deletion
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,15 +32,21 @@ 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;
2646
if(r==EDEADLK)R EVCONCURRENCY;
2747
R EVFACE;}
2848
static inline I jtpthread_mutex_trylock(jtpthread_mutex_t *m,I self){
29-
I4 r=pthread_mutex_timedlock(m);
49+
I4 r=pthread_mutex_trylock(m);
3050
if(!r)R 0;
3151
if(r==ETIMEDOUT)R -1;
3252
if(r==EDEADLK||r==EOWNERDEAD)R EVCONCURRENCY;

0 commit comments

Comments
 (0)