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,
typename ValueType,
typename LessKey = std::less<KeyType>>
35 class RWLockMap :
public std::map<KeyType, ValueType, LessKey>
66 template <
typename KeyType,
typename ValueType,
typename LessKey>
74 template <
typename KeyType,
typename ValueType,
typename LessKey>
76 : std::map<KeyType, ValueType, LessKey>::map(lm), rwlock_(new
ReadWriteLock())
81 template <
typename KeyType,
typename ValueType,
typename LessKey>
87 template <
typename KeyType,
typename ValueType,
typename LessKey>
91 rwlock_->lock_for_read();
95 template <
typename KeyType,
typename ValueType,
typename LessKey>
99 rwlock_->lock_for_write();
105 template <
typename KeyType,
typename ValueType,
typename LessKey>
109 return rwlock_->try_lock_for_read();
115 template <
typename KeyType,
typename ValueType,
typename LessKey>
119 return rwlock_->try_lock_for_write();
123 template <
typename KeyType,
typename ValueType,
typename LessKey>
127 return rwlock_->unlock();
134 template <
typename KeyType,
typename ValueType,
typename LessKey>
138 rwlock_->lock_for_write();
139 std::map<KeyType, ValueType, LessKey>::erase(key);
147 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.