source:
src/tests/concurrent/preempt.c
@
6926a6d
Last change on this file since 6926a6d was 32cab5b, checked in by , 6 years ago | |
---|---|
|
|
File size: 828 bytes |
Rev | Line | |
---|---|---|
[11dbfe1] | 1 | #include <kernel> |
2 | #include <thread> | |
[0f56058] | 3 | #include <time> |
[11dbfe1] | 4 | |
5 | #ifndef PREEMPTION_RATE | |
[8ad6533] | 6 | #define PREEMPTION_RATE 10`ms |
[11dbfe1] | 7 | #endif |
8 | ||
[8ad6533] | 9 | Duration default_preemption() { |
[11dbfe1] | 10 | return PREEMPTION_RATE; |
11 | } | |
12 | ||
[b2fe1c9] | 13 | #ifdef LONG_TEST |
14 | static const unsigned long N = 30_000ul; | |
15 | #else | |
16 | static const unsigned long N = 500ul; | |
17 | #endif | |
18 | ||
[11dbfe1] | 19 | static volatile int counter = 0; |
20 | ||
[0322865c] | 21 | thread worker_t { |
[11dbfe1] | 22 | int value; |
23 | }; | |
24 | ||
[2afec66] | 25 | void ?{}( worker_t & this, int value ) { |
26 | this.value = value; | |
[11dbfe1] | 27 | } |
28 | ||
[83a071f9] | 29 | void main(worker_t & this) { |
[b2fe1c9] | 30 | while(counter < N) { |
[83a071f9] | 31 | if( (counter % 7) == this.value ) { |
[11dbfe1] | 32 | int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST); |
[12d2dc8] | 33 | if( (next % 100) == 0 ) printf("%d\n", (int)next); |
[11dbfe1] | 34 | } |
35 | } | |
36 | } | |
37 | ||
38 | int main(int argc, char* argv[]) { | |
39 | processor p; | |
40 | { | |
[0322865c] | 41 | worker_t w0 = 0; |
42 | worker_t w1 = 1; | |
43 | worker_t w2 = 2; | |
44 | worker_t w3 = 3; | |
45 | worker_t w4 = 4; | |
46 | worker_t w5 = 5; | |
47 | worker_t w6 = 6; | |
[11dbfe1] | 48 | } |
[2afec66] | 49 | } |
Note: See TracBrowser
for help on using the repository browser.