summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread_sync.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2005-12-14 04:14:19 +0000
committertedu <tedu@openbsd.org>2005-12-14 04:14:19 +0000
commitd6be970d7b2490f227132429134f3d9a2a947c35 (patch)
treeb80848054aef99b722f1ef32c293149703915b72 /lib/librthread/rthread_sync.c
parentchange wait message for thrsleep to "thrsleep" (diff)
downloadwireguard-openbsd-d6be970d7b2490f227132429134f3d9a2a947c35.tar.xz
wireguard-openbsd-d6be970d7b2490f227132429134f3d9a2a947c35.zip
check for waiters when destroying a mutex or semaphore
Diffstat (limited to 'lib/librthread/rthread_sync.c')
-rw-r--r--lib/librthread/rthread_sync.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index 9911c370c1d..c93ebd82187 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.7 2005/12/13 17:22:46 tedu Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.8 2005/12/14 04:14:19 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -155,7 +155,14 @@ sem_init(sem_t *semp, int pshared, unsigned int value)
int
sem_destroy(sem_t *semp)
{
- /* should check for waiters */
+ if (!*semp)
+ return (EINVAL);
+ if ((*semp)->waitcount) {
+#define MSG "sem_destroy on semaphore with waiters!\n"
+ write(2, MSG, sizeof(MSG));
+#undef MSG
+ return (EBUSY);
+ }
free(*semp);
*semp = NULL;
@@ -233,7 +240,12 @@ int
pthread_mutex_destroy(pthread_mutex_t *mutexp)
{
- /* check for waiters */
+ if ((*mutexp) && (*mutexp)->count) {
+#define MSG "pthread_mutex_destroy on mutex with waiters!\n"
+ write(2, MSG, sizeof(MSG));
+#undef MSG
+ return (EBUSY);
+ }
free((void *)*mutexp);
*mutexp = NULL;
return (0);