@@ -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
5614typedef 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
0 commit comments