Changeset 67:e2bb58a307d2 in rrlib_util


Ignore:
Timestamp:
10.10.2012 00:49:34 (7 years ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
default
Phase:
public
Message:

Small improvements to tTaggedPointer:

  • Added constructor
  • Added a non-const conversion operator returning reference for use in atomics
  • Introduced common base class for tTaggedPointerImplementation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tTaggedPointer.h

    r65 r67  
    9999    implementation.SetRaw(raw_tagged_pointer); 
    100100  } 
     101  tTaggedPointer(T* pointer, int stamp) 
     102  { 
     103    Set(pointer, stamp); 
     104  } 
    101105 
    102106  /*! 
     
    151155    return implementation.GetStorage(); 
    152156  } 
     157  operator tStorage&() 
     158  { 
     159    return implementation.GetStorageReference(); 
     160  } 
    153161 
    154162  T& operator*() const 
  • tagged_pointer/tTaggedPointerImplementation.h

    r66 r67  
    7171class tTaggedPointerImplementation : public tTaggedPointerImplementation < TAG_BIT_WIDTH + 1, ALIGNED_POINTERS > 
    7272{ 
     73}; 
     74 
     75template <typename TStorage> 
     76class tTaggedPointerImplementationBase 
     77{ 
     78public: 
     79 
     80  typedef TStorage tStorage; 
     81 
     82  tTaggedPointerImplementationBase() : storage(0) {} 
     83 
     84  tStorage GetStorage() const 
     85  { 
     86    return storage; 
     87  } 
     88 
     89  tStorage& GetStorageReference() 
     90  { 
     91    return storage; 
     92  } 
     93 
     94  void SetRaw(tStorage raw) 
     95  { 
     96    storage = raw; 
     97  } 
     98 
     99protected: 
     100 
     101  /*! Current stamp and pointer are stored in this value */ 
     102  tStorage storage; 
    73103}; 
    74104 
     
    88118 */ 
    89119template <bool ALIGNED_POINTERS> 
    90 class tTaggedPointerImplementation<16, ALIGNED_POINTERS> 
    91 { 
    92 public: 
    93   typedef uint64_t tStorage; 
    94  
    95   tTaggedPointerImplementation() : storage(0) {} 
     120class tTaggedPointerImplementation<16, ALIGNED_POINTERS> : public tTaggedPointerImplementationBase<uint64_t> 
     121{ 
     122public: 
    96123 
    97124  void* GetPointer() const 
     
    103130  { 
    104131    return static_cast<int>(storage >> 48); 
    105   } 
    106  
    107   tStorage GetStorage() const 
    108   { 
    109     return storage; 
    110132  } 
    111133 
     
    126148  } 
    127149 
    128   void SetRaw(tStorage raw) 
    129   { 
    130     storage = raw; 
    131   } 
    132  
    133150  void SetStamp(int stamp) 
    134151  { 
     
    137154    storage = (stamp64 << 48) | old_pointer; 
    138155  } 
    139  
    140 private: 
    141  
    142   /*! Current stamp and pointer are stored in this value */ 
    143   tStorage storage; 
    144156}; 
    145157 
    146158template <> 
    147 class tTaggedPointerImplementation<19, true> 
    148 { 
    149 public: 
    150   typedef uint64_t tStorage; 
    151  
    152   tTaggedPointerImplementation() : storage(0) {} 
    153   tTaggedPointerImplementation(tStorage raw) : storage(raw) {} 
     159class tTaggedPointerImplementation<19, true> : public tTaggedPointerImplementationBase<uint64_t> 
     160{ 
     161public: 
    154162 
    155163  void* GetPointer() const 
     
    161169  { 
    162170    return static_cast<int>(storage >> 45); 
    163   } 
    164  
    165   tStorage GetStorage() const 
    166   { 
    167     return storage; 
    168171  } 
    169172 
     
    184187  } 
    185188 
    186   void SetRaw(tStorage raw) 
    187   { 
    188     storage = raw; 
    189   } 
    190  
    191189  void SetStamp(int stamp) 
    192190  { 
     
    195193    storage = (stamp64 << 45) | old_pointer; 
    196194  } 
    197  
    198 private: 
    199  
    200   /*! Current stamp and pointer are stored in this value */ 
    201   tStorage storage; 
    202195}; 
    203196 
     
    211204 
    212205template <> 
    213 class tTaggedPointerImplementation<3, true> 
    214 { 
    215 public: 
    216   typedef uint tStorage; 
    217  
    218   tTaggedPointerImplementation() : storage(0) {} 
    219   tTaggedPointerImplementation(tStorage raw) : storage(raw) {} 
     206class tTaggedPointerImplementation<3, true> : public tTaggedPointerImplementationBase<uint> 
     207{ 
     208public: 
    220209 
    221210  void* GetPointer() const 
     
    227216  { 
    228217    return static_cast<int>(storage & STAMP3_MASK); 
    229   } 
    230  
    231   tStorage GetStorage() const 
    232   { 
    233     return storage; 
    234218  } 
    235219 
     
    245229  } 
    246230 
    247   void SetRaw(tStorage raw) 
    248   { 
    249     storage = raw; 
    250   } 
    251  
    252231  void SetStamp(int stamp) 
    253232  { 
     
    255234    storage = old_pointer | stamp; 
    256235  } 
    257  
    258 private: 
    259  
    260   /*! Current stamp and pointer are stored in this value */ 
    261   tStorage storage; 
    262236}; 
    263237 
     
    269243 
    270244  tTaggedPointerImplementation() : storage(0) {} 
    271   tTaggedPointerImplementation(tStorage raw) : storage(raw) {} 
    272245 
    273246  void* GetPointer() const 
     
    282255 
    283256  tStorage GetStorage() const 
     257  { 
     258    return storage; 
     259  } 
     260 
     261  tStorage& GetStorageReference() 
    284262  { 
    285263    return storage; 
Note: See TracChangeset for help on using the changeset viewer.