4 // Lock_guard: a guard object using a lock such as helping_lock_t
6 template<typename LOCK>
10 typename LOCK::Status _state;
13 template< typename LOCK>
17 typename LOCK::Status _state1, _state2;
22 PUBLIC template<typename LOCK>
24 Lock_guard<LOCK>::Lock_guard()
27 , _state(LOCK::Invalid) // silence GCC warning
31 PUBLIC template<typename LOCK>
33 Lock_guard<LOCK>::Lock_guard(LOCK *l)
36 _state = _lock->test_and_set();
39 PUBLIC template<typename LOCK>
42 Lock_guard<LOCK>::lock(LOCK *l)
45 _state = l->test_and_set();
48 PUBLIC template<typename LOCK>
51 Lock_guard<LOCK>::try_lock(LOCK *l)
53 _state = l->test_and_set();
58 case LOCK::Not_locked:
59 _lock = l; // Was not locked -- unlock.
62 return false; // Error case -- lock not existent
66 PUBLIC template<typename LOCK>
69 Lock_guard<LOCK>::release()
78 PUBLIC template<typename LOCK>
80 Lock_guard<LOCK>::~Lock_guard()
86 PUBLIC template<typename LOCK>
89 Lock_guard<LOCK>::was_set(void)
91 return _state; //!_lock;
94 PUBLIC template<typename LOCK>
96 Lock_guard_2<LOCK>::Lock_guard_2()
100 PUBLIC template<typename LOCK>
102 Lock_guard_2<LOCK>::Lock_guard_2(LOCK *l1, LOCK *l2)
103 : _l1(l1 < l2 ? l1 : l2), _l2(l1 < l2 ? l2 : l1)
105 _state1 = _l1->test_and_set();
109 _state2 = _l2->test_and_set();
113 PUBLIC template<typename LOCK>
116 Lock_guard_2<LOCK>::lock(LOCK *l1, LOCK *l2)
118 _l1 = l1 < l2 ? l1 : l2;
119 _l2 = l1 < l2 ? l2 : l1;
120 if ((_state1 = _l1->test_and_set()) == LOCK::Invalid)
128 else if ((_state2 = _l2->test_and_set()) == LOCK::Invalid)
137 PUBLIC template<typename LOCK>
139 Lock_guard_2<LOCK>::~Lock_guard_2()