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>
35template <
typename KeyType,
typename LessKey = std::less<KeyType>>
36class LockSet :
public std::set<KeyType, LessKey>
49 typedef typename std::set<KeyType, LessKey>::iterator
iterator;
72template <
typename KeyType,
typename LessKey>
80template <
typename KeyType,
typename LessKey>
82: std::set<KeyType, LessKey>::set(lm), mutex_(new
Mutex())
87template <
typename KeyType,
typename LessKey>
93template <
typename KeyType,
typename LessKey>
103template <
typename KeyType,
typename LessKey>
107 return mutex_->try_lock();
111template <
typename KeyType,
typename LessKey>
115 return mutex_->unlock();
123template <
typename KeyType,
typename LessKey>
124std::pair<typename LockSet<KeyType, LessKey>::iterator,
bool>
128 std::pair<iterator, bool> ret = std::set<KeyType, LessKey>::insert(key);
137template <
typename KeyType,
typename LessKey>
142 std::set<KeyType, LessKey>::erase(key);
150template <
typename KeyType,
typename LessKey>
163template <
typename KeyType,
typename LessKey>
171 for (i = ll.begin(); i != ll.end(); ++i) {
186template <
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.
std::set< KeyType, LessKey >::iterator iterator
Iterator.
LockSet(const LockSet< KeyType, LessKey > &lm)
Copy constructor.
bool try_lock() const
Try to lock list.
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.