[Freeswitch-svn] [commit] r5144 - freeswitch/trunk/libs/iax/src

Freeswitch SVN mikej at freeswitch.org
Thu May 10 23:41:06 EDT 2007


Author: mikej
Date: Thu May 10 23:41:06 2007
New Revision: 5144

Modified:
   freeswitch/trunk/libs/iax/src/iax-mutex.c

Log:
make pthread mutexes nested.

Modified: freeswitch/trunk/libs/iax/src/iax-mutex.c
==============================================================================
--- freeswitch/trunk/libs/iax/src/iax-mutex.c	(original)
+++ freeswitch/trunk/libs/iax/src/iax-mutex.c	Thu May 10 23:41:06 2007
@@ -40,22 +40,40 @@
 
 mutex_status_t iax_mutex_create(mutex_t **mutex)
 {
+	mutex_status_t status = MUTEX_FAILURE;
+#ifndef WIN32
+	pthread_mutexattr_t attr;
+#endif
 	mutex_t *check = NULL;
 
 	check = (mutex_t *)malloc(sizeof(**mutex));
 	if (!check)
-		return MUTEX_FAILURE;
+		goto done;
 #ifdef WIN32
 	InitializeCriticalSection(&check->mutex);
 #else
-	if (pthread_mutex_init(&check->mutex, NULL))
-		return MUTEX_FAILURE;
+	if (pthread_mutexattr_init(&attr))
+		goto done;
 
-#endif
+	if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
+		goto fail;
+
+	if (pthread_mutex_init(&check->mutex, &attr))
+		goto fail;
 
+	goto success;
+
+fail:
+        pthread_mutexattr_destroy(&mattr);
+		goto done;
+
+success:
+#endif
 	*mutex = check;
+	status = MUTEX_SUCCESS;
 
-	return MUTEX_SUCCESS;
+done:
+	return status;
 }
 
 mutex_status_t iax_mutex_destroy(mutex_t *mutex)



More information about the Freeswitch-svn mailing list