Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / thread / destroycondition.c
blob5aaf6614b2a7dbf86d6e6c614fa548279d3b0d90
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/types.h>
13 #include <proto/exec.h>
14 #include <assert.h>
16 /*****************************************************************************
18 NAME */
19 AROS_LH1(BOOL, DestroyCondition,
21 /* SYNOPSIS */
22 AROS_LHA(void *, cond, A0),
24 /* LOCATION */
25 struct ThreadBase *, ThreadBase, 16, Thread)
27 /* FUNCTION
28 Destroys a condition variable.
30 INPUTS
31 cond - the condition variable to destroy.
33 RESULT
34 TRUE if the condition was destroyed, otherwise FALSE.
36 NOTES
37 You cannot destroy a condition variable if other threads are waiting on
38 it.
40 EXAMPLE
41 DestroyCondition(cond);
43 BUGS
45 SEE ALSO
46 CreateCondition(), WaitCondition(), SignalCondition(),
47 BroadcastCondition()
49 INTERNALS
51 *****************************************************************************/
53 AROS_LIBFUNC_INIT
55 struct _Condition *c = (struct _Condition *) cond;
57 assert(c != NULL);
59 /* we can only destroy the cond if noone is waiting on it */
60 ObtainSemaphoreShared(&c->lock);
61 if (c->count > 0) {
62 ReleaseSemaphore(&c->lock);
63 return FALSE;
66 FreeMem(c, sizeof(struct _Condition));
68 return TRUE;
70 AROS_LIBFUNC_EXIT
71 } /* DestroyCondition */