summaryrefslogtreecommitdiff
path: root/os_wrappers/Event.h
blob: 9bd46f6f79b3e72fb028ef1f69c5f4cf5c7352ff (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
66
/*
 * Event.h
 *
 * Copyright (C) ST-Ericsson SA 2011
 * Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
 *          Ola Borgelin <ola.borgelin@stericsson.com>,
 *          Karin Hedlund <karin.hedlund@stericsson.com>,
 *          Markus Andersson <markus.m.andersson@stericsson.com> for ST-Ericsson.
 * License terms: 3-clause BSD license
 *
 */

/*
 * @addtogroup OS Wrappers
 * @{
 */

#pragma once

#ifdef _WIN32
#include <windows.h>
#else
#include <semaphore.h>
#endif

/**
 * @brief Simple wrapper for OS synchronization primitive.
 *
 * This class wraps Win32 and POSIX semaphore.
 */
class Event
{
public:
    /**
     * @brief Constructor creating new event.
     */
    Event();

    /**
     * @brief Destructor that destroys the event.
     */
    virtual ~Event();

    /**
     * @brief Wait on the event for specified time.
     *
     * By default it waits for infinite time and blocks the thread until
     * the event is signaled.
     */
    void wait(unsigned long timeout = -1);

    /**
     * @brief Signal the event.
     *
     * When event is signaled the waiting thread is released.
     */
    void signal();
private:
#ifdef _WIN32
    HANDLE semaphore_;
#else
    sem_t semaphore_;
#endif
};

/* @} */