24 #ifndef __CORE_UTILS_RWLOCK_MAP_H_ 25 #define __CORE_UTILS_RWLOCK_MAP_H_ 27 #include <core/threading/read_write_lock.h> 28 #include <core/utils/refptr.h> 34 template <
typename KeyType,
36 typename LessKey = std::less<KeyType> >
37 class RWLockMap :
public std::map<KeyType, ValueType, LessKey>
71 template <
typename KeyType,
typename ValueType,
typename LessKey>
80 template <
typename KeyType,
typename ValueType,
typename LessKey>
82 :
std::map<KeyType, ValueType, LessKey>::map(lm), __rwlock(new
ReadWriteLock())
87 template <
typename KeyType,
typename ValueType,
typename LessKey>
93 template <
typename KeyType,
typename ValueType,
typename LessKey>
97 __rwlock->lock_for_read();
102 template <
typename KeyType,
typename ValueType,
typename LessKey>
106 __rwlock->lock_for_write();
113 template <
typename KeyType,
typename ValueType,
typename LessKey>
117 return __rwlock->try_lock_for_read();
124 template <
typename KeyType,
typename ValueType,
typename LessKey>
128 return __rwlock->try_lock_for_write();
133 template <
typename KeyType,
typename ValueType,
typename LessKey>
137 return __rwlock->unlock();
145 template <
typename KeyType,
typename ValueType,
typename LessKey>
149 __rwlock->lock_for_write();
150 std::map<KeyType, ValueType, LessKey>::erase(key);
159 template <
typename KeyType,
typename ValueType,
typename LessKey>
bool try_lock_for_write()
Try to lock list for writing.
bool try_lock_for_read()
Try to lock list for reading.
Fawkes library namespace.
void lock_for_read()
Lock list for reading.
virtual ~RWLockMap()
Destructor.
void unlock()
Unlock list.
Read/write lock to allow multiple readers but only a single writer on the resource at a time...
RefPtr< ReadWriteLock > rwlock() const
Get access to the internal rwlock.
RefPtr<> is a reference-counting shared smartpointer.
void erase_locked(const KeyType &key)
Remove item with lock.
void lock_for_write()
Lock list for writing.