summaryrefslogtreecommitdiff
path: root/src/components/include/utils/data_accessor.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/include/utils/data_accessor.h')
-rw-r--r--src/components/include/utils/data_accessor.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/components/include/utils/data_accessor.h b/src/components/include/utils/data_accessor.h
index 9be28a638b..1be7c3ab53 100644
--- a/src/components/include/utils/data_accessor.h
+++ b/src/components/include/utils/data_accessor.h
@@ -33,17 +33,15 @@
#define SRC_COMPONENTS_INCLUDE_UTILS_DATA_ACCESSOR_H_
#include "utils/lock.h"
-#include "utils/shared_ptr.h"
-// This class is for thread-safe access to data
+// This class is for thread-safe const access to data
template <class T>
class DataAccessor {
public:
- DataAccessor(const T& data, const sync_primitives::Lock& lock)
- : data_(data)
- , lock_(const_cast<sync_primitives::Lock&>(lock))
- , counter_(new uint32_t(0)) {
- lock_.Acquire();
+ DataAccessor(const T& data,
+ const std::shared_ptr<sync_primitives::BaseLock>& lock)
+ : data_(data), lock_(lock), counter_(new uint32_t(0)) {
+ lock_->Acquire();
}
DataAccessor(const DataAccessor<T>& other)
@@ -53,7 +51,7 @@ class DataAccessor {
~DataAccessor() {
if (0 == *counter_) {
- lock_.Release();
+ lock_->Release();
} else {
--(*counter_);
}
@@ -65,8 +63,9 @@ class DataAccessor {
private:
void* operator new(size_t size);
const T& data_;
- sync_primitives::Lock& lock_;
- utils::SharedPtr<uint32_t> counter_;
+ // Require that the lock lives at least as long as the DataAccessor
+ const std::shared_ptr<sync_primitives::BaseLock> lock_;
+ std::shared_ptr<uint32_t> counter_;
};
#endif // SRC_COMPONENTS_INCLUDE_UTILS_DATA_ACCESSOR_H_