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, SignalCondition
,
23 AROS_LHA(void *, cond
, A0
),
26 struct ThreadBase
*, ThreadBase
, 18, Thread
)
29 Signals a thread waiting on 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. If more
45 than one thread is waiting, only one will be signalled. Which one is
50 SignalCondition(cond);
56 CreateCondition(), DestroyCondition(), WaitCondition(),
60 SIGF_SIGNAL is used to signal the selected waiting thread.
62 *****************************************************************************/
66 struct _Condition
*c
= (struct _Condition
*) cond
;
67 struct _CondWaiter
*waiter
;
71 /* safely remove a waiter from the list */
72 ObtainSemaphore(&c
->lock
);
73 waiter
= (struct _CondWaiter
*) REMHEAD(&c
->waiters
);
76 ReleaseSemaphore(&c
->lock
);
83 Signal(waiter
->task
, SIGF_SINGLE
);
86 FreeMem(waiter
, sizeof(struct _CondWaiter
));
89 } /* SignalCondition */