summaryrefslogtreecommitdiff
path: root/nuttx/sched/pthread_mutexunlock.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-05-31 17:13:08 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-05-31 17:13:08 +0000
commit98a4a5029768be0c75d6d51fca4e73c98de4b7fa (patch)
tree75df8870063f23c8cb7d4d322575b6b2c7021065 /nuttx/sched/pthread_mutexunlock.c
parent52bbc6ee28f2ae7faef6a430e86c881376ff3bfb (diff)
downloadpx4-nuttx-98a4a5029768be0c75d6d51fca4e73c98de4b7fa.tar.gz
px4-nuttx-98a4a5029768be0c75d6d51fca4e73c98de4b7fa.tar.bz2
px4-nuttx-98a4a5029768be0c75d6d51fca4e73c98de4b7fa.zip
Add support for recursive mutexes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@753 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/pthread_mutexunlock.c')
-rw-r--r--nuttx/sched/pthread_mutexunlock.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/nuttx/sched/pthread_mutexunlock.c b/nuttx/sched/pthread_mutexunlock.c
index 1184fc804..f01f7761e 100644
--- a/nuttx/sched/pthread_mutexunlock.c
+++ b/nuttx/sched/pthread_mutexunlock.c
@@ -107,14 +107,38 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
if (mutex->pid != (int)getpid())
{
+ /* No... return an error (default behavior is like PTHREAD_MUTEX_ERRORCHECK) */
+
sdbg("Holder=%d returning EPERM\n", mutex->pid);
ret = EPERM;
}
+
+
+ /* Yes, the caller owns the semaphore.. Is this a recursive mutex? */
+
+#ifdef CONFIG_MUTEX_TYPES
+ else if (mutex->type == PTHREAD_MUTEX_RECURSIVE && mutex->nlocks > 1)
+ {
+ /* This is a recursive mutex and we there are multiple locks held. Retain
+ * the mutex lock, just decrement the count of locks held, and return
+ * success.
+ */
+ mutex->nlocks--;
+ }
+#endif
+
+ /* This is either a non-recursive mutex or is the outermost unlock of
+ * a recursive mutex.
+ */
+
else
{
- /* Nulllify the pid and post the semaphore */
+ /* Nullify the pid and lock count then post the semaphore */
- mutex->pid = 0;
+ mutex->pid = 0;
+#ifdef CONFIG_MUTEX_TYPES
+ mutex->nlocks = 0;
+#endif
ret = pthread_givesemaphore((sem_t*)&mutex->sem);
}
sched_unlock();