3 * Author: Lukas Krejci <krejci.l@centrum.cz>, (C) 2008
4 * Copyright: See COPYING file that comes with this distribution
7 #ifndef BEACON_INVOKABLE_H
8 #define BEACON_INVOKABLE_H
10 #include <beacon/reference_countable.hpp>
11 #include <beacon/detail/quick_wait.hpp>
12 #include <beacon/intrusive_ptr.hpp>
14 #include <boost/thread/recursive_mutex.hpp>
17 #include <atomic_ops.h>
23 * This class represents the token that identifies an invokable in
24 * \a event_queue::dequeue.
26 class invocation_token
: public reference_countable
{
30 /** The type of the lock for the \a guard. */
31 typedef boost::recursive_mutex::scoped_lock lock_t
;
33 invocation_token(bool valid
= true) : _valid(valid
) {
40 * A true return value indicates that the invokable accompanied
41 * by this token is valid.
48 * This causes the \a valid method to return false, indicating that
49 * the invokable accompanied by this token is no longer valid.
50 * The guard is locked during the method invocation.
58 * The guard can be used to lock access to the token.
60 boost::recursive_mutex
const & guard() const {
65 * The guard can be used to lock access to the token.
67 boost::recursive_mutex
& guard() {
72 boost::recursive_mutex _guard
;
76 * An abstract class that anything invokable from within an
77 * {@link event_queue} needs to implement.
82 typedef intrusive_ptr
<invocation_token
> token_ptr
;
83 typedef invocation_token token_type
;
88 * Creates new instance of an invokable object.
89 * @param token a token used to match different invokables
91 invokable(token_ptr token
) : _token(token
) {
96 virtual ~invokable() {
99 virtual void invoke() = 0;
101 token_ptr
token() const {