summaryrefslogtreecommitdiffstats
path: root/lib/libkse
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2003-11-04 19:53:32 +0000
committerdeischen <deischen@FreeBSD.org>2003-11-04 19:53:32 +0000
commit3ccfc8a9e49cbfef18f66d1e274467b8f7d53a89 (patch)
tree0a81637b0dcb21c20dcc36f406010c7fde859b73 /lib/libkse
parent96918b9811a81aec1bc2aaee34a0db88044994ee (diff)
downloadFreeBSD-src-3ccfc8a9e49cbfef18f66d1e274467b8f7d53a89.zip
FreeBSD-src-3ccfc8a9e49cbfef18f66d1e274467b8f7d53a89.tar.gz
Add the ability to reinitialize a mutex (internally, not a userland
API). Reviewed by: davidxu
Diffstat (limited to 'lib/libkse')
-rw-r--r--lib/libkse/thread/thr_mutex.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/libkse/thread/thr_mutex.c b/lib/libkse/thread/thr_mutex.c
index 0717768..017baeb 100644
--- a/lib/libkse/thread/thr_mutex.c
+++ b/lib/libkse/thread/thr_mutex.c
@@ -65,6 +65,11 @@
#endif
#define THR_IN_MUTEXQ(thr) (((thr)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
+#define MUTEX_DESTROY(m) do { \
+ _lock_destroy(&(m)->m_lock); \
+ free(m); \
+} while (0)
+
/*
* Prototypes
@@ -192,8 +197,7 @@ _pthread_mutex_init(pthread_mutex_t *mutex,
*mutex = pmutex;
} else {
/* Free the mutex lock structure: */
- _lock_destroy(&pmutex->m_lock);
- free(pmutex);
+ MUTEX_DESTROY(pmutex);
*mutex = NULL;
}
}
@@ -202,6 +206,19 @@ _pthread_mutex_init(pthread_mutex_t *mutex,
return (ret);
}
+void
+_thr_mutex_reinit(pthread_mutex_t *mutex)
+{
+ _lock_reinit(&(*mutex)->m_lock, LCK_ADAPTIVE,
+ _thr_lock_wait, _thr_lock_wakeup);
+ TAILQ_INIT(&(*mutex)->m_queue);
+ (*mutex)->m_owner = NULL;
+ (*mutex)->m_count = 0;
+ (*mutex)->m_refcount = 0;
+ (*mutex)->m_prio = 0;
+ (*mutex)->m_saved_prio = 0;
+}
+
int
_pthread_mutex_destroy(pthread_mutex_t *mutex)
{
@@ -241,11 +258,7 @@ _pthread_mutex_destroy(pthread_mutex_t *mutex)
* structure:
*/
MUTEX_ASSERT_NOT_OWNED(m);
-
- /* Free the mutex lock structure: */
- _lock_destroy(&m->m_lock);
-
- free(m);
+ MUTEX_DESTROY(m);
}
}
OpenPOWER on IntegriCloud