1 /***************************************************************************
3 * Copyright (C) <year> <author> *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
15 ***************************************************************************/
20 #include "semaphore.h"
28 /* {{{ Semaphore::Semaphore(unsigned int) */
29 Semaphore::Semaphore(unsigned int value
)
31 sem_init(&s
, 0, value
);
35 /* {{{ Semaphore::~Semaphore */
36 Semaphore::~Semaphore()
42 /* {{{ Semaphore::timedWait(time_t, long, bool) */
43 bool Semaphore::timedWait(time_t seconds
, long nanoseconds
, bool absolute
)
48 t
.tv_nsec
= nanoseconds
;
50 struct timespec current
;
51 clock_gettime(CLOCK_REALTIME
, ¤t
);
52 t
.tv_sec
= current
.tv_sec
+ seconds
+ (current
.tv_nsec
+ nanoseconds
) / 1000000000;
53 t
.tv_nsec
= (current
.tv_nsec
+ nanoseconds
) % 1000000000;
56 if (sem_timedwait(&s
, &t
) != 0)
64 }; // namespace Tairon
66 // vim: ai sw=4 ts=4 noet fdm=marker