MACE
1.0.0
|
00001 #ifndef _MACE_CMT_SIGNALS_HPP 00002 #define _MACE_CMT_SIGNALS_HPP 00003 #include <boost/signal.hpp> 00004 #include <boost/bind.hpp> 00005 #include <mace/cmt/task.hpp> 00006 #include <mace/cmt/thread.hpp> 00007 00008 namespace mace { namespace cmt { 00009 template<typename T> 00010 inline T wait( boost::signal<void(T)>& sig, const microseconds& timeout_us=microseconds::max() ) { 00011 typename promise<T>::ptr p(new promise<T>()); 00012 void (promise<T>::*m)( const T& ) = &promise<T>::set_value; 00013 boost::signals::scoped_connection c = sig.connect( boost::bind(m,p,_1) ); 00014 return p->wait( timeout_us ); 00015 } 00016 00017 inline void wait( boost::signal<void()>& sig, const microseconds& timeout_us=microseconds::max() ) { 00018 promise<void_t>::ptr p(new promise<void_t>()); 00019 void (promise<void_t>::*m)( const void_t& ) = &promise<void_t>::set_value; 00020 boost::signals::scoped_connection c = sig.connect( boost::bind(m,p,void_t()) ); 00021 p->wait( timeout_us ); 00022 } 00023 } } // mace::cmt 00024 00025 #endif