3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following condition:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
23 #include <kern/types.h>
24 #include <kern/libc.h>
25 #include <kern/time.h>
26 #include <kern/thread.h>
28 void wake(Time::KTimerEntry *entry)
30 Threads::Blocker *b = static_cast<Threads::Blocker *>(entry->data);
34 void clearflag(Time::KTimerEntry *entry)
36 int *flag = static_cast<int *>(entry->data);
40 void threadb(void *arg)
42 Time::KTimerEntry timer(Time::monotonic_timers);
43 Threads::ThreadBlocker tb(curthread);
46 volatile int flag = 1;
48 Time::monotonic_clock.get_time(&now);
52 timer.func = clearflag;
53 timer.data = (void *)(&flag);
66 curthread->block(&tb);
70 extern System::Mem::Mappable Mem::physmem;
72 void threada(void *arg)
74 Time::KTimerEntry timer(Time::monotonic_timers);
75 Threads::ThreadBlocker tb(curthread);
77 Threads::sched.new_thread(threadb, NULL, "thread b")->wake();
80 volatile int flag = 1;
82 Time::monotonic_clock.get_time(&now);
86 timer.func = clearflag;
87 timer.data = (void *)(&flag);
100 curthread->block(&tb);
106 Threads::sched.new_thread(threada, NULL, "thread a")->wake();