Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

LockSet.h

Go to the documentation of this file.
00001 #ifndef LOCK_SET_H 00002 #define LOCK_SET_H 00003 00004 #include <ext/hash_map> 00005 00006 #include "common.h" 00007 00008 BOREALIS_NAMESPACE_BEGIN; 00009 00010 class LockSet { 00011 public: 00012 ILockable &getLock() { return _lock; } 00013 00014 bool take_lock(int key) { 00015 VERIFY_CALLER_HOLDS_LOCK(_lock); 00016 if (_locked[key]) 00017 return false; 00018 else { 00019 _locked[key] = true; 00020 return true; 00021 } 00022 } 00023 00024 void release_lock(int key) { 00025 VERIFY_CALLER_HOLDS_LOCK(_lock); 00026 if (!_locked[key]) 00027 ERROR << "Extra release on key " << key; 00028 _locked[key] = false; 00029 } 00030 00031 private: 00032 // Any thread that's accessing _locked must hold this lock. 00033 PtMutex _lock; 00034 __gnu_cxx::hash_map<int, bool> _locked; 00035 }; 00036 00037 BOREALIS_NAMESPACE_END; 00038 00039 #endif

Generated on Fri Nov 12 15:15:21 2004 for Borealis by doxygen 1.3.8