24 #ifndef __CORE_UTILS_RWLOCK_VECTOR_H_
25 #define __CORE_UTILS_RWLOCK_VECTOR_H_
27 #include <core/threading/read_write_lock.h>
28 #include <core/utils/refptr.h>
36 template <
typename Type>
43 virtual void lock_for_read()
const;
44 virtual void lock_for_write()
const;
45 virtual bool try_lock_for_read()
const;
46 virtual bool try_lock_for_write()
const;
47 virtual void unlock()
const;
50 void push_back_locked(
const Type& x);
51 void pop_back_locked();
52 void erase_locked(
typename std::vector<Type>::iterator pos);
53 void erase_locked(
typename std::vector<Type>::iterator first,
54 typename std::vector<Type>::iterator last);
76 template <
typename Type>
85 template <
typename Type>
87 : std::vector<Type>::vector(lv), __rwlock(new
ReadWriteLock())
92 template <
typename Type>
98 template <
typename Type>
102 __rwlock->lock_for_read();
107 template <
typename Type>
111 __rwlock->lock_for_write();
118 template <
typename Type>
122 return __rwlock->try_lock_for_read();
129 template <
typename Type>
133 return __rwlock->try_lock_for_write();
138 template <
typename Type>
142 return __rwlock->unlock();
149 template <
typename Type>
153 __rwlock->lock_for_write();
154 std::vector<Type>::push_back(x);
160 template <
typename Type>
164 __rwlock->lock_for_write();
165 std::vector<Type>::pop_back();
173 template <
typename Type>
177 __rwlock->lock_for_write();
178 std::vector<Type>::erase(pos);
186 template <
typename Type>
189 typename std::vector<Type>::iterator last)
191 __rwlock->lock_for_write();
192 std::vector<Type>::erase(first, last);
200 template <
typename Type>
214 template <
typename Type>
218 __rwlock->lock_for_write();
222 for (i = lv.begin(); i != lv.end(); ++i) {
238 template <
typename Type>
242 __rwlock->lock_for_write();
244 typename std::vector<Type>::const_iterator i;
245 for (i = v.begin(); i != v.end(); ++i) {
virtual bool try_lock_for_read() const
Try to lock vector for reading.
virtual void lock_for_write() const
Lock vector for writing.
virtual ~RWLockVector()
Destructor.
RWLockVector< Type > & operator=(const RWLockVector< Type > &lv)
Copy values from another RWLockVector.
Read/write lock to allow multiple readers but only a single writer on the resource at a time...
virtual bool try_lock_for_write() const
Try to lock vector for writing.
RefPtr<> is a reference-counting shared smartpointer.
void erase_locked(typename std::vector< Type >::iterator pos)
Erase given element with lock protection.
RefPtr< ReadWriteLock > rwlock() const
Get access to the internal read/write lock.
void pop_back_locked()
Remove last element with lock protection.
RWLockVector()
Constructor.
void push_back_locked(const Type &x)
Push element to vector at back with lock protection.
virtual void unlock() const
Unlock vector.
virtual void lock_for_read() const
Lock vector for reading.