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