You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//values for mutex->v. The upper 16 bits are a wait counter; the state is the low 16 bits, as follows
127
130
//todo consider storing owner in the high bits of v
128
131
enum{
@@ -152,7 +155,7 @@ C jtpthread_mutex_lock(J jt,jtpthread_mutex_t *m,I self){ //lock m; self is thre
152
155
//ulrich drepper 'futexes are tricky' explains the issue with storing a waiter count in the value
153
156
//a couple of alternatives suggest themselves: store up to k waiters (FREE/LOCK/WAIT is really 0/1/n; we could do eg 0/1/2/3/n); store the waiter count somehow outside of the value
154
157
// Before waiting, handle system events if present
155
-
UI4waitval=m->v; Cbreakb; // get the serial number before we check
158
+
UI4waitval=lda(&m->v); Cbreakb; // get the serial number before we check. Must be atomic; this is supposed to synchronise with writes to the same location via futexwt by wakeall
156
159
if(unlikely(BETWEENC(lda(&JT(jt,systemlock)),1,2))){jtsystemlockaccept(jt,LOCKALL);} // if system lock requested, accept it
157
160
// the user may be requesting a BREAK interrupt for deadlock or other slow execution
158
161
if(unlikely((breakb=lda(&JT(jt,adbreak)[0])))!=0){r=breakb==1?EVATTN:EVBREAK;goto fail;} // JBREAK: give up on the pyx and exit
@@ -167,10 +170,10 @@ C jtpthread_mutex_lock(J jt,jtpthread_mutex_t *m,I self){ //lock m; self is thre
sta(&jt->futexwt,0); while(lda(&JT(jt,wakeallct)))YIELD; // remove wakeup to this thread; if wakeup in progress, wait till it finishes
173
+
clrfutexwt(jt);
171
174
}
172
175
m->ct+=m->recursive;m->owner=self;R0; // install ownership info, good return
173
-
fail:sta(&jt->futexwt,0); while(lda(&JT(jt,wakeallct)))YIELD; Rr;} // error return, with our internal errorcode
176
+
fail:clrfutexwt(jt); Rr;} // error return, with our internal errorcode
174
177
175
178
176
179
// return positive error code, 0 if got lock, -1 if lock timed out
@@ -181,18 +184,18 @@ I jtpthread_mutex_timedlock(J jt,jtpthread_mutex_t *m,UI ns,I self){ //lock m, w
181
184
structjtimespectgt=jtmtil(ns);
182
185
sta(&jt->futexwt,&m->v); //ensure other threads know how to wake us up for systemlock
183
186
while(xchga((US*)&m->v,WAIT)!=FREE){ //exit when _we_ successfully installed WAIT in place of FREE
184
-
UI4waitval=m->v; Cbreakb; // get the serial number before we check
187
+
UI4waitval=lda(&m->v); Cbreakb; // get the serial number before we check. Must be atomic; this is supposed to synchronise with writes to the same location via futexwt by wakeall
0 commit comments