source: trunk/sys/libpthread/semaphore.c @ 1

Last change on this file since 1 was 1, checked in by alain, 5 years ago

First import

File size: 2.2 KB
Line 
1/*
2 * semaphore.c - semaphore related system calls
3 *
4 * Author  Ghassan Almaless  (2008,2009,2010,2011,2012)
5 *         Alain Greiner     (2016)
6 *
7 * Copyright (c)  UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH.is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH.is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <errno.h>
26#include <sys/types.h>
27#include <semaphore.h>
28#include <sys/syscall.h>
29#include <cpu-syscall.h>
30
31typedef enum
32{
33        SEM_INIT,
34        SEM_GETVALUE,
35        SEM_WAIT,
36        SEM_POST,
37        SEM_DESTROY
38} 
39sem_operation_t;
40
41///////////////////////////////////////////////////////////////////////////////////////////////
42static int __sys_sem( sem_t *sem, int operation, int pshared, int *value)
43{
44        register int retval;
45 
46        retval = (int)cpu_syscall( (void*)sem,
47                               (void*)operation,
48                               (void*)pshared,
49                               (void*)value,
50                               SYS_SEMAPHORE );
51        return retval;
52}
53
54///////////////////////////////
55int sem_init( sem_t      * sem, 
56              int          pshared, 
57              unsigned int value)
58{
59        int v          = (int)value;
60        int *value_ptr = &v;
61
62        return __sys_sem(sem, SEM_INIT, pshared, value_ptr);
63}
64
65//////////////////////////////
66int sem_getvalue( sem_t * sem,
67                  int   * value )
68{
69        return __sys_sem(sem, SEM_GETVALUE, 0, value);
70}
71
72///////////////////////////
73int sem_wait( sem_t * sem )
74{
75        return __sys_sem(sem, SEM_WAIT, 0, NULL);
76}
77
78///////////////////////////
79int sem_post( sem_t * sem )
80{
81        return __sys_sem(sem, SEM_POST, 0, NULL);
82}
83
84//////////////////////////////
85int sem_destroy( sem_t * sem )
86{
87        return __sys_sem(sem, SEM_DESTROY, 0, NULL);
88}
Note: See TracBrowser for help on using the repository browser.