summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2005-12-14 04:14:20 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2005-12-14 04:14:20 +0000
commit68c5f5e065b27e47031bd71ea093c7133603af55 (patch)
treeca129e54751ffacc57d100a6025dbaa1834c624e /lib
parent1e9f063fecc590c2aaadaec44e11d040453bfe98 (diff)
check for waiters when destroying a mutex or semaphore
Diffstat (limited to 'lib')
-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);