Skip to content

Commit c3313e3

Browse files
committed
win build...?
1 parent 9fe1064 commit c3313e3

File tree

4 files changed

+17
-37
lines changed

4 files changed

+17
-37
lines changed

jsrc/cd.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,15 @@
33
/* */
44
// emulation of Unix functions on Windows
55
#ifdef _WIN32
6-
struct timezone {
7-
int tz_minuteswest;
8-
int tz_dsttime;
9-
};
10-
116
// Tip o'hat to Michaelangel007 on StackOverflow
127
#define WIN32_LEAN_AND_MEAN
138
#include <Windows.h>
149
#include <stdint.h> // portable: uint64_t MSVC: __int64
1510

16-
// MSVC defines this in winsock2.h!?
17-
typedef struct timeval {
18-
long tv_sec;
19-
long tv_usec;
20-
} timeval;
11+
struct jtimeval { long tv_sec, tv_usec; };
12+
struct jtimezone { int tz_minuteswest, tz_dsttime; };
2113

22-
extern int gettimeofday(struct timeval * tp, struct timezone * tzp)
14+
int jgettimeofday(struct jtimeval *tp, struct jtimezone * tzp)
2315
{
2416
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
2517
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
@@ -40,4 +32,3 @@ extern int gettimeofday(struct timeval * tp, struct timezone * tzp)
4032
return 0;
4133
}
4234
#endif
43-

jsrc/ct.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ NOINLINE I johnson(I n){I johnson=0x1234; if(n<0)R n; do{johnson ^= (johnson<<1)
1414
//36ns TUNE; ~60clk on zen, ~160clk on intel; consider adding more general uarch tuning capabilities (eg for cache size)
1515
//7ns mispredict penalty (15-20clk) + mul latency (3clk)
1616

17-
#if SY_WIN32
18-
struct timezone {
19-
int tz_minuteswest;
20-
int tz_dsttime;
21-
};
22-
23-
// Tip o'hat to Michaelangel007 on StackOverflow
24-
// MSVC defines this in winsock2.h!?
25-
typedef struct timeval {
26-
long tv_sec;
27-
long tv_usec;
28-
} timeval;
29-
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
30-
#else
31-
#include <sys/time.h>
32-
#endif
33-
3417
// Extend a hashtable/data table under lock. abuf is the pointer to the block to be extended (*abuf will hold the new block address).
3518
// *alock is the lock to use. We hold a writelock on *alock on entry, but we may relinquish inside this routine.
3619
// On exit we hold the write lock UNLESS there was an error, in which case we return NOT holding the lock (to allow the caller to abort on error)
@@ -241,8 +224,8 @@ A jtpyxval(J jt,A pyx){A res; C errcode;
241224
if(unlikely(maxtime<tod())){errcode=EVTIME; break;} // timeout: fail the pyx and exit
242225
pthread_mutex_lock(&((PYXBLOK*)AAV0(pyx))->pyxwb.mutex);
243226
if((res=__atomic_load_n(&((PYXBLOK*)AAV0(pyx))->pyxvalue,__ATOMIC_ACQUIRE))==0&&(errcode=__atomic_load_n(&((PYXBLOK*)AAV0(pyx))->errcode,__ATOMIC_ACQUIRE))==0){
244-
struct timeval nowtime;
245-
gettimeofday(&nowtime,0); // system time now
227+
struct jtimeval nowtime;
228+
jgettimeofday(&nowtime,0); // system time now
246229
I tousec=nowtime.tv_usec+200000;
247230
struct timespec endtime={nowtime.tv_usec+(tousec>=1000000),tousec-1000000*(tousec>=1000000)}; // system time when we give up. The struct says it uses nsec but it seems to use usec
248231
pthread_cond_timedwait(&((PYXBLOK*)AAV0(pyx))->pyxwb.cond,&((PYXBLOK*)AAV0(pyx))->pyxwb.mutex,&endtime);

jsrc/j.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ extern unsigned int __cdecl _clearfp (void);
405405
#endif
406406
#endif
407407

408+
#if SY_WIN32
409+
struct jtimeval { long tv_sec, tv_usec; };
410+
struct jtimezone { int tz_minuteswest, tz_dsttime; };
411+
int jgettimeofday(struct jtimeval*, struct jtimezone*);
412+
#else
413+
#include <sys/time.h>
414+
#define jtimeval timeval
415+
#define jtimezone timezone
416+
#define jgettimeofday gettimeofday
417+
#endif
418+
408419
#if SY_64
409420
#if defined(MMSC_VER) // SY_WIN32
410421
// RESTRICTI (for in-place) is used for things like *z++=*x++ - *y++; Normally you wouldn't store to a z unless you were done reading
@@ -2256,4 +2267,3 @@ extern uint32_t crc32csb4(uint32_t crc, uint32_t value);
22562267
#endif
22572268
#define CRC32LL CRC32L // takes UIL (8 bytes), return UI
22582269
#endif
2259-

jsrc/mt.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ static inline C jtpthread_mutex_lock(J jt,jtpthread_mutex_t *m,I self){
1919
R EVFACE;}
2020
static inline I jtpthread_mutex_timedlock(J jt,jtpthread_mutex_t *m,UI ns,I self){
2121
#if SY_WIN32
22-
// Tip o'hat to Michaelangel007 on StackOverflow
23-
// MSVC defines this in winsock2.h!?
24-
struct timeval { long tv_sec; long tv_usec; }; struct timezone;
25-
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
26-
struct timeval now;gettimeofday(&now,0);
22+
struct jtimeval now;jgettimeofday(&now,0);
2723
struct timespec t;
2824
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;}
2925
#else

0 commit comments

Comments
 (0)