3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
7 #ifndef BEACON_EVENT_LOOP_H
8 #define BEACON_EVENT_LOOP_H
10 #include <beacon/event_queue.hpp>
12 #include <boost/thread.hpp>
13 #include <boost/bind.hpp>
18 * Event loop is a wrapper of event_queue that implements
19 * a simple event queue. I.e. it starts a thread in which
20 * all the events are invoked.
22 class event_loop
: public event_queue
{
26 * A new thread is started to handle this event loop.
35 * This call does NOT block until the underlying thread finishes.
36 * It just destroys the event_loop object without stopping
37 * the underlying thread. Be sure to call @link join method before
38 * the event_loop is destroyed.
41 if (_thread
) delete _thread
;
45 * Starts the event loop. The events can be enqueued and dequeued before
46 * the event loop is started but they won't be processed until it is.
48 * This method has no effect if there already is a thread running and
55 _thread
= new boost::thread(boost::bind(&event_loop::run
, this));
60 * Joins the event loop thread. If the thread is started using the {@link start} method
61 * while another thread is executing this method, the result is undefined.
63 * This method IS NOT thread-safe.
68 //the thread we're executing the events in
69 boost::thread
* _thread
;
71 //controlling the thread alive-state