@@ -431,14 +431,14 @@ int game_mode_context_register(GameModeContext *self, pid_t client, pid_t reques
431431 /* Update the list */
432432 cl -> next = self -> client ;
433433 self -> client = cl ;
434- pthread_rwlock_unlock (& self -> rwlock );
435434
436435 /* First add, init */
437436 if (atomic_fetch_add_explicit (& self -> refcount , 1 , memory_order_seq_cst ) == 0 ) {
438437 game_mode_context_enter (self );
439438 }
440439
441440 game_mode_apply_client_optimisations (self , client );
441+ pthread_rwlock_unlock (& self -> rwlock );
442442
443443 game_mode_client_count_changed ();
444444
@@ -517,7 +517,6 @@ int game_mode_context_unregister(GameModeContext *self, pid_t client, pid_t requ
517517 }
518518
519519 /* Unlock here, potentially yielding */
520- pthread_rwlock_unlock (& self -> rwlock );
521520
522521 if (!found ) {
523522 LOG_HINTED (
@@ -528,6 +527,7 @@ int game_mode_context_unregister(GameModeContext *self, pid_t client, pid_t requ
528527 " -- with a nearby 'Removing expired game' which means we cleaned up properly\n"
529528 " -- (we will log this event). This hint will be displayed only once.\n" ,
530529 client );
530+ pthread_rwlock_unlock (& self -> rwlock );
531531 return -1 ;
532532 }
533533
@@ -536,10 +536,12 @@ int game_mode_context_unregister(GameModeContext *self, pid_t client, pid_t requ
536536 game_mode_context_leave (self );
537537 }
538538
539- game_mode_client_count_changed ();
540-
541539 game_mode_remove_client_optimisations (self , client );
542540
541+ pthread_rwlock_unlock (& self -> rwlock );
542+
543+ game_mode_client_count_changed ();
544+
543545 return 0 ;
544546}
545547
0 commit comments