Changes in tests/concurrent/preempt.cfa [7b2c8c3c:c701332a]
- File:
-
- 1 edited
-
tests/concurrent/preempt.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/preempt.cfa
r7b2c8c3c rc701332a 1 #include <clock.hfa>2 #include <fstream.hfa>3 1 #include <kernel.hfa> 4 2 #include <thread.hfa> … … 23 21 extern void __cfaabi_check_preemption(); 24 22 25 static struct { 26 volatile int counter; 27 volatile Time prev; 28 Duration durations[6]; 29 } globals; 23 static volatile int counter = 0; 30 24 31 25 thread worker_t { 32 26 int value; 33 unsigned long long spin;34 27 }; 35 28 36 29 void ?{}( worker_t & this, int value ) { 37 30 this.value = value; 38 this.spin = 0;39 31 } 40 32 41 33 void main(worker_t & this) { 42 while(TEST(globals.counter < N)) { 43 if(this.spin > 50_000_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")"; 34 while(TEST(counter < N)) { 44 35 __cfaabi_check_preemption(); 45 if( ( globals.counter % 7) == this.value ) {36 if( (counter % 7) == this.value ) { 46 37 __cfaabi_check_preemption(); 47 #if !defined(TEST_LONG) 48 Time now = timeHiRes(); 49 Duration diff = now - globals.prev; 50 globals.prev = now; 51 #endif 52 int next = __atomic_add_fetch( &globals.counter, 1, __ATOMIC_SEQ_CST ); 38 int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST ); 53 39 __cfaabi_check_preemption(); 54 if( (next % 100) == 0 ) { 55 #if !defined(TEST_LONG) 56 unsigned idx = next / 100; 57 if (idx >= 6) abort | "Idx from next is invalid: " | idx | "vs" | next; 58 globals.durations[idx] = diff; 59 if(diff > 12`s) serr | "Duration suspiciously large:" | diff; 60 #endif 61 printf("%d\n", (int)next); 62 63 } 40 if( (next % 100) == 0 ) printf("%d\n", (int)next); 64 41 __cfaabi_check_preemption(); 65 this.spin = 0;66 42 } 67 43 __cfaabi_check_preemption(); 68 44 KICK_WATCHDOG; 69 this.spin++;70 45 } 71 46 } … … 73 48 int main(int argc, char* argv[]) { 74 49 processor p; 75 globals.counter = 0;76 globals.durations[0] = 0;77 globals.durations[1] = 0;78 globals.durations[2] = 0;79 globals.durations[3] = 0;80 globals.durations[4] = 0;81 globals.durations[5] = 0;82 50 { 83 globals.prev = timeHiRes();84 51 worker_t w0 = 0; 85 52 worker_t w1 = 1;
Note:
See TracChangeset
for help on using the changeset viewer.