source:
src/tests/concurrent/preempt.c
@
ade5272
Last change on this file since ade5272 was b68fc85, checked in by , 7 years ago | |
---|---|
|
|
File size: 1.0 KB |
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 | ||
[b68fc85] | 19 | extern void __cfaabi_check_preemption(); |
20 | ||
[11dbfe1] | 21 | static volatile int counter = 0; |
22 | ||
[0322865c] | 23 | thread worker_t { |
[11dbfe1] | 24 | int value; |
25 | }; | |
26 | ||
[2afec66] | 27 | void ?{}( worker_t & this, int value ) { |
28 | this.value = value; | |
[11dbfe1] | 29 | } |
30 | ||
[83a071f9] | 31 | void main(worker_t & this) { |
[b2fe1c9] | 32 | while(counter < N) { |
[b68fc85] | 33 | __cfaabi_check_preemption(); |
[83a071f9] | 34 | if( (counter % 7) == this.value ) { |
[b68fc85] | 35 | __cfaabi_check_preemption(); |
[11dbfe1] | 36 | int next = __atomic_add_fetch_4(&counter, 1, __ATOMIC_SEQ_CST); |
[b68fc85] | 37 | __cfaabi_check_preemption(); |
[12d2dc8] | 38 | if( (next % 100) == 0 ) printf("%d\n", (int)next); |
[b68fc85] | 39 | __cfaabi_check_preemption(); |
[11dbfe1] | 40 | } |
[b68fc85] | 41 | __cfaabi_check_preemption(); |
[11dbfe1] | 42 | } |
43 | } | |
44 | ||
45 | int main(int argc, char* argv[]) { | |
46 | processor p; | |
47 | { | |
[0322865c] | 48 | worker_t w0 = 0; |
49 | worker_t w1 = 1; | |
50 | worker_t w2 = 2; | |
51 | worker_t w3 = 3; | |
52 | worker_t w4 = 4; | |
53 | worker_t w5 = 5; | |
54 | worker_t w6 = 6; | |
[11dbfe1] | 55 | } |
[2afec66] | 56 | } |
Note: See TracBrowser
for help on using the repository browser.