Subversion Repositories shark

Rev

Details | 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
Mutexs for the user.
24
 
25
***************************************/
26
 
27
/*
28
 * CVS :        $Id: mutex.h,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $
29
 *
30
 * File:        $File$
31
 * Revision:    $Revision: 1.1.1.1 $
32
 * Last update: $Date: 2002-03-29 14:12:51 $
33
 */
34
 
35
/*
36
 * Copyright (C) 1999,2000 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 _MUTEX_H
55
#define _MUTEX_H
56
 
57
/*
58
#include <hartik/const.h>
59
 
60
typedef struct {
61
  QUEUE queue;
62
  int   value;
63
} mutex_t;
64
 
65
void mutex_init(mutex_t *);
66
void mutex_lock(mutex_t *);
67
int  mutex_trylock(mutex_t *);
68
void mutex_unlock(mutex_t *);
69
*/
70
 
71
/*
72
 * temporary hack
73
 */
74
 
75
#include <h/sys/kern.h>
76
#include <h/sys/const.h>
77
 
78
/*+ a mutex object +*/
79
typedef SEM mutex_t;
80
 
81
/*
82
  The following macros require a pointer to a mutex object and
83
  return nothing.
84
*/
85
 
86
/* Initialize a mutex object +*/
87
#define mutex_init(ptr)    { *(ptr)=sem_create(1); }
88
 
89
/*+ Lock a mutex object +*/
90
#define mutex_lock(ptr)    { sem_wait(*(ptr),BLOCK); }
91
 
92
/*+ Try to lock a mutex (return 0 on success locking) +*/
93
#define mutex_trylock(ptr) { sem_wait(*(ptr),NON_BLOCK); }
94
 
95
/*+ Unlock a mutex +*/
96
#define mutex_unlock(ptr)  { sem_signal(*(ptr)); }
97
 
98
#endif
99