Last active
March 11, 2020 18:44
-
-
Save rajkumar-p/11a7d3f7e364cecb6b5ca329d6b30b9f to your computer and use it in GitHub Desktop.
NodeListWithLock Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename T> | |
| class NodeListWithLock | |
| { | |
| private: | |
| T _data; | |
| std::mutex _mux; | |
| public: | |
| NodeListWithLock<T> _next; | |
| public: | |
| NodeListWithLock(T data); | |
| T data(); | |
| void lock_node(); | |
| void unlock_node(); | |
| }; | |
| template<typename T> | |
| NodeListWithLock<T>::NodeListWithLock(T data) | |
| : _data(data), _next(nullptr) | |
| { | |
| } | |
| template<typename T> | |
| T NodeListWithLock<T>::data() | |
| { | |
| return _data; | |
| } | |
| template<typename T> | |
| void NodeListWithLock<T>::lock_node() | |
| { | |
| this->_mux.lock(); | |
| } | |
| template<typename T> | |
| void NodeListWithLock<T>::unlock_node() | |
| { | |
| this->_mux.unlock(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment