source: trunk/libs/libsemaphore/semaphore.c @ 527

Last change on this file since 527 was 469, checked in by alain, 6 years ago

1) Introduce the libsemaphore library.
2) Introduce a small libmath library, required by the "fft" application..
3) Introduce the multithreaded "fft" application.
4) Fix a bad synchronisation bug in the Copy-On-Write mechanism.

File size: 2.5 KB
RevLine 
[469]1/*
2 * pthread.c - User leve <semaphore> library implementation.
3 *
4 * Author     Alain Greiner (2016,2017,2018)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_user.h>
25#include <hal_shared_types.h>
26#include <semaphore.h>
27#include <shared_semaphore.h>
28#include <syscalls_numbers.h>
29#include <stdio.h>
30
31/////////////////////////////////
32int sem_init( sem_t        * sem,
33              int            pshared,
34              unsigned int   init_value )
35{
36    if( pshared )
37    {
38        printf("[ERROR] in %s : pshared argument must be zero\n", __FUNCTION__ );
39        return -1;
40    }
41
42    return hal_user_syscall( SYS_SEM,
43                             (reg_t)sem,
44                             SEM_INIT,
45                             (reg_t)init_value,
46                             0 ) ;
47}
48
49///////////////////////////
50int sem_wait( sem_t * sem )
51{
52    return hal_user_syscall( SYS_SEM,
53                             (reg_t)sem, 
54                             SEM_WAIT, 0, 0 );
55}
56
57///////////////////////////
58int sem_post( sem_t * sem )
59{
60    return hal_user_syscall( SYS_SEM,
61                             (reg_t)sem, 
62                             SEM_POST, 0, 0 );
63}
64
65//////////////////////////////
66int sem_destroy( sem_t * sem )
67{
68    return hal_user_syscall( SYS_SEM,
69                             (reg_t)sem, 
70                             SEM_DESTROY, 0, 0 );
71}
72
73//////////////////////////////
74int sem_getvalue( sem_t * sem,
75                  int   * current_value )
76{
77    return hal_user_syscall( SYS_SEM,
78                             (reg_t)sem,
79                             SEM_GETVALUE,
80                             0, 
81                             (reg_t)current_value );
82}
83
84
85// Local Variables:
86// tab-width: 4
87// c-basic-offset: 4
88// c-file-offsets:((innamespace . 0)(inline-open . 0))
89// indent-tabs-mode: nil
90// End:
91// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
92
Note: See TracBrowser for help on using the repository browser.