@@ -7,7 +7,7 @@ static VALUE rb_eClosedQueueError;
77
88/* Mutex */
99typedef struct rb_mutex_struct {
10- rb_serial_t fiber_serial ;
10+ rb_serial_t ec_serial ;
1111 VALUE thread ; // even if the fiber is collected, we might need access to the thread in mutex_free
1212 struct rb_mutex_struct * next_mutex ;
1313 struct ccan_list_head waitq ; /* protected by GVL */
@@ -81,7 +81,7 @@ static void rb_mutex_abandon_all(rb_mutex_t *mutexes);
8181static void rb_mutex_abandon_keeping_mutexes (rb_thread_t * th );
8282static void rb_mutex_abandon_locking_mutex (rb_thread_t * th );
8383#endif
84- static const char * rb_mutex_unlock_th (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t fiber_serial );
84+ static const char * rb_mutex_unlock_th (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t ec_serial );
8585
8686/*
8787 * Document-class: Thread::Mutex
@@ -125,7 +125,7 @@ rb_thread_t* rb_fiber_threadptr(const rb_fiber_t *fiber);
125125static bool
126126mutex_locked_p (rb_mutex_t * mutex )
127127{
128- return mutex -> fiber_serial != 0 ;
128+ return mutex -> ec_serial != 0 ;
129129}
130130
131131static void
@@ -221,26 +221,26 @@ thread_mutex_remove(rb_thread_t *thread, rb_mutex_t *mutex)
221221}
222222
223223static void
224- mutex_set_owner (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t fiber_serial )
224+ mutex_set_owner (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t ec_serial )
225225{
226226 mutex -> thread = th -> self ;
227- mutex -> fiber_serial = fiber_serial ;
227+ mutex -> ec_serial = ec_serial ;
228228}
229229
230230static void
231- mutex_locked (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t fiber_serial )
231+ mutex_locked (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t ec_serial )
232232{
233- mutex_set_owner (mutex , th , fiber_serial );
233+ mutex_set_owner (mutex , th , ec_serial );
234234 thread_mutex_insert (th , mutex );
235235}
236236
237237static inline bool
238- mutex_trylock (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t fiber_serial )
238+ mutex_trylock (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t ec_serial )
239239{
240- if (mutex -> fiber_serial == 0 ) {
240+ if (mutex -> ec_serial == 0 ) {
241241 RUBY_DEBUG_LOG ("%p ok" , mutex );
242242
243- mutex_locked (mutex , th , fiber_serial );
243+ mutex_locked (mutex , th , ec_serial );
244244 return true;
245245 }
246246 else {
@@ -252,7 +252,7 @@ mutex_trylock(rb_mutex_t *mutex, rb_thread_t *th, rb_serial_t fiber_serial)
252252static VALUE
253253rb_mut_trylock (rb_execution_context_t * ec , VALUE self )
254254{
255- return RBOOL (mutex_trylock (mutex_ptr (self ), ec -> thread_ptr , rb_ec_fiber_serial (ec )));
255+ return RBOOL (mutex_trylock (mutex_ptr (self ), ec -> thread_ptr , rb_ec_serial (ec )));
256256}
257257
258258VALUE
@@ -262,9 +262,9 @@ rb_mutex_trylock(VALUE self)
262262}
263263
264264static VALUE
265- mutex_owned_p (rb_serial_t fiber_serial , rb_mutex_t * mutex )
265+ mutex_owned_p (rb_serial_t ec_serial , rb_mutex_t * mutex )
266266{
267- return RBOOL (mutex -> fiber_serial == fiber_serial );
267+ return RBOOL (mutex -> ec_serial == ec_serial );
268268}
269269
270270static VALUE
@@ -305,7 +305,7 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
305305 rb_execution_context_t * ec = args -> ec ;
306306 rb_thread_t * th = ec -> thread_ptr ;
307307 rb_fiber_t * fiber = ec -> fiber_ptr ;
308- rb_serial_t fiber_serial = rb_ec_fiber_serial (ec );
308+ rb_serial_t ec_serial = rb_ec_serial (ec );
309309 rb_mutex_t * mutex = args -> mutex ;
310310 rb_atomic_t saved_ints = 0 ;
311311
@@ -315,13 +315,13 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
315315 rb_raise (rb_eThreadError , "can't be called from trap context" );
316316 }
317317
318- if (!mutex_trylock (mutex , th , fiber_serial )) {
319- if (mutex -> fiber_serial == fiber_serial ) {
318+ if (!mutex_trylock (mutex , th , ec_serial )) {
319+ if (mutex -> ec_serial == ec_serial ) {
320320 rb_raise (rb_eThreadError , "deadlock; recursive locking" );
321321 }
322322
323- while (mutex -> fiber_serial != fiber_serial ) {
324- VM_ASSERT (mutex -> fiber_serial != 0 );
323+ while (mutex -> ec_serial != ec_serial ) {
324+ VM_ASSERT (mutex -> ec_serial != 0 );
325325
326326 VALUE scheduler = rb_fiber_scheduler_current ();
327327 if (scheduler != Qnil ) {
@@ -335,8 +335,8 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
335335
336336 rb_ensure (call_rb_fiber_scheduler_block , self , delete_from_waitq , (VALUE )& sync_waiter );
337337
338- if (!mutex -> fiber_serial ) {
339- mutex_set_owner (mutex , th , fiber_serial );
338+ if (!mutex -> ec_serial ) {
339+ mutex_set_owner (mutex , th , ec_serial );
340340 }
341341 }
342342 else {
@@ -376,8 +376,8 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
376376 ccan_list_del (& sync_waiter .node );
377377
378378 // unlocked by another thread while sleeping
379- if (!mutex -> fiber_serial ) {
380- mutex_set_owner (mutex , th , fiber_serial );
379+ if (!mutex -> ec_serial ) {
380+ mutex_set_owner (mutex , th , ec_serial );
381381 }
382382
383383 rb_ractor_sleeper_threads_dec (th -> ractor );
@@ -390,13 +390,13 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
390390 if (interruptible_p ) {
391391 /* release mutex before checking for interrupts...as interrupt checking
392392 * code might call rb_raise() */
393- if (mutex -> fiber_serial == fiber_serial ) {
393+ if (mutex -> ec_serial == ec_serial ) {
394394 mutex -> thread = Qfalse ;
395- mutex -> fiber_serial = 0 ;
395+ mutex -> ec_serial = 0 ;
396396 }
397397 RUBY_VM_CHECK_INTS_BLOCKING (th -> ec ); /* may release mutex */
398- if (!mutex -> fiber_serial ) {
399- mutex_set_owner (mutex , th , fiber_serial );
398+ if (!mutex -> ec_serial ) {
399+ mutex_set_owner (mutex , th , ec_serial );
400400 }
401401 }
402402 else {
@@ -415,13 +415,13 @@ do_mutex_lock(struct mutex_args *args, int interruptible_p)
415415 }
416416
417417 if (saved_ints ) th -> ec -> interrupt_flag = saved_ints ;
418- if (mutex -> fiber_serial == fiber_serial ) mutex_locked (mutex , th , fiber_serial );
418+ if (mutex -> ec_serial == ec_serial ) mutex_locked (mutex , th , ec_serial );
419419 }
420420
421421 RUBY_DEBUG_LOG ("%p locked" , mutex );
422422
423423 // assertion
424- if (mutex_owned_p (fiber_serial , mutex ) == Qfalse ) rb_bug ("do_mutex_lock: mutex is not owned." );
424+ if (mutex_owned_p (ec_serial , mutex ) == Qfalse ) rb_bug ("do_mutex_lock: mutex is not owned." );
425425
426426 return self ;
427427}
@@ -456,7 +456,7 @@ rb_mutex_lock(VALUE self)
456456static VALUE
457457rb_mut_owned_p (rb_execution_context_t * ec , VALUE self )
458458{
459- return mutex_owned_p (rb_ec_fiber_serial (ec ), mutex_ptr (self ));
459+ return mutex_owned_p (rb_ec_serial (ec ), mutex_ptr (self ));
460460}
461461
462462VALUE
@@ -466,20 +466,20 @@ rb_mutex_owned_p(VALUE self)
466466}
467467
468468static const char *
469- rb_mutex_unlock_th (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t fiber_serial )
469+ rb_mutex_unlock_th (rb_mutex_t * mutex , rb_thread_t * th , rb_serial_t ec_serial )
470470{
471471 RUBY_DEBUG_LOG ("%p" , mutex );
472472
473- if (mutex -> fiber_serial == 0 ) {
473+ if (mutex -> ec_serial == 0 ) {
474474 return "Attempt to unlock a mutex which is not locked" ;
475475 }
476- else if (fiber_serial && mutex -> fiber_serial != fiber_serial ) {
476+ else if (ec_serial && mutex -> ec_serial != ec_serial ) {
477477 return "Attempt to unlock a mutex which is locked by another thread/fiber" ;
478478 }
479479
480480 struct sync_waiter * cur = 0 , * next ;
481481
482- mutex -> fiber_serial = 0 ;
482+ mutex -> ec_serial = 0 ;
483483 thread_mutex_remove (th , mutex );
484484
485485 ccan_list_for_each_safe (& mutex -> waitq , cur , next , node ) {
@@ -517,7 +517,7 @@ do_mutex_unlock(struct mutex_args *args)
517517 rb_mutex_t * mutex = args -> mutex ;
518518 rb_thread_t * th = rb_ec_thread_ptr (args -> ec );
519519
520- err = rb_mutex_unlock_th (mutex , th , rb_ec_fiber_serial (args -> ec ));
520+ err = rb_mutex_unlock_th (mutex , th , rb_ec_serial (args -> ec ));
521521 if (err ) rb_raise (rb_eThreadError , "%s" , err );
522522}
523523
@@ -583,7 +583,7 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes)
583583 while (mutexes ) {
584584 mutex = mutexes ;
585585 mutexes = mutex -> next_mutex ;
586- mutex -> fiber_serial = 0 ;
586+ mutex -> ec_serial = 0 ;
587587 mutex -> next_mutex = 0 ;
588588 ccan_list_head_init (& mutex -> waitq );
589589 }
0 commit comments