00001 // AUTOMATICALLY GENERATED -- DO NOT EDIT! -*- c++ -*- 00002 00003 #ifndef switch_lock_h 00004 #define switch_lock_h 00005 00006 // 00007 // INTERFACE definition follows 00008 // 00009 00010 00011 class Context; 00012 00015 class Switch_lock 00016 { 00017 // Warning: This lock's member variables must not need a 00018 // constructor. Switch_lock instances must assume 00019 // zero-initialization or be initialized using the initialize() 00020 // member function. 00021 // Reason: to avoid overwriting the lock in the thread-ctor 00022 Context *_lock_owner; 00023 00024 public: 00025 // 00026 // Switch_lock inlines 00027 // 00028 00032 inline void initialize(); 00033 00037 inline Context * lock_owner() const; 00038 00042 inline bool test() const; 00043 00048 void lock(); 00049 00053 inline bool test_and_set(); 00054 00061 void clear(); 00062 00063 private: 00069 inline bool try_lock(); 00070 }; 00071 00072 // 00073 // IMPLEMENTATION includes follow (for use by inline functions) 00074 // 00075 00076 00077 #include "atomic.h" 00078 #include "globals.h" 00079 00080 // 00081 // IMPLEMENTATION of inline functions (and needed classes) 00082 // 00083 00084 00085 00086 // 00087 // Switch_lock inlines 00088 // 00089 00094 inline void 00095 Switch_lock::initialize() 00096 { 00097 _lock_owner = 0; 00098 } 00099 00100 00105 inline Context * 00106 Switch_lock::lock_owner() const 00107 { 00108 return _lock_owner; 00109 } 00110 00111 00116 inline bool 00117 Switch_lock::test() const 00118 { 00119 return _lock_owner; 00120 } 00121 00122 00127 inline bool 00128 Switch_lock::test_and_set() 00129 { 00130 if (_lock_owner == current()) 00131 return true; 00132 00133 lock(); 00134 00135 return false; 00136 } 00137 00138 #endif // switch_lock_h