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.
10 #include "thread_intern.h"
12 #include <exec/tasks.h>
13 #include <exec/lists.h>
14 #include <proto/exec.h>
17 /*****************************************************************************
20 AROS_LH1(void, BroadcastCondition
,
23 AROS_LHA(void *, cond
, A0
),
26 struct ThreadBase
*, ThreadBase
, 19, Thread
)
29 Signals all threads waiting on a condition variable.
32 cond - the condition to signal.
35 This function always succeeds.
38 Before calling this function you should lock the mutex that protects
39 the condition. WaitCondition() atomically unlocks the mutex and waits
40 on the condition, so by locking the mutex first before sending the
41 signal, you ensure that the signal cannot be missed. See
42 WaitCondition() for more details.
44 If no threads are waiting on the condition, nothing happens.
48 BroadcastCondition(cond);
54 CreateCondition(), DestroyCondition(), WaitCondition(),
58 SIGF_SIGNAL is used to signal the selected waiting thread.
60 *****************************************************************************/
64 struct _Condition
*c
= (struct _Condition
*) cond
;
65 struct _CondWaiter
*waiter
;
69 /* safely operation on the condition */
70 ObtainSemaphore(&c
->lock
);
72 /* wake up all the waiters */
73 while ((waiter
= (struct _CondWaiter
*) REMHEAD(&c
->waiters
)) != NULL
) {
74 Signal(waiter
->task
, SIGF_SINGLE
);
75 FreeMem(waiter
, sizeof(struct _CondWaiter
));
81 ReleaseSemaphore(&c
->lock
);
84 } /* BroadcastCondition */