25 #ifndef _CORE_UTILS_LOCK_SET_H_
26 #define _CORE_UTILS_LOCK_SET_H_
28 #include <core/threading/mutex.h>
29 #include <core/utils/refptr.h>
35 template <
typename KeyType,
typename LessKey = std::less<KeyType>>
36 class LockSet :
public std::set<KeyType, LessKey>
49 typedef typename std::set<KeyType, LessKey>::iterator
iterator;
72 template <
typename KeyType,
typename LessKey>
80 template <
typename KeyType,
typename LessKey>
82 : std::set<KeyType, LessKey>::set(lm), mutex_(new
Mutex())
87 template <
typename KeyType,
typename LessKey>
93 template <
typename KeyType,
typename LessKey>
103 template <
typename KeyType,
typename LessKey>
107 return mutex_->try_lock();
111 template <
typename KeyType,
typename LessKey>
115 return mutex_->unlock();
123 template <
typename KeyType,
typename LessKey>
124 std::pair<typename LockSet<KeyType, LessKey>::iterator,
bool>
128 std::pair<iterator, bool> ret = std::set<KeyType, LessKey>::insert(key);
137 template <
typename KeyType,
typename LessKey>
142 std::set<KeyType, LessKey>::erase(key);
150 template <
typename KeyType,
typename LessKey>
163 template <
typename KeyType,
typename LessKey>
171 for (i = ll.begin(); i != ll.end(); ++i) {
186 template <
typename KeyType,
typename LessKey>
192 typename std::set<KeyType, LessKey>::const_iterator i;
193 for (i = l.begin(); i != l.end(); ++i) {
void lock() const
Lock list.
void unlock() const
Unlock list.
RefPtr< Mutex > mutex() const
Get access to the internal mutex.
LockSet(const LockSet< KeyType, LessKey > &lm)
Copy constructor.
bool try_lock() const
Try to lock list.
std::set< KeyType, LessKey >::iterator iterator
Iterator.
LockSet< KeyType, LessKey > & operator=(const LockSet< KeyType, LessKey > &ll)
Copy values from another LockSet.
std::pair< iterator, bool > insert_locked(const KeyType &key)
Insert item with lock.
virtual ~LockSet()
Destructor.
LockSet< KeyType, LessKey > & operator=(const std::set< KeyType, LessKey > &l)
Copy values from a standard set.
void erase_locked(const KeyType &key)
Remove item with lock.
Mutex mutual exclusion lock.
RefPtr<> is a reference-counting shared smartpointer.
Fawkes library namespace.