Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/target-cpu/fragments/seq-sarr.in
ViewVC logotype

Diff of /branches/vis15/src/compiler/target-cpu/fragments/seq-sarr.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4488, Sat Sep 3 00:02:19 2016 UTC revision 4489, Sat Sep 3 00:32:03 2016 UTC
# Line 11  Line 11 
11      uint32_t            _nStable;       // stable strands (in locations 0.._nStable-1)      uint32_t            _nStable;       // stable strands (in locations 0.._nStable-1)
12      uint32_t            _nActive;       // active strands (in locations _nStable.._nStable+_nActive-1)      uint32_t            _nActive;       // active strands (in locations _nStable.._nStable+_nActive-1)
13    
14        strand_array () : _status(nullptr), _storage(nullptr), _nItems(0) { }
15        ~strand_array ()
16        {
17            if (this->_status != nullptr) std::free (this->_status);
18            if (this->_storage != nullptr) std::free (this->_storage);
19        }
20    
21        uint32_t num_active () const { return this->_nActive; }
22        uint32_t num_stable () const { return this->_nStable; }
23        uint32_t num_alive () const { return this->_nActive+this->_nStable; }
24    
25      // return a strand's status
26        diderot::strand_status status (index_t ix) const
27        {
28            return static_cast<diderot::strand_status>(this->_status[ix]);
29        }
30    // return a pointer to the given strand    // return a pointer to the given strand
31      @STRANDTY@ *strand (index_t ix) const      @STRANDTY@ *strand (index_t ix) const
32      {      {
33          return static_cast<@STRANDTY@ *>(this->_storage + ix * sizeof(@STRANDTY@));          return reinterpret_cast<@STRANDTY@ *>(this->_storage + ix * sizeof(@STRANDTY@));
34      }      }
35    // return a pointer to the local state of strand ix    // return a pointer to the local state of strand ix
36      @STRANDTY@ *local_state (index_t ix) const      @STRANDTY@ *local_state (index_t ix) const
37      {      {
38          return this->strand();          return this->strand(ix);
39      }      }
40    
41    // allocate space for nItems    // allocate space for nItems
42      bool alloc (uint32_t nItems)      bool alloc (uint32_t nItems)
43      {      {
44          char *storage = static_cast<char *>(std::malloc (nItems * sizeof(@STRANDTY@)));          this->_storage = static_cast<char *>(std::malloc (nItems * sizeof(@STRANDTY@)));
45          if (this->_storage == nullptr) {          if (this->_storage == nullptr) {
46              return true;              return true;
47          }          }
# Line 37  Line 53 
53          this->_nItems = nItems;          this->_nItems = nItems;
54          this->_nActive = 0;          this->_nActive = 0;
55          this->_nStable = 0;          this->_nStable = 0;
56            return false;
57      }      }
58    
59    // initialize the first nStrands locations as new active strands    // initialize the first nStrands locations as new active strands
# Line 44  Line 61 
61      {      {
62          assert (this->_nActive == 0);          assert (this->_nActive == 0);
63          assert (this->_nItems == nStrands);          assert (this->_nItems == nStrands);
64          for (uint32_t ix = 0;  i < nStrands;  i++) {          for (uint32_t ix = 0;  ix < nStrands;  ix++) {
65              this->_status[ix] = diderot::kActive;              this->_status[ix] = diderot::kActive;
66              new(this->strand(ix)) @STRANDTY@;              new(this->strand(ix)) @STRANDTY@;
67          }          }
68          this->_nActive = nStrands;          this->_nActive = nStrands;
69      }      }
70    
71      // swap in and out states (NOP for this version)
72        void swap () { }
73    
74    // mark the given strand as stable    // mark the given strand as stable
75      void stabilize (index_t ix)      void stabilize (@STABILIZE_PARAMS@index_t ix)
76      {      {
77    #ifdef DIDEROT_HAS_STABILIZE
78            @STRAND@_stabilize (@STABILIZE_ARGS@this->strand(ix));
79    #endif
80          this->_status[ix] = diderot::kStable;          this->_status[ix] = diderot::kStable;
81            this->_nActive--;
82            this->_nStable++;
83        }
84    
85      // mark the given strand as dead
86        void kill (index_t ix)
87        {
88            this->_status[ix] = diderot::kDead;
89            this->_nActive--;
90        }
91    
92      // iterator over alive (active+stable) strands
93        index_t begin_alive () const { return 0; }
94        index_t end_alive () const { return this->_nItems; }
95        index_t next_alive (index_t &ix)
96        {
97    #ifdef DIDEROT_HAS_STRAND_DIE
98            while ((ix < this->_nItems) && (this->_status[ix] == diderot::kDead)) {
99                ix++;
100            }
101    #else
102            ix++;
103    #endif
104            return ix;
105        }
106    
107      // iterator over active strands
108        index_t begin_active () const { return 0; }
109        index_t end_active () const { return this->_nItems; }
110        index_t next_active (index_t &ix)
111        {
112            while ((ix < this->_nItems) && (this->_status[ix] != diderot::kActive)) {
113                ix++;
114            }
115            return ix;
116        }
117    
118      // iterator over stable strands
119        index_t begin_stable () const { return 0; }
120        index_t end_stable () const { return this->_nItems; }
121        index_t next_stable (index_t &ix)
122        {
123            while ((ix < this->_nItems) && (this->_status[ix] != diderot::kStable)) {
124                ix++;
125            }
126            return ix;
127      }      }
128    
129  }; // @STRAND@_array  }; // @STRAND@_array

Legend:
Removed from v.4488  
changed lines
  Added in v.4489

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0