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>
34template <
typename KeyType,
typename ValueType,
typename LessKey = std::less<KeyType>>
35class RWLockMap :
public std::map<KeyType, ValueType, LessKey>
66template <
typename KeyType,
typename ValueType,
typename LessKey>
74template <
typename KeyType,
typename ValueType,
typename LessKey>
76: std::map<KeyType, ValueType, LessKey>::map(lm), rwlock_(new
ReadWriteLock())
81template <
typename KeyType,
typename ValueType,
typename LessKey>
87template <
typename KeyType,
typename ValueType,
typename LessKey>
91 rwlock_->lock_for_read();
95template <
typename KeyType,
typename ValueType,
typename LessKey>
99 rwlock_->lock_for_write();
105template <
typename KeyType,
typename ValueType,
typename LessKey>
109 return rwlock_->try_lock_for_read();
115template <
typename KeyType,
typename ValueType,
typename LessKey>
119 return rwlock_->try_lock_for_write();
123template <
typename KeyType,
typename ValueType,
typename LessKey>
127 return rwlock_->unlock();
134template <
typename KeyType,
typename ValueType,
typename LessKey>
138 rwlock_->lock_for_write();
139 std::map<KeyType, ValueType, LessKey>::erase(key);
147template <
typename KeyType,
typename ValueType,
typename LessKey>
bool try_lock_for_write()
Try to lock list for writing.
void lock_for_read()
Lock list for reading.
void erase_locked(const KeyType &key)
Remove item with lock.
void unlock()
Unlock list.
RefPtr< ReadWriteLock > rwlock() const
Get access to the internal rwlock.
bool try_lock_for_read()
Try to lock list for reading.
void lock_for_write()
Lock list for writing.
virtual ~RWLockMap()
Destructor.
Read/write lock to allow multiple readers but only a single writer on the resource at a time.
RefPtr<> is a reference-counting shared smartpointer.
Fawkes library namespace.