- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- Class List
- Class Hierarchy
- Class Members

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

Class to handle eventloop. . More...

`#include <eventloop.hpp>`

## Public Member Functions
| EventLoop (std::string name="eventloop", int nthreads=0, bool spawnOnOverload=true)
| Creates a group of threads running event loops. More...
| EventLoop (std::string name, int nthreads, int minThreads, int maxThreads, bool spawnOnOverload)
| ~EventLoop () override
| Default destructor. More...
bool | isInThisContext () const override
| Checks if the current thread is one of the event loop threads. More...
void | start (int threadCount=0)
| Starts the event loop. Does nothing if already started. More...
void | join ()
| Waits for all threads of the pool to terminate. More...
void | stop ()
| Stops all running threads. Does nothing if already stopped. More...
void | setEmergencyCallback (boost::function< void()> cb)
| Sets callback to be called in case of a deadlock detection. More...
void | setMinThreads (unsigned int min)
| Sets the minimum number of threads in the pool. More...
void | setMaxThreads (unsigned int max)
| Sets the maximum number of threads in the pool. More...
void * | nativeHandle ()
| Internal function. More...
void | post (const boost::function< void()> &callback, uint64_t usDelay)
| Similar to async() but without cancelation or notification. More...
void | post (const boost::function< void()> &callback, qi::Duration delay)
void | post (const boost::function< void()> &callback, qi::SteadyClockTimePoint timepoint)
Future< void > | monitorEventLoop (EventLoop *helper, uint64_t maxUsDelay)
| Monitors event loop to detect deadlocks. More...
template<typename R >
Future< R > | async (const boost::function< R()> &callback, uint64_t usDelay)
| Calls given function once after given delay in microseconds. More...
Future< void > | async (const boost::function< void()> &callback, uint64_t usDelay)
Future< void > | async (const boost::function< void()> &callback, qi::Duration delay) override
Future< void > | async (const boost::function< void()> &callback, qi::SteadyClockTimePoint timepoint) override
Public Member Functions inherited from qi::ExecutionContext
virtual | ~ExecutionContext ()
template<typename R >
boost::disable_if < std::is_same< R, void > , qi::Future< R > >::type | async (const boost::function< R()> &callback, qi::Duration delay)
template<typename R >
boost::disable_if < std::is_same< R, void > , qi::Future< R > >::type | async (const boost::function< R()> &callback, qi::SteadyClockTimePoint tp)
template<typename R >
qi::Future< R > | async (const detail::Function< R()> &callback)
template<typename F >
void | post (F &&callback, ExecutionOptions options=defaultExecutionOptions())
| post a callback to be executed as soon as possible More...
template<typename F , typename R = ka::Decay<decltype(std::declval<F>()())>>
qi::Future< R > | asyncAt (F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options=defaultExecutionOptions())
| call a callback asynchronously to be executed on tp More...
template<typename F , typename R = ka::Decay<decltype(std::declval<F>()())>>
qi::Future< R > | asyncDelay (F &&callback, qi::Duration delay, ExecutionOptions options=defaultExecutionOptions())
| call a callback asynchronously to be executed in delay More...
template<typename F >
auto | async (F &&callback, ExecutionOptions options=defaultExecutionOptions()) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0), options))
template<typename F , typename R >
Future< R > | asyncAt (F &&callback, qi::SteadyClockTimePoint tp, ExecutionOptions options)
template<typename F , typename R >
Future< R > | asyncDelay (F &&callback, qi::Duration delay, ExecutionOptions options)

## Additional Inherited Members

## Detailed Description

Class to handle eventloop. .

Definition at line 37 of file eventloop.hpp.

## Constructor & Destructor Documentation

qi::EventLoop::EventLoop | ( | std::string | name = `"eventloop"`,
|  | int | nthreads = `0`,
|  | bool | spawnOnOverload = `true`
| ) |  |
| explicit

Creates a group of threads running event loops.

Parameters

  name | Name of the event loop to create.
  nthreads | Initial number of threads. If lower or equal to 0, the event loop will use in order: the value of the environment variable QI_EVENTLOOP_THREAD_COUNT if it's set, the value returned by std::thread::hardware_concurrency() if it's greater than 3, the fixed value of 3.

qi::EventLoop::EventLoop | ( | std::string | name,
|  | int | nthreads,
|  | int | minThreads,
|  | int | maxThreads,
|  | bool | spawnOnOverload
| ) |  |

See Also
  EventLoop(std::string, int, bool)

Note
  When the eventloop is starting, the number of threads may be adjusted to ensure that the minimum is below or equal to the maximum, and that the number of threads to start is between the minimum and the maximum included.

qi::EventLoop::~EventLoop | ( |  | ) |
| override

Default destructor.

## Member Function Documentation

template<typename R >

Future< R > qi::EventLoop::async | ( | const boost::function< R()> & | callback,
|  | uint64_t | usDelay
| ) |  |

Calls given function once after given delay in microseconds.

Parameters

  callback | Callback to be called.
  usDelay | Delay before call the callback in microsecond.

Returns
  A canceleable future.

Deprecated:
  use qi::async with qi::Duration

Definition at line 19 of file eventloop.hxx.

Future<void> qi::EventLoop::async | ( | const boost::function< void()> & | callback,
|  | uint64_t | usDelay
| ) |  |
| inline

Definition at line 130 of file eventloop.hpp.

Future<void> qi::EventLoop::async | ( | const boost::function< void()> & | callback,
|  | qi::Duration | delay
| ) |  |
| inline override virtual

call a callback asynchronously to be executed in delay

Deprecated:
  since 2.5

Implements qi::ExecutionContext.

Definition at line 135 of file eventloop.hpp.

Future<void> qi::EventLoop::async | ( | const boost::function< void()> & | callback,
|  | qi::SteadyClockTimePoint | tp
| ) |  |
| inline override virtual

call a callback asynchronously to be executed on tp

Deprecated:
  since 2.5

Implements qi::ExecutionContext.

Definition at line 140 of file eventloop.hpp.

bool qi::EventLoop::isInThisContext | ( |  | ) | const
| override virtual

Checks if the current thread is one of the event loop threads.

Note
  It is safe to call this method concurrently.

Returns
  true if the current thread is one of the event loop threads.

Implements qi::ExecutionContext.

void qi::EventLoop::join | ( |  | ) |

Waits for all threads of the pool to terminate.

Note
  It is NOT safe to call this method concurrently.

Deprecated:
  EventLoop automatically joins when destroyed.

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

Monitors event loop to detect deadlocks.

Parameters

  helper | an other event loop used for monitoring.
  maxUsDelay | maximum 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 | ( |  | ) |

Internal function.

void qi::EventLoop::post | ( | const boost::function< void()> & | callback,
|  | uint64_t | usDelay
| ) |  |
| inline

Similar to async() but without cancelation or notification.

Parameters

  callback | Callback to be called.
  usDelay | Delay before call the callback in microsecond.

Definition at line 155 of file eventloop.hpp.

void qi::EventLoop::post | ( | const boost::function< void()> & | callback,
|  | qi::Duration | delay
| ) |  |
| inline

Definition at line 160 of file eventloop.hpp.

void qi::EventLoop::post | ( | const boost::function< void()> & | callback,
|  | qi::SteadyClockTimePoint | timepoint
| ) |  |

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

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

Parameters

  cb | Callback to be called.

Note
  It is safe to call this method concurrently.

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

Sets the maximum number of threads in the pool.

Parameters

  max | Maximum number of threads.

Note
  It is safe to call this method concurrently.

void qi::EventLoop::setMinThreads | ( | unsigned int | min | ) |

Sets the minimum number of threads in the pool.

Note
  It is safe to call this method concurrently.
  It will be effectively taken into account the next time the "ping task" is run (see environment variable `QI_EVENTLOOP_PING_TIMEOUT`).

void qi::EventLoop::start | ( | int | threadCount = `0` | ) |

Starts the event loop. Does nothing if already started.

Parameters

  threadCount | Number of threads. See the constructor for more information.

Note
  It is NOT safe to call this method concurrently.

Deprecated:
  EventLoop automatically starts when constructed.

void qi::EventLoop::stop | ( |  | ) |

Stops all running threads. Does nothing if already stopped.

Note
  It is NOT safe to call this method concurrently.

Deprecated:
  EventLoop automatically stops when destroyed.

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

- /home/opennao/work/release-2.8/sdk/libqi/qi/eventloop.hpp
- /home/opennao/work/release-2.8/sdk/libqi/qi/detail/eventloop.hxx