ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since c5c743e was             b2a37b0, checked in by Thierry Delisle <tdelisle@…>, 6 years ago           | 
        
        
          | 
             
Initial drafts in C++ of the CFA scheduler 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            627 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include <atomic>
 | 
|---|
| 2 | 
 | 
|---|
| 3 | struct thread {};
 | 
|---|
| 4 | 
 | 
|---|
| 5 | struct cluster {
 | 
|---|
| 6 |         void add();
 | 
|---|
| 7 |         void remove();
 | 
|---|
| 8 |         thread * next();
 | 
|---|
| 9 | };
 | 
|---|
| 10 | 
 | 
|---|
| 11 | struct processor {
 | 
|---|
| 12 | 
 | 
|---|
| 13 |         cluster cluster;
 | 
|---|
| 14 |         std::atomic<bool> stop;
 | 
|---|
| 15 |         volatile bool idle;
 | 
|---|
| 16 | };
 | 
|---|
| 17 | 
 | 
|---|
| 18 | 
 | 
|---|
| 19 | void run(thread * ) {
 | 
|---|
| 20 |         // verify preemption
 | 
|---|
| 21 | 
 | 
|---|
| 22 |         // run Thread
 | 
|---|
| 23 | 
 | 
|---|
| 24 |         // verify preemption
 | 
|---|
| 25 | 
 | 
|---|
| 26 |         // finish Running
 | 
|---|
| 27 | }
 | 
|---|
| 28 | 
 | 
|---|
| 29 | void main(processor & self) {
 | 
|---|
| 30 | 
 | 
|---|
| 31 |         self.cluster.add();
 | 
|---|
| 32 | 
 | 
|---|
| 33 |         while(!self.stop) {
 | 
|---|
| 34 |                 if(thread * t = self.cluster.next()) {
 | 
|---|
| 35 |                         run(t);
 | 
|---|
| 36 |                         continue;
 | 
|---|
| 37 |                 }
 | 
|---|
| 38 | 
 | 
|---|
| 39 |                 self.set_idle();
 | 
|---|
| 40 |                 std::atomic_thread_fence();
 | 
|---|
| 41 | 
 | 
|---|
| 42 |                 if(thread * t = self.cluster.next()) {
 | 
|---|
| 43 |                         self.idle = false;
 | 
|---|
| 44 |                         run(t);
 | 
|---|
| 45 |                         continue;
 | 
|---|
| 46 |                 }
 | 
|---|
| 47 | 
 | 
|---|
| 48 |                 halt();
 | 
|---|
| 49 |         }
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         self.cluster.remove();
 | 
|---|
| 52 | 
 | 
|---|
| 53 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.