2 libfmail: Semaphore class
4 Copyright (C) 2007 Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <semaphore.h>
26 #include <libfmail/semaphore.h>
32 /* TODO: Add support for shared semaphores */
33 Semaphore::Semaphore(int value
, int shared
, int key
){
36 os_sem
= (OSSem
*)malloc(sizeof(OSSem
));
37 sem_init(&(os_sem
->sem
), 0, value
);
39 Semaphore::~Semaphore(){
40 sem_destroy(&(os_sem
->sem
));
44 int Semaphore::TryWait(){
45 return sem_trywait(&(os_sem
->sem
));
48 int Semaphore::Wait(){
49 return sem_wait(&(os_sem
->sem
));
52 int Semaphore::Post(){
53 return sem_post(&(os_sem
->sem
));
56 int Semaphore::getValue(){
58 sem_getvalue(&(os_sem
->sem
), &ret
);