ADT
        ast-experimental
        enum
        forall-pointer-decay
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since 120ab9d5 was             b200492, checked in by Thierry Delisle <tdelisle@…>, 4 years ago           | 
        
        
          | 
             
Fixed last push which wasn't checked properly. 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.3 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include <fstream.hfa>
 | 
|---|
| 2 | #include <kernel.hfa>
 | 
|---|
| 3 | #include <thread.hfa>
 | 
|---|
| 4 | #include <time.hfa>
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #include "long_tests.hfa"
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef PREEMPTION_RATE
 | 
|---|
| 9 | #define PREEMPTION_RATE 10`ms
 | 
|---|
| 10 | #endif
 | 
|---|
| 11 | 
 | 
|---|
| 12 | Duration default_preemption() {
 | 
|---|
| 13 |         return PREEMPTION_RATE;
 | 
|---|
| 14 | }
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #ifdef TEST_LONG
 | 
|---|
| 17 | static const unsigned long N = 30_000ul;
 | 
|---|
| 18 | #else
 | 
|---|
| 19 | static const unsigned long N = 500ul;
 | 
|---|
| 20 | #endif
 | 
|---|
| 21 | 
 | 
|---|
| 22 | extern void __cfaabi_check_preemption();
 | 
|---|
| 23 | 
 | 
|---|
| 24 | static volatile int counter = 0;
 | 
|---|
| 25 | 
 | 
|---|
| 26 | thread worker_t {
 | 
|---|
| 27 |         int value;
 | 
|---|
| 28 |         unsigned spin;
 | 
|---|
| 29 | };
 | 
|---|
| 30 | 
 | 
|---|
| 31 | void ?{}( worker_t & this, int value ) {
 | 
|---|
| 32 |         this.value = value;
 | 
|---|
| 33 |         this.spin = 0;
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | void main(worker_t & this) {
 | 
|---|
| 37 |         while(TEST(counter < N)) {
 | 
|---|
| 38 |                 if(this.spin > 100_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
 | 
|---|
| 39 |                 __cfaabi_check_preemption();
 | 
|---|
| 40 |                 if( (counter % 7) == this.value ) {
 | 
|---|
| 41 |                         __cfaabi_check_preemption();
 | 
|---|
| 42 |                         int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
 | 
|---|
| 43 |                         __cfaabi_check_preemption();
 | 
|---|
| 44 |                         if( (next % 100) == 0 ) printf("%d\n", (int)next);
 | 
|---|
| 45 |                         __cfaabi_check_preemption();
 | 
|---|
| 46 |                         this.spin = 0;
 | 
|---|
| 47 |                 }
 | 
|---|
| 48 |                 __cfaabi_check_preemption();
 | 
|---|
| 49 |                 KICK_WATCHDOG;
 | 
|---|
| 50 |                 this.spin++;
 | 
|---|
| 51 |         }
 | 
|---|
| 52 | }
 | 
|---|
| 53 | 
 | 
|---|
| 54 | int main(int argc, char* argv[]) {
 | 
|---|
| 55 |         processor p;
 | 
|---|
| 56 |         {
 | 
|---|
| 57 |                 worker_t w0 = 0;
 | 
|---|
| 58 |                 worker_t w1 = 1;
 | 
|---|
| 59 |                 worker_t w2 = 2;
 | 
|---|
| 60 |                 worker_t w3 = 3;
 | 
|---|
| 61 |                 worker_t w4 = 4;
 | 
|---|
| 62 |                 worker_t w5 = 5;
 | 
|---|
| 63 |                 worker_t w6 = 6;
 | 
|---|
| 64 |         }
 | 
|---|
| 65 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.