Skip to content

Commit c6377af

Browse files
committed
windows
1 parent 4e9a0aa commit c6377af

File tree

8 files changed

+18
-55
lines changed

8 files changed

+18
-55
lines changed

jsrc/cd.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define WIN32_LEAN_AND_MEAN
88
#include <Windows.h>
99
#include <stdint.h> // portable: uint64_t MSVC: __int64
10+
#include "jerr.h"
1011

1112
struct jtimespec { long long tv_sec, tv_nsec; };
1213
struct jtimeval { long long tv_sec, tv_usec; };
@@ -36,8 +37,17 @@ int jgettimeofday(struct jtimeval *tp, struct jtimezone * tzp)
3637
//monotonic clock
3738
//alternative is QueryPerformanceCounter; it probably uses rdtsc, which is stable on recent processors, but it gives inconsistent results when the processor goes to sleep
3839
struct jtimespec jmtclk(){
39-
UI t=GetTickCount64();
40-
R(struct jtimeval){.tv_sec=t/1000,.tv_nsec=1000000*(t%1000)};}
40+
long long t=GetTickCount64();
41+
return (struct jtimespec){.tv_sec=t/1000,.tv_nsec=1000000*(t%1000)};}
42+
43+
void jfutex_wake1(unsigned *p){WakeByAddressSingle(p);}
44+
void jfutex_wakea(unsigned *p){WakeByAddressAll(p);}
45+
unsigned char jfutex_wait(unsigned *p,unsigned v){return WaitOnAddress(p,&v,4,INFINITE)?0:EVFACE;}
46+
long long jfutex_waitn(unsigned *p,unsigned v,unsigned long long ns){
47+
if(WaitOnAddress(p,&v,4,ns/1000000))return 0;
48+
if(GetLastError()==ERROR_TIMEOUT)return -1;
49+
//is there EINTR on windows? Does it manifest as a spurious wake with no error?
50+
return EVFACE;}
4151
#else
4252
#include"j.h"
4353
struct jtimespec jmtclk(){struct timespec r; clock_gettime(CLOCK_MONOTONIC,&r);R r;}

jsrc/mt.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,7 @@ I jfutex_waitn(UI4 *p,UI4 v,UI ns){
101101
if(r==-EAGAIN||r==-EINTR)R 0;
102102
R EVFACE;}
103103
#elif defined(_WIN32)
104-
#define WIN32_LEAN_AND_MEAN
105-
#include <windows.h>
106-
void jfutex_wake1(UI4 *p){WakeByAddressSingle(p);}
107-
void jfutex_wakea(UI4 *p){WakeByAddressAll(p);}
108-
C jfutex_wait(UI4 *p,UI4 v){R WaitOnAddress(p,&v,4,INFINITE)?0:EVFACE;}
109-
I jfutex_waitn(UI4 *p,UI4 v,UI ns){
110-
if(WaitOnAddress(p,&v,4,ns/1000000))R 0;
111-
if(GetLastError()==ERROR_TIMEOUT)R -1;
112-
//is there EINTR on windows? Does it manifest as a spurious wake with no error?
113-
R EVFACE;}
104+
// defined in cd.c to avoid name collisions between j.h and windows.h
114105
#endif
115106

116107
#if defined(__APPLE__) || defined(__linux__)

jsrc/mt.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,6 @@ __attribute__((cold)) I jfutex_waitn(UI4 *p,UI4 v,UI ns); //ditto, but wake up a
1111
__attribute__((cold)) void jfutex_wake1(UI4 *p); //wake 1 thread waiting on p
1212
__attribute__((cold)) void jfutex_wakea(UI4 *p); //wake all threads waiting on p
1313

14-
#if !defined(__APPLE__) && !defined(__linux__)
15-
#include <pthread.h>
16-
typedef pthread_mutex_t jtpthread_mutex_t;
17-
static inline void jtpthread_mutex_init(jtpthread_mutex_t *m,B recursive){
18-
if(likely(!recursive)){pthread_mutex_init(m,0);}
19-
else{
20-
pthread_mutexattr_t attr;
21-
pthread_mutexattr_init(&attr);
22-
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
23-
pthread_mutex_init(m,&attr);}}
24-
static inline C jtpthread_mutex_lock(J jt,jtpthread_mutex_t *m,I self){
25-
I4 r=pthread_mutex_lock(m);
26-
if(likely(r==0))R 0;
27-
if(r==EDEADLK)R EVCONCURRENCY;
28-
R EVFACE;}
29-
static inline I jtpthread_mutex_timedlock(J jt,jtpthread_mutex_t *m,UI ns,I self){
30-
#if SY_WIN32
31-
struct jtimeval now;jgettimeofday(&now,0);
32-
struct timespec t;
33-
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;}
34-
#else
35-
struct timespec t;clock_gettime(CLOCK_REALTIME,&t);
36-
t.tv_sec+=ns/1000000000;t.tv_nsec+=ns%1000000000;if(t.tv_nsec>=1000000000){t.tv_sec++;t.tv_nsec-=1000000000;}
37-
#endif
38-
I4 r=pthread_mutex_timedlock(m,&t);
39-
if(r==0)R 0;
40-
if(r==ETIMEDOUT)R -1;
41-
if(r==EDEADLK)R EVCONCURRENCY;
42-
R EVFACE;}
43-
static inline I jtpthread_mutex_trylock(jtpthread_mutex_t *m,I self){
44-
I4 r=pthread_mutex_trylock(m);
45-
if(!r)R 0;
46-
if(r==EBUSY)R -1;
47-
if(r==EAGAIN)R EVLIMIT; //'max recursive locks exceeded'
48-
if(r==EDEADLK||r==EOWNERDEAD)R EVCONCURRENCY;
49-
R EVFACE;}
50-
static inline C jtpthread_mutex_unlock(jtpthread_mutex_t *m,I self){
51-
I4 r=pthread_mutex_unlock(m);
52-
if(likely(!r))R 0;
53-
if(r==EPERM)R EVCONCURRENCY;
54-
R EVFACE;}
55-
#else
5614
typedef struct {
5715
B recursive;
5816
I owner; //user-provided; task id
@@ -107,5 +65,4 @@ extern int __ulock_wake(uint32_t operation, void *addr, uint64_t wake_value);
10765
// untested windows path; make henry test it when he gets back from vacation
10866
// don't pollute everybody with windows.h. win api is fairly basic anyway, so there is not much to take advantage of
10967
#endif //_WIN32
110-
#endif //__APPLE__ || __linux__
11168
#endif //PYXES

makemsvc/jdll/makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ OBJS= \
202202
../../jsrc/xu.o \
203203
../../jsrc/crc32c.o \
204204
../../jsrc/str.o \
205+
../../jsrc/mt.o \
205206
../../jsrc/openssl/sha/keccak1600.o \
206207
../../jsrc/openssl/sha/md4_dgst.o \
207208
../../jsrc/openssl/sha/md4_one.o \

makemsvc/jdll/makefile.win

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ OBJS= \
202202
../../jsrc/xu.o \
203203
../../jsrc/crc32c.o \
204204
../../jsrc/str.o \
205+
../../jsrc/mt.o \
205206
../../jsrc/openssl/sha/keccak1600.o \
206207
../../jsrc/openssl/sha/md4_dgst.o \
207208
../../jsrc/openssl/sha/md4_one.o \

makevs/jdll/template/jdll_vs2013.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@
11881188
<ClCompile Include="..\..\jsrc\xu.c" />
11891189
<ClCompile Include="..\..\jsrc\crc32c.c" />
11901190
<ClCompile Include="..\..\jsrc\str.c" />
1191+
<ClCompile Include="..\..\jsrc\mt.c" />
11911192
<ClCompile Include="..\..\jsrc\openssl\sha\keccak1600.c" />
11921193
<ClCompile Include="..\..\jsrc\openssl\sha\md4_dgst.c" />
11931194
<ClCompile Include="..\..\jsrc\openssl\sha\md4_one.c" />

makevs/jdll/template/jdll_vs2019.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@
11941194
<ClCompile Include="..\..\jsrc\xu.c" />
11951195
<ClCompile Include="..\..\jsrc\crc32c.c" />
11961196
<ClCompile Include="..\..\jsrc\str.c" />
1197+
<ClCompile Include="..\..\jsrc\mt.c" />
11971198
<ClCompile Include="..\..\jsrc\openssl\sha\keccak1600.c" />
11981199
<ClCompile Include="..\..\jsrc\openssl\sha\md4_dgst.c" />
11991200
<ClCompile Include="..\..\jsrc\openssl\sha\md4_one.c" />

makevs/jdll/template/jdll_vs2019_clang.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ copy $(outdir)$(targetname).dll $(userprofile)\jbld\j64\bin\javx2.dll</Command>
13091309
<ClCompile Include="..\..\jsrc\xu.c" />
13101310
<ClCompile Include="..\..\jsrc\crc32c.c" />
13111311
<ClCompile Include="..\..\jsrc\str.c" />
1312+
<ClCompile Include="..\..\jsrc\mt.c" />
13121313
<ClCompile Include="..\..\jsrc\openssl\sha\keccak1600.c" />
13131314
<ClCompile Include="..\..\jsrc\openssl\sha\md4_dgst.c" />
13141315
<ClCompile Include="..\..\jsrc\openssl\sha\md4_one.c" />

0 commit comments

Comments
 (0)