Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / thread / destroymutex.c
blobf1faf4caf6e0cb53384760bb93fec17bc2898518
1 /*
2 * thread.library - threading and synchronisation primitives
4 * Copyright © 2007 Robert Norris
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
8 */
10 #include "thread_intern.h"
12 #include <exec/semaphores.h>
13 #include <proto/exec.h>
14 #include <assert.h>
16 /*****************************************************************************
18 NAME */
19 AROS_LH1(BOOL, DestroyMutex,
21 /* SYNOPSIS */
22 AROS_LHA(void *, mutex, A0),
24 /* LOCATION */
25 struct ThreadBase *, ThreadBase, 11, Thread)
27 /* FUNCTION
28 Destroys a mutex.
30 INPUTS
31 mutex - the mutex to destroy.
33 RESULT
34 TRUE if the mutex was destroyed, otherwise FALSE.
36 NOTES
37 You cannot destroy a mutex that is currently locked or has tasks
38 waiting to lock it.
40 EXAMPLE
41 DestroyMutex(mutex)
43 BUGS
45 SEE ALSO
46 CreateMutex(), LockMutex(), TryLockMutex(), UnlockMutex()
48 INTERNALS
49 Mutexes are implemented as thin wrappers around Exec semaphores.
51 *****************************************************************************/
53 AROS_LIBFUNC_INIT
55 assert(mutex != NULL);
57 /* we can only destroy the mutex if its not held and noone is waiting */
58 Forbid();
59 if (((struct SignalSemaphore *) mutex)->ss_QueueCount >= 0) {
60 Permit();
61 return FALSE;
63 Permit();
65 FreeMem(mutex, sizeof(struct SignalSemaphore));
67 return TRUE;
69 AROS_LIBFUNC_EXIT
70 } /* DestroyMutex */