summaryrefslogtreecommitdiff
path: root/os_wrappers/Event.cpp
blob: 0390735d529ef7d26141ef81533d50e9514b6571 (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
/*
 * Event.cpp
 *
 * 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
 * @{
 */

#include "Event.h"

Event::Event()
{
#ifdef _WIN32
    semaphore_ = CreateSemaphore(NULL, 0, 256, NULL);
#else
    sem_init(&semaphore_, 0, 0);
#endif
}

Event::~Event()
{
#ifdef _WIN32
    CloseHandle(semaphore_);
#else
    sem_destroy(&semaphore_);
#endif
}

void Event::signal()
{
#ifdef _WIN32
    ReleaseSemaphore(semaphore_, 1, NULL);
#else
    sem_post(&semaphore_);
#endif
}

void Event::wait(unsigned long timeout __attribute__((unused)))
{
#ifdef _WIN32
    WaitForSingleObject(semaphore_, timeout);
#else
    sem_wait(&semaphore_);
#endif
}

/* @} */