SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

001 /* Copyright (C) 2004 David Decotigny
002 
003    This program is free software; you can redistribute it and/or
004    modify it under the terms of the GNU General Public License
005    as published by the Free Software Foundation; either version 2
006    of the License, or (at your option) any later version.
007    
008    This program is distributed in the hope that it will be useful,
009    but WITHOUT ANY WARRANTY; without even the implied warranty of
010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011    GNU General Public License for more details.
012    
013    You should have received a copy of the GNU General Public License
014    along with this program; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
016    USA. 
017 */
018 #ifndef _SOS_KSYNCH_H_
019 #define _SOS_KSYNCH_H_
020 
021 
022 /**
023  * @file synch.h
024  *
025  * Common kernel synchronisation primitives.
026  */
027 
028 
029 #include <sos/errno.h>
030 #include <sos/kwaitq.h>
031 
032 
033 /* ====================================================================
034  * Kernel semaphores, NON-recursive
035  */
036 
037 
038 /**
039  * The structure of a (NON-RECURSIVE) kernel Semaphore
040  */
041 struct sos_ksema
042 {
043   int value;
044   struct sos_kwaitq kwaitq;
045 };
046 
047 
048 /*
049  * Initialize a kernel semaphore structure with the given name
050  *
051  * @param name Name of the semaphore (for debugging purpose only; safe
052  * [deep copied])
053  *
054  * @param initial_value The value of the semaphore before any up/down
055  */
056 sos_ret_t sos_ksema_init(struct sos_ksema *sema, const char *name,
057                          int initial_value,
058                          sos_kwaitq_ordering_t ordering);
059 
060 
061 /*
062  * De-initialize a kernel semaphore
063  *
064  * @return -SOS_EBUSY when semaphore could not be de-initialized
065  * because at least a thread is in the waitq.
066  */
067 sos_ret_t sos_ksema_dispose(struct sos_ksema *sema);
068 
069 
070 /*
071  * Enters the semaphore
072  *
073  * @param timeout Maximum time to wait for the semaphore. Or NULL for
074  * "no limit". Updated on return to reflect the time remaining (0 when
075  * timeout has been triggered)
076  *
077  * @return -SOS_EINTR when timeout was triggered or when another waitq
078  * woke us up.
079  *
080  * @note This is a BLOCKING FUNCTION
081  */
082 sos_ret_t sos_ksema_down(struct sos_ksema *sema,
083                          struct sos_time *timeout);
084 
085 
086 /*
087  * Try to enter the semaphore without blocking.
088  *
089  * @return -SOS_EBUSY when locking the semaphore would block
090  */
091 sos_ret_t sos_ksema_trydown(struct sos_ksema *sema);
092 
093 
094 /**
095  * Increments the semaphore's value, eventually waking up a thread
096  */
097 sos_ret_t sos_ksema_up(struct sos_ksema *sema);
098 
099 
100 
101 /* ====================================================================
102  * Kernel mutex (ie binary semaphore with strong ownership),
103  * NON-recursive !
104  */
105 
106 
107 /**
108  * The structure of a (NON-RECURSIVE) kernel Mutex
109  */
110 struct sos_kmutex
111 {
112   struct sos_thread  *owner;
113   struct sos_kwaitq  kwaitq;
114 };
115 
116 
117 /*
118  * Initialize a kernel mutex structure with the given name
119  *
120  * @param name Name of the mutex (for debugging purpose only; safe
121  * [deep copied])
122  *
123  * @param initial_value The value of the mutex before any up/down
124  */
125 sos_ret_t sos_kmutex_init(struct sos_kmutex *mutex, const char *name,
126                           sos_kwaitq_ordering_t ordering);
127 
128 
129 /*
130  * De-initialize a kernel mutex
131  *
132  * @return -SOS_EBUSY when mutex could not be de-initialized
133  * because at least a thread is in the waitq.
134  */
135 sos_ret_t sos_kmutex_dispose(struct sos_kmutex *mutex);
136 
137 
138 /*
139  * Lock the mutex. If the same thread multiply locks the same mutex,
140  * it won't hurt (no deadlock, return value = -SOS_EBUSY).
141  *
142  * @param timeout Maximum time to wait for the mutex. Or NULL for "no
143  * limit". Updated on return to reflect the time remaining (0 when
144  * timeout has been triggered)
145  *
146  * @return -SOS_EINTR when timeout was triggered or when another waitq
147  * woke us up, -SOS_EBUSY when the thread already owns the mutex.
148  *
149  * @note This is a BLOCKING FUNCTION
150  */
151 sos_ret_t sos_kmutex_lock(struct sos_kmutex *mutex,
152                           struct sos_time *timeout);
153 
154 
155 /*
156  * Try to lock the mutex without blocking.
157  *
158  * @return -SOS_EBUSY when locking the mutex would block
159  */
160 sos_ret_t sos_kmutex_trylock(struct sos_kmutex *mutex);
161 
162 
163 /**
164  * Unlock the mutex, eventually waking up a thread
165  *
166  * @return -SOS_EPERM when the calling thread is NOT the owner of the
167  * mutex
168  */
169 sos_ret_t sos_kmutex_unlock(struct sos_kmutex *mutex);
170 
171 
172 #endif /* _SOS_KSYNCH_H_ */

source navigation ] diff markup ] identifier search ] general search ]