aboutsummaryrefslogtreecommitdiff
path: root/src/stable/event.h
blob: d6c9f5e7c2f6a215ceb8940030cd31256bcee784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#ifndef BU_EVENT_H
#define BU_EVENT_H

#include <pthread.h>

#include "bu/mutex.h"
#include "bu/condition.h"

namespace Bu
{
    /**
     *@ingroup Threading
     */
    class Event
    {
    public:
        Event()
        {
        }
        
        ~Event()
        {
        }

        void wait()
        {
            cBlock.lock();
            cBlock.wait();
            cBlock.unlock();
        }

        void wait( int nSec, int nUSec )
        {
            cBlock.lock();
            cBlock.wait( nSec, nUSec );
            cBlock.unlock();
        }

        void unblockOne()
        {
            cBlock.lock();
            cBlock.signal();
            cBlock.unlock();
        }

        void unblockAll()
        {
            cBlock.lock();
            cBlock.broadcast();
            cBlock.unlock();
        }

    private:
        Condition cBlock;   /**< The condition for blocking dequeues. */
    };
}

#endif