Update Code Style Guidelines
[fmail.git] / src / posix-sem.cpp
blobb261919c1efb377f7a2f51846d155675ddc0c1a4
1 /*
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.
21 #include <stdio.h>
22 #include <string.h>
23 #include <malloc.h>
25 #include <semaphore.h>
26 #include <libfmail/semaphore.h>
28 struct _ossem{
29 sem_t sem;
32 Semaphore::Semaphore(int value, int shared, int key){
33 (void)shared;
34 (void)key;
35 os_sem = (OSSem*)malloc(sizeof(OSSem));
36 sem_init(&(os_sem->sem), 0, value);
38 Semaphore::~Semaphore(){
39 sem_destroy(&(os_sem->sem));
40 free(os_sem);
43 int Semaphore::TryWait(){
44 return sem_trywait(&(os_sem->sem));
47 int Semaphore::Wait(){
48 return sem_wait(&(os_sem->sem));
51 int Semaphore::Post(){
52 return sem_post(&(os_sem->sem));
55 int Semaphore::getValue(){
56 int ret;
57 sem_getvalue(&(os_sem->sem), &ret);
59 return ret;