Apache Mesos
Classes | Macros | Functions
synchronized.hpp File Reference
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <type_traits>
#include <glog/logging.h>
#include <stout/preprocessor.hpp>

Go to the source code of this file.

Classes

class  Synchronized< T >
 

Macros

#define SYNCHRONIZED_PREFIX   CAT(__synchronizer_, __LINE__)
 
#define SYNCHRONIZED_VAR   CAT(SYNCHRONIZED_PREFIX, _var__)
 
#define SYNCHRONIZED_LABEL   CAT(SYNCHRONIZED_PREFIX, _label__)
 
#define synchronized(m)
 

Functions

template<typename T >
Synchronized< T > synchronize (T *t)
 
Synchronized< std::atomic_flag > synchronize (std::atomic_flag *lock)
 
template<typename T >
T * synchronized_get_pointer (T **t)
 
template<typename T >
T * synchronized_get_pointer (T *t)
 
template<typename CV , typename Lock >
void synchronized_wait (CV *cv, Lock *lock)
 Waits on the condition variable associated with 'lock' which has already been synchronized. More...
 
template<>
void synchronized_wait (std::condition_variable *cv, std::mutex *mutex)
 
template<typename Lock >
void synchronized_wait (std::condition_variable_any *cv, Lock *lock)=delete
 There is a known bug around 'std::condition_variable_any' in 'libstdc++' distributed 'devtoolset-2', and also general issues around the use of 'std::condition_variable_any' with 'std::recursive_mutex'. More...
 

Macro Definition Documentation

#define synchronized (   m)
Value:
if (Synchronized<typename std::remove_pointer<decltype(m)>::type> \
Synchronized< T > synchronize(T *t)
Definition: synchronized.hpp:52
#define SYNCHRONIZED_VAR
Definition: synchronized.hpp:97
Definition: synchronized.hpp:27
Try< uint32_t > type(const std::string &path)
T * synchronized_get_pointer(T **t)
Definition: synchronized.hpp:78
#define SYNCHRONIZED_LABEL
Definition: synchronized.hpp:98
#define SYNCHRONIZED_LABEL   CAT(SYNCHRONIZED_PREFIX, _label__)
#define SYNCHRONIZED_PREFIX   CAT(__synchronizer_, __LINE__)
#define SYNCHRONIZED_VAR   CAT(SYNCHRONIZED_PREFIX, _var__)

Function Documentation

template<typename T >
Synchronized<T> synchronize ( T *  t)
Synchronized<std::atomic_flag> synchronize ( std::atomic_flag *  lock)
inline
template<typename T >
T* synchronized_get_pointer ( T **  t)
template<typename T >
T* synchronized_get_pointer ( T *  t)
template<typename CV , typename Lock >
void synchronized_wait ( CV *  cv,
Lock *  lock 
)

Waits on the condition variable associated with 'lock' which has already been synchronized.

Currently, the only supported implementation is for 'std::condition_variable' associated with a 'std::mutex'.

Parameters
cvThe condition variable.
lockThe lock associated with the condition variable.
Precondition
'lock' is already owned by the calling thread.
Postcondition
'lock' is still owned by the calling thread.
Returns
Nothing.
Examples:
/mesos/3rdparty/stout/include/stout/synchronized.hpp.
template<>
void synchronized_wait ( std::condition_variable *  cv,
std::mutex *  mutex 
)
inline
template<typename Lock >
void synchronized_wait ( std::condition_variable_any *  cv,
Lock *  lock 
)
delete

There is a known bug around 'std::condition_variable_any' in 'libstdc++' distributed 'devtoolset-2', and also general issues around the use of 'std::condition_variable_any' with 'std::recursive_mutex'.

Hence, this function is currently deleted until both issues are resolved.

See also
https://rhn.redhat.com/errata/RHBA-2014-1035.html
http://stackoverflow.com/questions/11752155/behavior-of-condition-variable-any-when-used-with-a-recursive-mutex