diff options
author | JackLivio <jack@livio.io> | 2018-10-19 15:05:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 15:05:09 -0400 |
commit | d36316738785c96dab2ee892762ed08c059fffde (patch) | |
tree | 168a7c0705b5bc8f0dee7ce4b511ccf71759d9b4 /src/components/include/utils/data_accessor.h | |
parent | 7f7fcbb998fb17f2954fd103349af67ea9b71a3f (diff) | |
parent | 83c5e805346d55ec7fb9f4ba8b6f6855d992273e (diff) | |
download | sdl_core-hotfix/templates_updates.tar.gz |
Merge pull request #2572 from smartdevicelink/release/5.0.05.0.0hotfix/templates_updatesfeature/show_app_menufeature/progress_bar_seekfeature/open-menu-rpcfeature/open-menu-rfeature/button
Release 5.0.0
Diffstat (limited to 'src/components/include/utils/data_accessor.h')
-rw-r--r-- | src/components/include/utils/data_accessor.h | 19 |
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_ |