Rev 3 | Rev 1031 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
21 | /*************************************** |
||
22 | |||
23 | Semaphores for the kernel |
||
24 | |||
25 | ***************************************/ |
||
26 | |||
27 | /* |
||
80 | pj | 28 | * CVS : $Id: semaph.h,v 1.2 2003-03-13 13:37:58 pj Exp $ |
2 | pj | 29 | * |
30 | * File: $File$ |
||
80 | pj | 31 | * Revision: $Revision: 1.2 $ |
32 | * Last update: $Date: 2003-03-13 13:37:58 $ |
||
2 | pj | 33 | */ |
34 | |||
35 | /* |
||
36 | * Copyright (C) 1999 Massimiliano Giorgi |
||
37 | * |
||
38 | * This program is free software; you can redistribute it and/or modify |
||
39 | * it under the terms of the GNU General Public License as published by |
||
40 | * the Free Software Foundation; either version 2 of the License, or |
||
41 | * (at your option) any later version. |
||
42 | * |
||
43 | * This program is distributed in the hope that it will be useful, |
||
44 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
45 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
46 | * GNU General Public License for more details. |
||
47 | * |
||
48 | * You should have received a copy of the GNU General Public License |
||
49 | * along with this program; if not, write to the Free Software |
||
50 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
51 | * |
||
52 | */ |
||
53 | |||
54 | #ifndef _FS_SEMAPH_H |
||
55 | #define _FS_SEMAPH_H |
||
56 | |||
57 | #include <kernel/int_sem.h> |
||
80 | pj | 58 | #include "ll/sys/cdefs.h" |
2 | pj | 59 | |
80 | pj | 60 | __BEGIN_DECLS |
61 | |||
2 | pj | 62 | /*+ a semaphore object +*/ |
63 | typedef internal_sem_t __sem_t; |
||
64 | |||
65 | /* |
||
66 | The following macros can be used to synchronize events; all |
||
67 | require a pointer to a semaphore object and return nothing; |
||
68 | a semaphore can have "val" resource free. |
||
69 | */ |
||
70 | |||
71 | /*+ Initialize a semaphore (to integer val) +*/ |
||
72 | #define __sem_init(ptr,val) internal_sem_init((ptr),(val)) |
||
73 | |||
74 | /*+ Wait for a semaphore +*/ |
||
75 | #define __sem_wait(ptr) (internal_sem_wait(ptr)) |
||
76 | |||
77 | /*+ Try to wait for a semaphore (return 0 on success) +*/ |
||
78 | #define __sem_trywait(ptr) (internal_sem_trywait(ptr)) |
||
79 | |||
80 | /*+ Signal a semaphore +*/ |
||
81 | #define __sem_signal(ptr) (internal_sem_post(ptr)) |
||
82 | |||
83 | |||
84 | |||
85 | |||
86 | #if 0 |
||
87 | |||
88 | /* |
||
89 | #include <hartik/const.h> |
||
90 | |||
91 | typedef struct { |
||
92 | QUEUE queue; |
||
93 | int value; |
||
94 | } __semaph_t; |
||
95 | |||
96 | void __semaph_init(__semaph_t *, int val); |
||
97 | void __semaph_lock(__semaph_t *); |
||
98 | int __semaph_trylock(__semaph_t *); |
||
99 | void __semaph_unlock(__semaph_t *); |
||
100 | */ |
||
101 | |||
102 | /* |
||
103 | * temporary hack |
||
104 | */ |
||
105 | |||
106 | #include <h/sys/kern.h> |
||
107 | #include <h/sys/const.h> |
||
108 | |||
109 | #ifdef FSCHECKSEMAPH |
||
110 | #include <fs/assert.h> |
||
111 | #define checksemaph(x) _assert((x)>=0&&(x)<MAX_SEM) |
||
112 | #else |
||
113 | #define checksemaph(x) |
||
114 | #endif |
||
115 | |||
116 | /*+ a semaphore object +*/ |
||
117 | typedef SEM __sem_t; |
||
118 | |||
119 | /* |
||
120 | The following macros can be used to synchronize events; all |
||
121 | require a pointer to a semaphore object and return nothing; |
||
122 | a semaphore can have "val" resource free. |
||
123 | */ |
||
124 | |||
125 | /*+ Initialize a semaphore (to integer val) +*/ |
||
126 | #define __sem_init(ptr,val) {*(ptr)=sem_create(val); checksemaph(*ptr);} |
||
127 | |||
128 | /*+ Wait for a semaphore +*/ |
||
129 | #define __sem_wait(ptr) {checksemaph(*ptr); sem_wait(*(ptr),BLOCK);} |
||
130 | |||
131 | /*+ Try to wait for a semaphore (return 0 on success) +*/ |
||
132 | #define __sem_trywait(ptr) (!sem_wait(*(ptr),NON_BLOCK)) |
||
133 | |||
134 | /*+ Signal a semaphore +*/ |
||
135 | #define __sem_signal(ptr) {checksemaph(*ptr); sem_signal(*(ptr));} |
||
136 | |||
137 | #endif |
||
138 | |||
139 | |||
80 | pj | 140 | __END_DECLS |
2 | pj | 141 | #endif |
142 | |||
143 | |||
144 | |||
145 |