3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
15 #include <kern/types.h>
16 #include <kern/libc.h>
17 #include <kern/time.h>
18 #include <kern/thread.h>
20 void wake(Time::KTimerEntry *entry)
22 Threads::Blocker *b = static_cast<Threads::Blocker *>(entry->data);
26 void clearflag(Time::KTimerEntry *entry)
28 int *flag = static_cast<int *>(entry->data);
32 void threadb(void *arg)
34 Time::KTimerEntry timer(Time::monotonic_timers);
35 Threads::ThreadBlocker tb(curthread);
38 volatile int flag = 1;
40 Time::monotonic_clock.get_time(&now);
44 timer.func = clearflag;
45 timer.data = (void *)(&flag);
58 curthread->block(&tb);
62 extern System::Mem::Mappable Mem::physmem;
64 void threada(void *arg)
66 Time::KTimerEntry timer(Time::monotonic_timers);
67 Threads::ThreadBlocker tb(curthread);
69 Threads::sched.new_thread(threadb, NULL, "thread b")->wake();
72 volatile int flag = 1;
74 Time::monotonic_clock.get_time(&now);
78 timer.func = clearflag;
79 timer.data = (void *)(&flag);
92 curthread->block(&tb);
98 Threads::sched.new_thread(threada, NULL, "thread a")->wake();