Updated PCI IDs to latest snapshot.
[tangerine.git] / test / threads / signalcondition.c
blob15cf90f42f780099832388ae6db1f9e61c790649
1 #include <exec/memory.h>
2 #include <libraries/thread.h>
3 #include <proto/exec.h>
4 #include <proto/dos.h>
5 #include <proto/thread.h>
6 #include <stdio.h>
7 #include <stdint.h>
9 struct thread_data {
10 void *mutex;
11 void *cond;
14 void *waiter_thread(void *data) {
15 struct thread_data *td = (struct thread_data *) data;
16 uint32_t id = CurrentThread();
18 printf("[%d] starting, locking the mutex\n", id);
19 LockMutex(td->mutex);
21 printf("[%d] waiting on the condition\n", id);
22 WaitCondition(td->cond, td->mutex);
24 printf("[%d] condition signalled, unlocking the mutex\n", id);
25 UnlockMutex(td->mutex);
27 printf("[%d] all done, exiting\n", id);
29 return NULL;
32 int main (int argc, char **argv) {
33 struct thread_data *td;
34 uint32_t tw;
36 td = AllocMem(sizeof(struct thread_data), MEMF_PUBLIC | MEMF_CLEAR);
38 printf("creating mutex\n");
39 td->mutex = CreateMutex();
41 printf("creating condition\n");
42 td->cond = CreateCondition();
44 printf("starting waiter thread\n");
45 tw = CreateThread(waiter_thread, (void *) td);
47 printf("sleeping for 2s\n");
48 Delay(100);
50 printf("signalling condition\n");
51 SignalCondition(td->cond);
53 printf("waiting for waiter thread\n");
54 WaitThread(tw, NULL);
56 printf("destroying the condition\n");
57 DestroyCondition(td->cond);
59 printf("destroying the mutex\n");
60 DestroyMutex(td->mutex);
62 FreeMem(td, sizeof(struct thread_data));
64 printf("all done\n");
66 return 0;