2 * Copyright (c) 2005-2007, Kohsuke Ohtani
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 int magic
; /* Magic number */
41 task_t task
; /* Owner task */
42 struct event event
; /* Event */
43 u_int value
; /* Current value */
45 typedef struct semaphore
*sem_t
;
47 #define SEM_MAX ((u_int)((~0u) >> 1))
48 #define SEM_MAGIC 0x53656d3f /* 'Sem?' */
50 #define sem_valid(s) (kern_area(s) && ((s)->magic == SEM_MAGIC))
52 extern int sem_init(sem_t
*sem
, u_int value
);
53 extern int sem_destroy(sem_t
*sem
);
54 extern int sem_wait(sem_t
*sem
, u_long timeout
);
55 extern int sem_trywait(sem_t
*sem
);
56 extern int sem_post(sem_t
*sem
);
57 extern int sem_getvalue(sem_t
*sem
, u_int
*value
);
64 int magic
; /* Magic number */
65 task_t task
; /* Owner task */
66 struct event event
; /* Event */
67 struct list link
; /* Link to locked mutex list */
68 thread_t owner
; /* Owner thread locking this mutex */
69 int prio
; /* Highest prio in waiting threads */
70 int lock_count
; /* Counter for recursive lock */
72 typedef struct mutex
*mutex_t
;
74 #define MUTEX_MAGIC 0x4d75783f /* 'Mux?' */
75 #define MUTEX_INITIALIZER (mutex_t)0x4d496e69 /* 'MIni' */
77 #define mutex_valid(m) (kern_area(m) && \
78 ((m)->magic == MUTEX_MAGIC) && \
79 ((m)->task == cur_task()))
81 extern int mutex_init(mutex_t
*mtx
);
82 extern int mutex_destroy(mutex_t
*mtx
);
83 extern int mutex_lock(mutex_t
*mtx
);
84 extern int mutex_trylock(mutex_t
*mtx
);
85 extern int mutex_unlock(mutex_t
*mtx
);
86 extern void mutex_cleanup(thread_t th
);
87 extern void mutex_setprio(thread_t th
, int prio
);
94 int magic
; /* Magic number */
95 task_t task
; /* Owner task */
96 struct event event
; /* Event */
98 typedef struct cond
*cond_t
;
100 #define COND_MAGIC 0x436f6e3f /* 'Con?' */
101 #define COND_INITIALIZER (cond_t)0x43496e69 /* 'CIni' */
103 #define cond_valid(c) (kern_area(c) && \
104 ((c)->magic == COND_MAGIC) && \
105 ((c)->task == cur_task()))
107 extern int cond_init(cond_t
*cond
);
108 extern int cond_destroy(cond_t
*cond
);
109 extern int cond_wait(cond_t
*cond
, mutex_t
*mtx
, u_long timeout
);
110 extern int cond_signal(cond_t
*cond
);
111 extern int cond_broadcast(cond_t
*cond
);
113 #endif /* !_SYNC_H */