class single_mutex_single_condvar
{
//@cond
- std::mutex m_mutex;
+ std::mutex m_mutex;
std::condition_variable m_condvar;
+ bool m_wakeup;
typedef std::unique_lock< std::mutex > unique_lock;
//@endcond
typedef PublicationRecord type; ///< publication record type
};
+ /// Default ctor
+ single_mutex_single_condvar()
+ : m_wakeup( false )
+ {}
+
/// Does nothing
template <typename PublicationRecord>
void prepare( PublicationRecord& /*rec*/ )
{
if ( fc.get_operation( rec ) >= req_Operation ) {
unique_lock lock( m_mutex );
- if ( fc.get_operation( rec ) >= req_Operation )
- return m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds )) == std::cv_status::no_timeout;
+ if ( fc.get_operation( rec ) >= req_Operation ) {
+ if ( m_wakeup ) {
+ m_wakeup = false;
+ return true;
+ }
+
+ bool ret = m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds ) ) == std::cv_status::no_timeout;
+ m_wakeup = false;
+ return ret;
+ }
}
return false;
}
/// Calls condition variable function \p notify_all()
template <typename FCKernel, typename PublicationRecord>
- void notify( FCKernel& /*fc*/, PublicationRecord& /*rec*/ )
+ void notify( FCKernel& fc, PublicationRecord& /*rec*/ )
{
- m_condvar.notify_all();
+ wakeup( fc );
}
/// Calls condition variable function \p notify_all()
template <typename FCKernel>
void wakeup( FCKernel& /*fc*/ )
{
+ unique_lock lock( m_mutex );
+ m_wakeup = true;
m_condvar.notify_all();
}
};
class single_mutex_multi_condvar
{
//@cond
- std::mutex m_mutex;
+ std::mutex m_mutex;
+ bool m_wakeup;
typedef std::unique_lock< std::mutex > unique_lock;
//@endcond
};
};
+ /// Default ctor
+ single_mutex_multi_condvar()
+ : m_wakeup( false )
+ {}
+
/// Does nothing
template <typename PublicationRecord>
void prepare( PublicationRecord& /*rec*/ )
{
if ( fc.get_operation( rec ) >= req_Operation ) {
unique_lock lock( m_mutex );
- if ( fc.get_operation( rec ) >= req_Operation )
- return rec.m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds )) == std::cv_status::no_timeout;
+
+ if ( fc.get_operation( rec ) >= req_Operation ) {
+ if ( m_wakeup ) {
+ m_wakeup = false;
+ return true;
+ }
+
+ bool ret = rec.m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds ) ) == std::cv_status::no_timeout;
+ m_wakeup = false;
+ return ret;
+ }
}
return false;
}
template <typename FCKernel, typename PublicationRecord>
void notify( FCKernel& /*fc*/, PublicationRecord& rec )
{
+ unique_lock lock( m_mutex );
+ m_wakeup = true;
rec.m_condvar.notify_one();
}
//@cond
std::mutex m_mutex;
std::condition_variable m_condvar;
+ bool m_wakeup;
+
+ type()
+ : m_wakeup( false )
+ {}
//@endcond
};
};
{
if ( fc.get_operation( rec ) >= req_Operation ) {
unique_lock lock( rec.m_mutex );
- if ( fc.get_operation( rec ) >= req_Operation )
- return rec.m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds )) == std::cv_status::no_timeout;
+
+ if ( fc.get_operation( rec ) >= req_Operation ) {
+ if ( rec.m_wakeup ) {
+ rec.m_wakeup = false;
+ return true;
+ }
+
+ bool ret = rec.m_condvar.wait_for( lock, std::chrono::milliseconds( c_nWaitMilliseconds ) ) == std::cv_status::no_timeout;
+ rec.m_wakeup = false;
+ return ret;
+ }
}
return false;
}
template <typename FCKernel, typename PublicationRecord>
void notify( FCKernel& /*fc*/, PublicationRecord& rec )
{
+ unique_lock lock( rec.m_mutex );
+ rec.m_wakeup = true;
rec.m_condvar.notify_one();
}