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();
50 case LOCK::Not_locked:
51 _lock = l; // Was not locked -- unlock.
54 return false; // Error case -- lock not existent
58 PUBLIC template<typename LOCK>
61 Lock_guard<LOCK>::release()
70 PUBLIC template<typename LOCK>
72 Lock_guard<LOCK>::~Lock_guard()
78 PUBLIC template<typename LOCK>
81 Lock_guard<LOCK>::was_set(void)
83 return _state; //!_lock;
86 PUBLIC template<typename LOCK>
88 Lock_guard_2<LOCK>::Lock_guard_2()
92 PUBLIC template<typename LOCK>
94 Lock_guard_2<LOCK>::Lock_guard_2(LOCK *l1, LOCK *l2)
95 : _l1(l1 < l2 ? l1 : l2), _l2(l1 < l2 ? l2 : l1)
97 _state1 = _l1->test_and_set();
101 _state2 = _l2->test_and_set();
105 PUBLIC template<typename LOCK>
108 Lock_guard_2<LOCK>::lock(LOCK *l1, LOCK *l2)
110 _l1 = l1 < l2 ? l1 : l2;
111 _l2 = l1 < l2 ? l2 : l1;
112 if ((_state1 = _l1->test_and_set()) == LOCK::Invalid)
120 else if ((_state2 = _l2->test_and_set()) == LOCK::Invalid)
129 PUBLIC template<typename LOCK>
131 Lock_guard_2<LOCK>::~Lock_guard_2()