5 #include <9p-mixp/err.h>
6 #include "mixp_local.h"
7 #include "mixp_pthread.h"
9 static MIXP_THREAD ixp_pthread
;
10 static pthread_key_t errstr_k
;
16 ret
= pthread_key_create(&errstr_k
, free
);
18 mixp_werrstr("can't create TLS value: %s", mixp_errbuf());
22 mixp_thread
= &ixp_pthread
;
30 ret
= pthread_getspecific(errstr_k
);
32 ret
= calloc(1,IXP_ERRMAX
);
33 pthread_setspecific(errstr_k
, (void*)ret
);
39 mlock(MIXP_MUTEX
*m
) {
40 pthread_mutex_lock(m
->aux
);
44 mcanlock(MIXP_MUTEX
*m
) {
45 return !pthread_mutex_trylock(m
->aux
);
49 munlock(MIXP_MUTEX
*m
) {
50 pthread_mutex_unlock(m
->aux
);
54 mdestroy(MIXP_MUTEX
*m
) {
55 pthread_mutex_destroy(m
->aux
);
60 initmutex(MIXP_MUTEX
*m
) {
61 pthread_mutex_t
*mutex
;
63 mutex
= calloc(1,sizeof *mutex
);
64 if(pthread_mutex_init(mutex
, NULL
)) {
74 rlock(MIXP_RWLOCK
*rw
) {
75 pthread_rwlock_rdlock(rw
->aux
);
79 canrlock(MIXP_RWLOCK
*rw
) {
80 return !pthread_rwlock_tryrdlock(rw
->aux
);
84 wlock(MIXP_RWLOCK
*rw
) {
85 pthread_rwlock_rdlock(rw
->aux
);
89 canwlock(MIXP_RWLOCK
*rw
) {
90 return !pthread_rwlock_tryrdlock(rw
->aux
);
94 rwunlock(MIXP_RWLOCK
*rw
) {
95 pthread_rwlock_unlock(rw
->aux
);
99 rwdestroy(MIXP_RWLOCK
*rw
) {
100 pthread_rwlock_destroy(rw
->aux
);
105 initrwlock(MIXP_RWLOCK
*rw
) {
106 pthread_rwlock_t
*rwlock
;
108 rwlock
= calloc(1,sizeof *rwlock
);
109 if(pthread_rwlock_init(rwlock
, NULL
)) {
119 rsleep(MIXP_RENDEZ
*r
) {
120 pthread_cond_wait(r
->aux
, r
->mutex
->aux
);
124 rwake(MIXP_RENDEZ
*r
) {
125 pthread_cond_signal(r
->aux
);
130 rwakeall(MIXP_RENDEZ
*r
) {
131 pthread_cond_broadcast(r
->aux
);
136 rdestroy(MIXP_RENDEZ
*r
) {
137 pthread_cond_destroy(r
->aux
);
142 initrendez(MIXP_RENDEZ
*r
) {
143 pthread_cond_t
*cond
;
145 cond
= calloc(1,sizeof *cond
);
146 if(pthread_cond_init(cond
, NULL
)) {
155 static MIXP_THREAD ixp_pthread
= {
157 .initmutex
= initmutex
,
161 .mdestroy
= mdestroy
,
163 .initrwlock
= initrwlock
,
165 .canrlock
= canrlock
,
167 .canwlock
= canwlock
,
170 .rwdestroy
= rwdestroy
,
172 .initrendez
= initrendez
,
176 .rdestroy
= rdestroy
,