| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d3e0229 commit ded4a5e
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,54 @@ | |||
| 1 | + #ifndef SRC_NODE_THREADSAFE_COW_INL_H_ | ||
| 2 | + #define SRC_NODE_THREADSAFE_COW_INL_H_ | ||
| 3 | + | ||
| 4 | + #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| 5 | + | ||
| 6 | + namespace node { | ||
| 7 | + | ||
| 8 | + template <typename T> | ||
| 9 | + T* CopyOnWrite<T>::write() { | ||
| 10 | + if (data_.use_count() > 1l) { | ||
| 11 | + data_ = std::make_shared<T>(*data_); | ||
| 12 | + } | ||
| 13 | + return data_.get(); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + template <typename T> | ||
| 17 | + ThreadsafeCopyOnWrite<T>::Read::Read(const ThreadsafeCopyOnWrite<T>* cow) | ||
| 18 | + : cow_(cow), lock_(cow->impl_->mutex) {} | ||
| 19 | + | ||
| 20 | + template <typename T> | ||
| 21 | + const T& ThreadsafeCopyOnWrite<T>::Read::operator*() const { | ||
| 22 | + return cow_->impl_->data; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + template <typename T> | ||
| 26 | + const T* ThreadsafeCopyOnWrite<T>::Read::operator->() const { | ||
| 27 | + return &cow_->impl_->data; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + template <typename T> | ||
| 31 | + ThreadsafeCopyOnWrite<T>::Write::Write(ThreadsafeCopyOnWrite<T>* cow) | ||
| 32 | + : cow_(cow), impl_(cow->impl_.write()), lock_(impl_->mutex) {} | ||
| 33 | + | ||
| 34 | + template <typename T> | ||
| 35 | + T& ThreadsafeCopyOnWrite<T>::Write::operator*() { | ||
| 36 | + return impl_->data; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + template <typename T> | ||
| 40 | + T* ThreadsafeCopyOnWrite<T>::Write::operator->() { | ||
| 41 | + return &impl_->data; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + template <typename T> | ||
| 45 | + ThreadsafeCopyOnWrite<T>::Impl::Impl(const Impl& other) { | ||
| 46 | + RwLock::ScopedReadLock lock(other.mutex); | ||
| 47 | + data = other.data; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + } // namespace node | ||
| 51 | + | ||
| 52 | + #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| 53 | + | ||
| 54 | + #endif // SRC_NODE_THREADSAFE_COW_INL_H_ | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments