redmine

[hllock] Fixed a deadlock

Fixed a regression made by a96d68fc
@@ -392,7 +392,7 @@ int syntax() { @@ -392,7 +392,7 @@ int syntax() {
392 } 392 }
393 393
394 int ncpus; 394 int ncpus;
395 -pid_t parent_pid; 395 +pid_t parent_pid = 0;
396 396
397 pid_t waitpid_timed(pid_t child_pid, int *status_p, long sec, long nsec) { 397 pid_t waitpid_timed(pid_t child_pid, int *status_p, long sec, long nsec) {
398 struct timespec ts; 398 struct timespec ts;
@@ -713,6 +713,39 @@ int pa_unsetup(struct pa_options *opts) { @@ -713,6 +713,39 @@ int pa_unsetup(struct pa_options *opts) {
713 return 0; 713 return 0;
714 } 714 }
715 715
  716 +static int helper_isalive_cache;
  717 +static inline int helper_isalive_proc() {
  718 + int rc;
  719 + debug(12, "helper_pid == %u", helper_pid);
  720 +
  721 + if ((rc=waitpid(helper_pid, NULL, WNOHANG))>=0)
  722 + return helper_isalive_cache=1;
  723 +
  724 + debug(1, "waitpid(%u, NULL, WNOHANG) => %i", helper_pid, rc);
  725 +
  726 + return helper_isalive_cache=0;
  727 +}
  728 +static inline int helper_isalive_thread() {
  729 + int rc;
  730 + debug(12, "");
  731 +
  732 + if ((rc=pthread_kill(privileged_thread, 0)))
  733 + return helper_isalive_cache=0;
  734 +
  735 + debug(1, "pthread_kill(privileged_thread, 0) => %i", helper_pid, rc);
  736 +
  737 + return helper_isalive_cache=1;
  738 +}
  739 +static inline int helper_isalive() {
  740 + return helper_pid ? helper_isalive_proc() : helper_isalive_thread();
  741 +}
  742 +
  743 +int privileged_check() {
  744 + if (helper_pid)
  745 + critical_on(!helper_isalive_proc());
  746 + return 0;
  747 +}
  748 +
716 # ifdef HL_LOCKS 749 # ifdef HL_LOCKS
717 750
718 static inline int hl_isanswered(int lockid) { 751 static inline int hl_isanswered(int lockid) {
@@ -728,11 +761,24 @@ static inline void hl_setstate(int lockid, hllock_state_t stateid) { @@ -728,11 +761,24 @@ static inline void hl_setstate(int lockid, hllock_state_t stateid) {
728 } 761 }
729 762
730 int hl_setstate_ifstate(int lockid, hllock_state_t stateid_new, hllock_state_t stateid_old_mask) { 763 int hl_setstate_ifstate(int lockid, hllock_state_t stateid_new, hllock_state_t stateid_old_mask) {
  764 + static long long counter = 0;
731 volatile int *local_lock_p = &hl_lock_p->locallock_hl_setstate_ifstate; 765 volatile int *local_lock_p = &hl_lock_p->locallock_hl_setstate_ifstate;
732 debug(90, "%i, 0x%o, 0x%o", lockid, stateid_new, stateid_old_mask); 766 debug(90, "%i, 0x%o, 0x%o", lockid, stateid_new, stateid_old_mask);
733 767
734 - if (!g_atomic_int_dec_and_test(local_lock_p)) 768 + if (helper_pid || parent_pid) {
  769 + if (((++counter) & 0xffffff) == 0) {
  770 + if (helper_pid) {
  771 + critical_on(!helper_isalive_proc());
  772 + } else {
  773 + critical_on(!parent_isalive());
  774 + }
  775 + }
  776 + }
  777 +
  778 + if (!g_atomic_int_dec_and_test(local_lock_p)) {
  779 + g_atomic_int_inc(local_lock_p);
735 return 0; 780 return 0;
  781 + }
736 782
737 if (!(hl_lock_p->state[lockid]&stateid_old_mask)) { 783 if (!(hl_lock_p->state[lockid]&stateid_old_mask)) {
738 g_atomic_int_inc(local_lock_p); 784 g_atomic_int_inc(local_lock_p);
@@ -812,39 +858,6 @@ void hl_shutdown(int lockid) { @@ -812,39 +858,6 @@ void hl_shutdown(int lockid) {
812 858
813 # endif 859 # endif
814 860
815 -static int helper_isalive_cache;  
816 -static inline int helper_isalive_proc() {  
817 - int rc;  
818 - debug(12, "helper_pid == %u", helper_pid);  
819 -  
820 - if ((rc=waitpid(helper_pid, NULL, WNOHANG))>=0)  
821 - return helper_isalive_cache=1;  
822 -  
823 - debug(1, "waitpid(%u, NULL, WNOHANG) => %i", helper_pid, rc);  
824 -  
825 - return helper_isalive_cache=0;  
826 -}  
827 -static inline int helper_isalive_thread() {  
828 - int rc;  
829 - debug(12, "");  
830 -  
831 - if ((rc=pthread_kill(privileged_thread, 0)))  
832 - return helper_isalive_cache=0;  
833 -  
834 - debug(1, "pthread_kill(privileged_thread, 0) => %i", helper_pid, rc);  
835 -  
836 - return helper_isalive_cache=1;  
837 -}  
838 -static inline int helper_isalive() {  
839 - return helper_pid ? helper_isalive_proc() : helper_isalive_thread();  
840 -}  
841 -  
842 -int privileged_check() {  
843 - if (helper_pid)  
844 - critical_on(!helper_isalive_proc());  
845 - return 0;  
846 -}  
847 -  
848 int privileged_handler(ctx_t *ctx_p) 861 int privileged_handler(ctx_t *ctx_p)
849 { 862 {
850 # ifdef READWRITE_SIGNALLING 863 # ifdef READWRITE_SIGNALLING