redmine

[hllock] fixed a potential deadlock based on race condition

@@ -342,6 +342,7 @@ volatile struct hl_lock *hl_lock_p; @@ -342,6 +342,7 @@ volatile struct hl_lock *hl_lock_p;
342 static inline void hl_lock_init(volatile struct hl_lock *hl_lock_p) { 342 static inline void hl_lock_init(volatile struct hl_lock *hl_lock_p) {
343 debug(10, ""); 343 debug(10, "");
344 hl_lock_p->enabled = 1; 344 hl_lock_p->enabled = 1;
  345 + hl_lock_p->locallock_hl_setstate_ifstate = 1;
345 # ifdef HL_LOCK_TRIES_AUTO 346 # ifdef HL_LOCK_TRIES_AUTO
346 int i; 347 int i;
347 i = 0; 348 i = 0;
@@ -730,26 +731,17 @@ int hl_setstate_ifstate(int lockid, hllock_state_t stateid_new, hllock_state_t s @@ -730,26 +731,17 @@ int hl_setstate_ifstate(int lockid, hllock_state_t stateid_new, hllock_state_t s
730 volatile int *local_lock_p = &hl_lock_p->locallock_hl_setstate_ifstate; 731 volatile int *local_lock_p = &hl_lock_p->locallock_hl_setstate_ifstate;
731 debug(90, "%i, 0x%o, 0x%o", lockid, stateid_new, stateid_old_mask); 732 debug(90, "%i, 0x%o, 0x%o", lockid, stateid_new, stateid_old_mask);
732 733
733 - if (*local_lock_p) 734 + if (!g_atomic_int_dec_and_test(local_lock_p))
734 return 0; 735 return 0;
735 736
736 - debug(92, "%i", *local_lock_p);  
737 - g_atomic_int_inc(local_lock_p);  
738 - debug(92, "%i", *local_lock_p);  
739 - if (*local_lock_p != 1) {  
740 - g_atomic_int_dec_and_test(local_lock_p);  
741 - return 0;  
742 - }  
743 -  
744 if (!(hl_lock_p->state[lockid]&stateid_old_mask)) { 737 if (!(hl_lock_p->state[lockid]&stateid_old_mask)) {
745 - g_atomic_int_dec_and_test(local_lock_p); 738 + g_atomic_int_inc(local_lock_p);
746 return 0; 739 return 0;
747 } 740 }
748 741
749 debug(50, "success"); 742 debug(50, "success");
750 g_atomic_int_set(&hl_lock_p->state[lockid], stateid_new); 743 g_atomic_int_set(&hl_lock_p->state[lockid], stateid_new);
751 - g_atomic_int_dec_and_test(local_lock_p); 744 + g_atomic_int_inc(local_lock_p);
752 -#undef local_lock  
753 return 1; 745 return 1;
754 } 746 }
755 747