STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
shared_timed_mutex Class Reference

Public Member Functions

 shared_timed_mutex () _NOEXCEPT
 
 ~shared_timed_mutex () _NOEXCEPT
 
void lock ()
 
bool try_lock ()
 
template<class _Rep , class _Period >
bool try_lock_for (const chrono::duration< _Rep, _Period > &_Rel_time)
 
template<class _Clock , class _Duration >
bool try_lock_until (const chrono::time_point< _Clock, _Duration > &_Abs_time)
 
void unlock ()
 
void lock_shared ()
 
bool try_lock_shared ()
 
template<class _Rep , class _Period >
bool try_lock_shared_for (const chrono::duration< _Rep, _Period > &_Rel_time)
 
template<class _Time >
bool _Try_lock_shared_until (_Time _Abs_time)
 
template<class _Clock , class _Duration >
bool try_lock_shared_until (const chrono::time_point< _Clock, _Duration > &_Abs_time)
 
bool try_lock_shared_until (const xtime *_Abs_time)
 
void unlock_shared ()
 
 shared_timed_mutex (const shared_timed_mutex &)=delete
 
shared_timed_mutexoperator= (const shared_timed_mutex &)=delete
 

Private Types

typedef unsigned int _Read_cnt_t
 

Private Attributes

mutex _Mymtx
 
condition_variable _Read_queue
 
condition_variable _Write_queue
 
_Read_cnt_t _Readers
 
bool _Writing
 

Static Private Attributes

static constexpr _Read_cnt_t _Max_readers = _Read_cnt_t(-1)
 

Member Typedef Documentation

typedef unsigned int shared_timed_mutex::_Read_cnt_t
private

Constructor & Destructor Documentation

shared_timed_mutex::shared_timed_mutex ( )
inline
97  _Readers(0), _Writing(false)
98  { // default construct
99  }
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Read_queue
Definition: shared_mutex:250
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
_Read_cnt_t _Readers
Definition: shared_mutex:251
shared_timed_mutex::~shared_timed_mutex ( )
inline
102  { // destroy the object
103  }
shared_timed_mutex::shared_timed_mutex ( const shared_timed_mutex )
delete

Member Function Documentation

template<class _Time >
bool shared_timed_mutex::_Try_lock_shared_until ( _Time  _Abs_time)
inline
202  { // try to lock non-exclusive until absolute time
203  auto _Can_acquire = [this] {
204  return (!_Writing && _Readers < _Max_readers); };
205 
206  unique_lock<mutex> _Lock(_Mymtx);
207 
208  if (!_Write_queue.wait_until(_Lock, _Abs_time, _Can_acquire))
209  return (false);
210 
211  ++_Readers;
212  return (true);
213  }
Definition: mutex:259
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
static constexpr _Read_cnt_t _Max_readers
Definition: shared_mutex:92
_Cv_status wait_until(unique_lock< mutex > &_Lck, const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: mutex:601
_Read_cnt_t _Readers
Definition: shared_mutex:251
void shared_timed_mutex::lock ( )
inline
106  { // lock exclusive
107  unique_lock<mutex> _Lock(_Mymtx);
108  while (_Writing)
109  _Write_queue.wait(_Lock);
110  _Writing = true;
111  while (0 < _Readers)
112  _Read_queue.wait(_Lock); // wait for writing, no readers
113  }
Definition: mutex:259
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Read_queue
Definition: shared_mutex:250
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:564
_Read_cnt_t _Readers
Definition: shared_mutex:251
void shared_timed_mutex::lock_shared ( )
inline
172  { // lock non-exclusive
173  unique_lock<mutex> _Lock(_Mymtx);
174  while (_Writing || _Readers == _Max_readers)
175  _Write_queue.wait(_Lock);
176  ++_Readers;
177  }
Definition: mutex:259
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
void wait(unique_lock< mutex > &_Lck)
Definition: mutex:564
static constexpr _Read_cnt_t _Max_readers
Definition: shared_mutex:92
_Read_cnt_t _Readers
Definition: shared_mutex:251
shared_timed_mutex& shared_timed_mutex::operator= ( const shared_timed_mutex )
delete
bool shared_timed_mutex::try_lock ( )
inline
116  { // try to lock exclusive
117  lock_guard<mutex> _Lock(_Mymtx);
118  if (_Writing || 0 < _Readers)
119  return (false);
120  else
121  { // set writing, no readers
122  _Writing = true;
123  return (true);
124  }
125  }
mutex _Mymtx
Definition: shared_mutex:249
bool _Writing
Definition: shared_mutex:252
Definition: mutex:183
_Read_cnt_t _Readers
Definition: shared_mutex:251
template<class _Rep , class _Period >
bool shared_timed_mutex::try_lock_for ( const chrono::duration< _Rep, _Period > &  _Rel_time)
inline
131  { // try to lock for duration
132  return (try_lock_until(chrono::steady_clock::now() + _Rel_time));
133  }
bool try_lock_until(const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: shared_mutex:137
static time_point now() _NOEXCEPT
Definition: chrono:1001
bool shared_timed_mutex::try_lock_shared ( )
inline
180  { // try to lock non-exclusive
181  lock_guard<mutex> _Lock(_Mymtx);
182  if (_Writing || _Readers == _Max_readers)
183  return (false);
184  else
185  { // count another reader
186  ++_Readers;
187  return (true);
188  }
189  }
mutex _Mymtx
Definition: shared_mutex:249
bool _Writing
Definition: shared_mutex:252
Definition: mutex:183
static constexpr _Read_cnt_t _Max_readers
Definition: shared_mutex:92
_Read_cnt_t _Readers
Definition: shared_mutex:251
template<class _Rep , class _Period >
bool shared_timed_mutex::try_lock_shared_for ( const chrono::duration< _Rep, _Period > &  _Rel_time)
inline
195  { // try to lock non-exclusive for relative time
196  return (try_lock_shared_until(_Rel_time
198  }
bool try_lock_shared_until(const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: shared_mutex:217
static time_point now() _NOEXCEPT
Definition: chrono:1001
template<class _Clock , class _Duration >
bool shared_timed_mutex::try_lock_shared_until ( const chrono::time_point< _Clock, _Duration > &  _Abs_time)
inline
219  { // try to lock non-exclusive until absolute time
220  return (_Try_lock_shared_until(_Abs_time));
221  }
bool _Try_lock_shared_until(_Time _Abs_time)
Definition: shared_mutex:201
bool shared_timed_mutex::try_lock_shared_until ( const xtime _Abs_time)
inline
224  { // try to lock non-exclusive until absolute time
225  return (_Try_lock_shared_until(_Abs_time));
226  }
bool _Try_lock_shared_until(_Time _Abs_time)
Definition: shared_mutex:201
template<class _Clock , class _Duration >
bool shared_timed_mutex::try_lock_until ( const chrono::time_point< _Clock, _Duration > &  _Abs_time)
inline
139  { // try to lock until time point
140  auto _Not_writing = [this] { return (!_Writing); };
141  auto _Zero_readers = [this] { return (_Readers == 0); };
142  unique_lock<mutex> _Lock(_Mymtx);
143 
144  if (!_Write_queue.wait_until(_Lock, _Abs_time, _Not_writing))
145  return (false);
146 
147  _Writing = true;
148 
149  if (!_Read_queue.wait_until(_Lock, _Abs_time, _Zero_readers))
150  { // timeout, leave writing state
151  _Writing = false;
152  _Lock.unlock(); // unlock before notifying, for efficiency
154  return (false);
155  }
156 
157  return (true);
158  }
Definition: mutex:259
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Read_queue
Definition: shared_mutex:250
void notify_all() _NOEXCEPT
Definition: mutex:559
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
_Cv_status wait_until(unique_lock< mutex > &_Lck, const chrono::time_point< _Clock, _Duration > &_Abs_time)
Definition: mutex:601
_Read_cnt_t _Readers
Definition: shared_mutex:251
void shared_timed_mutex::unlock ( )
inline
161  { // unlock exclusive
162  { // unlock before notifying, for efficiency
163  lock_guard<mutex> _Lock(_Mymtx);
164 
165  _Writing = false;
166  }
167 
169  }
mutex _Mymtx
Definition: shared_mutex:249
void notify_all() _NOEXCEPT
Definition: mutex:559
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
Definition: mutex:183
void shared_timed_mutex::unlock_shared ( )
inline
229  { // unlock non-exclusive
230  _Read_cnt_t _Local_readers;
231  bool _Local_writing;
232 
233  { // unlock before notifying, for efficiency
234  lock_guard<mutex> _Lock(_Mymtx);
235  --_Readers;
236  _Local_readers = _Readers;
237  _Local_writing = _Writing;
238  }
239 
240  if (_Local_writing && _Local_readers == 0)
242  else if (!_Local_writing && _Local_readers == _Max_readers - 1)
244  }
void notify_one() _NOEXCEPT
Definition: mutex:554
mutex _Mymtx
Definition: shared_mutex:249
condition_variable _Read_queue
Definition: shared_mutex:250
void notify_all() _NOEXCEPT
Definition: mutex:559
condition_variable _Write_queue
Definition: shared_mutex:250
bool _Writing
Definition: shared_mutex:252
unsigned int _Read_cnt_t
Definition: shared_mutex:91
Definition: mutex:183
static constexpr _Read_cnt_t _Max_readers
Definition: shared_mutex:92
_Read_cnt_t _Readers
Definition: shared_mutex:251

Member Data Documentation

constexpr _Read_cnt_t shared_timed_mutex::_Max_readers = _Read_cnt_t(-1)
staticprivate
mutex shared_timed_mutex::_Mymtx
private
condition_variable shared_timed_mutex::_Read_queue
private
_Read_cnt_t shared_timed_mutex::_Readers
private
condition_variable shared_timed_mutex::_Write_queue
private
bool shared_timed_mutex::_Writing
private

The documentation for this class was generated from the following file: