SHARE
TWEET

Untitled

a guest Jul 24th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<class T>
  2. class ThreadSafeData
  3. {
  4. public:
  5.     const T& get() const
  6.     {
  7.         std::lock_guard<std::mutex> _(m_mutex);
  8.         return m_data;
  9.  
  10.     }
  11.  
  12.     void get(T& data)
  13.     {
  14.         std::lock_guard<std::mutex> _(m_mutex);
  15.         data = m_data;
  16.     }
  17.  
  18.     void set(const T& data)
  19.     {
  20.         std::lock_guard<std::mutex> _(m_mutex);
  21.         m_data = data;
  22.     }
  23.  
  24. private:
  25.     T m_data;
  26.     mutable std::mutex m_mutex;
  27.  
  28. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top