libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
qi::EventLoop Class Reference

#include <eventloop.hpp>

Public Member Functions

 EventLoop (const std::string &name="eventloop")
 
 ~EventLoop ()
 
bool isInEventLoopThread ()
 Return true if current thread is the event loop thread. More...
 
void start (int nthreads=0)
 Start in threaded mode. More...
 
void startThreadPool (int minWorkers=-1, int maxWorkers=-1, int minIdleWorkers=-1, int maxIdleWorkers=-1)
 Start in thread-pool mode: each asyncCall() will be run in parallel. More...
 
void join ()
 Wait for run thread to terminate. More...
 
void stop ()
 Ask main loop to terminate. More...
 
void run ()
 Run main loop in current thread. More...
 
void setEmergencyCallback (boost::function< void()> cb)
 Set callback to be called in case of a deadlock detection. More...
 
void setMaxThreads (unsigned int max)
 Set the maximum number of threads in the pool. More...
 
void * nativeHandle ()
 
void post (const boost::function< void()> &callback, uint64_t usDelay=0)
 Similar to async() but without cancelation or notification. More...
 
Future< void > monitorEventLoop (EventLoop *helper, uint64_t maxUsDelay)
 
template<typename R >
Future< R > async (boost::function< R()> callback, uint64_t usDelay=0)
 
Future< void > async (boost::function< void()> callback, uint64_t usDelay=0)
 

Public Attributes

EventLoopPrivate * _p
 
std::string _name
 

Detailed Description

Definition at line 35 of file eventloop.hpp.

Constructor & Destructor Documentation

qi::EventLoop::EventLoop ( const std::string &  name = "eventloop")

Create a new eventLoop. You must then call either start(), run() or startThreadPool() to start event processing.

qi::EventLoop::~EventLoop ( )

Member Function Documentation

template<typename R >
Future< R > qi::EventLoop::async ( boost::function< R()>  callback,
uint64_t  usDelay = 0 
)

Call given function once after given delay in microseconds.

Returns
a canceleable future

Definition at line 51 of file eventloop.hxx.

Future<void> qi::EventLoop::async ( boost::function< void()>  callback,
uint64_t  usDelay = 0 
)
bool qi::EventLoop::isInEventLoopThread ( )

Return true if current thread is the event loop thread.

void qi::EventLoop::join ( )

Wait for run thread to terminate.

Future<void> qi::EventLoop::monitorEventLoop ( EventLoop helper,
uint64_t  maxUsDelay 
)

Monitor event loop to detect deadlocks.

Parameters
helperan other event loop used for monitoring
maxUsDelaymaximum expected delay between an async() and its execution
Returns
a canceleable future. Invoke cancel() to terminate monitoring. In case an async() call does not execute in time, the future's error will be set.
void* qi::EventLoop::nativeHandle ( )
void qi::EventLoop::post ( const boost::function< void()> &  callback,
uint64_t  usDelay = 0 
)

Similar to async() but without cancelation or notification.

void qi::EventLoop::run ( )

Run main loop in current thread.

void qi::EventLoop::setEmergencyCallback ( boost::function< void()>  cb)

Set callback to be called in case of a deadlock detection.

void qi::EventLoop::setMaxThreads ( unsigned int  max)

Set the maximum number of threads in the pool.

void qi::EventLoop::start ( int  nthreads = 0)

Start in threaded mode.

void qi::EventLoop::startThreadPool ( int  minWorkers = -1,
int  maxWorkers = -1,
int  minIdleWorkers = -1,
int  maxIdleWorkers = -1 
)

Start in thread-pool mode: each asyncCall() will be run in parallel.

void qi::EventLoop::stop ( )

Ask main loop to terminate.

Member Data Documentation

std::string qi::EventLoop::_name

Definition at line 88 of file eventloop.hpp.

EventLoopPrivate* qi::EventLoop::_p

Definition at line 87 of file eventloop.hpp.


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