~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/core/common/WCondition.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#ifndef WCONDITION_H
 
26
#define WCONDITION_H
 
27
 
 
28
#include <boost/shared_ptr.hpp>
 
29
#include <boost/function.hpp>
 
30
#include <boost/signals2/signal.hpp>
 
31
#include <boost/thread.hpp>
 
32
 
 
33
#include "WExportCommon.h"
 
34
 
 
35
/**
 
36
 * Class to encapsulate boost::condition_variable_any. You may use it to efficiently wait for events (a condition comes true). It
 
37
 * is a very simple implementation. It might be extended easily. Timed wait functions and so on.
 
38
 */
 
39
class OWCOMMON_EXPORT WCondition // NOLINT
 
40
{
 
41
    friend class WCondition_test;
 
42
public:
 
43
    /**
 
44
     * Shared pointer type for WCondition.
 
45
     */
 
46
    typedef boost::shared_ptr< WCondition > SPtr;
 
47
 
 
48
    /**
 
49
     * Const shared pointer type for WCondition.
 
50
     */
 
51
    typedef boost::shared_ptr< const WCondition > ConstSPtr;
 
52
 
 
53
    /**
 
54
     * Default constructor.
 
55
     */
 
56
    WCondition();
 
57
 
 
58
    /**
 
59
     * Destructor.
 
60
     */
 
61
    virtual ~WCondition();
 
62
 
 
63
    /**
 
64
     * Wait for the condition. Sets the calling thread asleep.
 
65
     */
 
66
    virtual void wait() const;
 
67
 
 
68
    /**
 
69
     * Notifies all waiting threads.
 
70
     */
 
71
    virtual void notify();
 
72
 
 
73
    /**
 
74
     * Type used for signalling condition changes.
 
75
     */
 
76
    typedef boost::function0< void > t_ConditionNotifierType;
 
77
 
 
78
    /**
 
79
     * Subscribes a specified function to be notified on condition change.
 
80
     *
 
81
     * \param notifier the notifier function
 
82
     *
 
83
     * \return the connection.
 
84
     */
 
85
    boost::signals2::connection subscribeSignal( t_ConditionNotifierType notifier );
 
86
 
 
87
protected:
 
88
 
 
89
    /**
 
90
     * Type used for condition notification.
 
91
     */
 
92
    typedef boost::signals2::signal<void ( void )>  t_ConditionSignalType;
 
93
 
 
94
    /**
 
95
     * Signal getting fired whenever the condition fires.
 
96
     */
 
97
    t_ConditionSignalType signal_ConditionFired;
 
98
 
 
99
    /**
 
100
     * The condition.
 
101
     */
 
102
    mutable boost::condition_variable_any m_condition;
 
103
 
 
104
    /**
 
105
     * The mutex used for the condition.
 
106
     */
 
107
    mutable boost::shared_mutex m_mutex;
 
108
 
 
109
private:
 
110
};
 
111
 
 
112
#endif  // WCONDITION_H
 
113