Do not delete the mutex, while it is being locked by other threads
Keep count for the locked mutex and delete only if count is 0.
---
 src/base/os_defs.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/base/os_defs.c b/src/base/os_defs.c
index 83458c208..95b539d34 100644
--- a/src/base/os_defs.c
+++ b/src/base/os_defs.c
@@ -424,20 +424,27 @@ unsigned int ncs_os_lock(NCS_OS_LOCK *lock, 
NCS_OS_LOCK_REQUEST request,
 
                if (pthread_mutexattr_destroy(&mutex_attr) != 0)
                        return (NCSCC_RC_FAILURE);
-
+               lock->count = 0;
                break;
        }
        case NCS_OS_LOCK_RELEASE:
-               if (pthread_mutex_destroy(&lock->lock) != 0)
-                       return (NCSCC_RC_FAILURE);
+               if (lock->count == 0) {
+                       if (pthread_mutex_destroy(&lock->lock) != 0)
+                               return (NCSCC_RC_FAILURE);
+               } else {
+                       //Cant delete a locked mutex
+                       return NCSCC_RC_FAILURE;
+               }
                break;
 
        case NCS_OS_LOCK_LOCK:
                osaf_mutex_lock_ordie(&lock->lock);
+               lock->count++;
                break;
 
        case NCS_OS_LOCK_UNLOCK:
                osaf_mutex_unlock_ordie(&lock->lock);
+               lock->count--;
                break;
 
        default:
-- 
2.17.1



_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to