ReactOS  0.4.13-dev-479-gec9c8fd
sys.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 #ifndef __LWIP_SYS_H__
33 #define __LWIP_SYS_H__
34 
35 #include "lwip/opt.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #if NO_SYS
42 
43 /* For a totally minimal and standalone system, we provide null
44  definitions of the sys_ functions. */
45 typedef u8_t sys_sem_t;
46 typedef u8_t sys_mutex_t;
47 typedef u8_t sys_mbox_t;
48 
49 #define sys_sem_new(s, c) ERR_OK
50 #define sys_sem_signal(s)
51 #define sys_sem_wait(s)
52 #define sys_arch_sem_wait(s,t)
53 #define sys_sem_free(s)
54 #define sys_sem_valid(s) 0
55 #define sys_sem_set_invalid(s)
56 #define sys_mutex_new(mu) ERR_OK
57 #define sys_mutex_lock(mu)
58 #define sys_mutex_unlock(mu)
59 #define sys_mutex_free(mu)
60 #define sys_mutex_valid(mu) 0
61 #define sys_mutex_set_invalid(mu)
62 #define sys_mbox_new(m, s) ERR_OK
63 #define sys_mbox_fetch(m,d)
64 #define sys_mbox_tryfetch(m,d)
65 #define sys_mbox_post(m,d)
66 #define sys_mbox_trypost(m,d)
67 #define sys_mbox_free(m)
68 #define sys_mbox_valid(m)
69 #define sys_mbox_set_invalid(m)
70 
71 #define sys_thread_new(n,t,a,s,p)
72 
73 #define sys_msleep(t)
74 
75 #else /* NO_SYS */
76 
78 #define SYS_ARCH_TIMEOUT 0xffffffffUL
79 
83 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
84 
85 #include "lwip/err.h"
86 #include "arch/sys_arch.h"
87 
89 typedef void (*lwip_thread_fn)(void *arg);
90 
91 /* Function prototypes for functions to be implemented by platform ports
92  (in sys_arch.c) */
93 
94 /* Mutex functions: */
95 
98 #if LWIP_COMPAT_MUTEX
99 /* for old ports that don't have mutexes: define them to binary semaphores */
100 #define sys_mutex_t sys_sem_t
101 #define sys_mutex_new(mutex) sys_sem_new(mutex, 1)
102 #define sys_mutex_lock(mutex) sys_sem_wait(mutex)
103 #define sys_mutex_unlock(mutex) sys_sem_signal(mutex)
104 #define sys_mutex_free(mutex) sys_sem_free(mutex)
105 #define sys_mutex_valid(mutex) sys_sem_valid(mutex)
106 #define sys_mutex_set_invalid(mutex) sys_sem_set_invalid(mutex)
107 
108 #else /* LWIP_COMPAT_MUTEX */
109 
113 err_t sys_mutex_new(sys_mutex_t *mutex);
116 void sys_mutex_lock(sys_mutex_t *mutex);
119 void sys_mutex_unlock(sys_mutex_t *mutex);
122 void sys_mutex_free(sys_mutex_t *mutex);
123 #ifndef sys_mutex_valid
124 
125 int sys_mutex_valid(sys_mutex_t *mutex);
126 #endif
127 #ifndef sys_mutex_set_invalid
128 
129 void sys_mutex_set_invalid(sys_mutex_t *mutex);
130 #endif
131 #endif /* LWIP_COMPAT_MUTEX */
132 
133 /* Semaphore functions: */
134 
151 void sys_sem_free(sys_sem_t *sem);
153 #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0)
154 #ifndef sys_sem_valid
155 
157 #endif
158 #ifndef sys_sem_set_invalid
159 
161 #endif
162 
163 /* Time functions. */
164 #ifndef sys_msleep
165 void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
166 #endif
167 
168 /* Mailbox functions. */
169 
179 void sys_mbox_post(sys_mbox_t *mbox, void *msg);
192 /* Allow port to override with a macro, e.g. special timout for sys_arch_mbox_fetch() */
193 #ifndef sys_arch_mbox_tryfetch
194 
201 #endif
202 
203 #define sys_mbox_tryfetch(mbox, msg) sys_arch_mbox_tryfetch(mbox, msg)
204 
207 #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0)
208 #ifndef sys_mbox_valid
209 
211 #endif
212 #ifndef sys_mbox_set_invalid
213 
215 #endif
216 
224 sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio);
225 
226 #endif /* NO_SYS */
227 
228 /* sys_init() must be called before anthing else. */
229 void sys_init(void);
230 
231 #ifndef sys_jiffies
232 
233 u32_t sys_jiffies(void);
234 #endif
235 
238 u32_t sys_now(void);
239 
240 /* Critical Region Protection */
241 /* These functions must be implemented in the sys_arch.c file.
242  In some implementations they can provide a more light-weight protection
243  mechanism than using semaphores. Otherwise semaphores can be used for
244  implementation */
245 #ifndef SYS_ARCH_PROTECT
246 
251 #if SYS_LIGHTWEIGHT_PROT
252 
258 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
259 
268 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
269 
277 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
279 void sys_arch_unprotect(sys_prot_t pval);
280 
281 #else
282 
283 #define SYS_ARCH_DECL_PROTECT(lev)
284 #define SYS_ARCH_PROTECT(lev)
285 #define SYS_ARCH_UNPROTECT(lev)
286 
287 #endif /* SYS_LIGHTWEIGHT_PROT */
288 
289 #endif /* SYS_ARCH_PROTECT */
290 
291 /*
292  * Macros to set/get and increase/decrease variables in a thread-safe way.
293  * Use these for accessing variable that are used from more than one thread.
294  */
295 
296 #ifndef SYS_ARCH_INC
297 #define SYS_ARCH_INC(var, val) do { \
298  SYS_ARCH_DECL_PROTECT(old_level); \
299  SYS_ARCH_PROTECT(old_level); \
300  var += val; \
301  SYS_ARCH_UNPROTECT(old_level); \
302  } while(0)
303 #endif /* SYS_ARCH_INC */
304 
305 #ifndef SYS_ARCH_DEC
306 #define SYS_ARCH_DEC(var, val) do { \
307  SYS_ARCH_DECL_PROTECT(old_level); \
308  SYS_ARCH_PROTECT(old_level); \
309  var -= val; \
310  SYS_ARCH_UNPROTECT(old_level); \
311  } while(0)
312 #endif /* SYS_ARCH_DEC */
313 
314 #ifndef SYS_ARCH_GET
315 #define SYS_ARCH_GET(var, ret) do { \
316  SYS_ARCH_DECL_PROTECT(old_level); \
317  SYS_ARCH_PROTECT(old_level); \
318  ret = var; \
319  SYS_ARCH_UNPROTECT(old_level); \
320  } while(0)
321 #endif /* SYS_ARCH_GET */
322 
323 #ifndef SYS_ARCH_SET
324 #define SYS_ARCH_SET(var, val) do { \
325  SYS_ARCH_DECL_PROTECT(old_level); \
326  SYS_ARCH_PROTECT(old_level); \
327  var = val; \
328  SYS_ARCH_UNPROTECT(old_level); \
329  } while(0)
330 #endif /* SYS_ARCH_SET */
331 
332 
333 #ifdef __cplusplus
334 }
335 #endif
336 
337 #endif /* __LWIP_SYS_H__ */
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
Definition: sys_arch.c:280
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
u32_t sys_thread_t
Definition: sys_arch.h:20
err_t sys_mutex_new(sys_mutex_t *mutex)
u32_t sys_now(void)
Definition: sys_arch.c:28
GLuint GLuint GLsizei count
Definition: gl.h:1545
void sys_arch_unprotect(sys_prot_t lev)
Definition: sys_arch.c:45
int sys_mbox_valid(sys_mbox_t *mbox)
Definition: sys_arch.c:146
void sys_mutex_unlock(sys_mutex_t *mutex)
void sys_mutex_lock(sys_mutex_t *mutex)
void * arg
Definition: msvc.h:12
Definition: dhcpd.h:245
void sys_sem_set_invalid(sys_sem_t *sem)
Definition: sys_arch.c:71
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
Definition: sys_arch.c:182
KIRQL sys_prot_t
Definition: sys_arch.h:18
void sys_mutex_set_invalid(sys_mutex_t *mutex)
void sys_sem_free(sys_sem_t *sem)
Definition: sys_arch.c:77
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
Definition: sys_arch.c:51
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
Definition: sys_arch.c:243
int sys_sem_valid(sys_sem_t *sem)
Definition: sys_arch.c:66
struct _sys_sem_t sys_sem_t
s8_t err_t
Definition: err.h:47
struct _sys_mbox_t sys_mbox_t
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
Definition: sys_arch.c:133
void(* lwip_thread_fn)(void *arg)
Definition: sys.h:89
void sys_arch_protect(sys_prot_t *lev)
Definition: sys_arch.c:38
GLsizeiptr size
Definition: glext.h:5919
int sys_mutex_valid(sys_mutex_t *mutex)
unsigned long u32_t
Definition: cc.h:25
void sys_mutex_free(sys_mutex_t *mutex)
static HANDLE thread
Definition: service.c:33
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
Definition: sys_arch.c:91
static HANDLE sem
Definition: sync.c:677
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:252
u32_t sys_jiffies(void)
unsigned char u8_t
Definition: cc.h:23
void sys_msleep(u32_t ms)
Definition: sys.c:55
#define msg(x)
Definition: auth_time.c:54
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:165
Definition: name.c:36
void sys_sem_signal(sys_sem_t *sem)
Definition: sys_arch.c:85
void sys_mbox_set_invalid(sys_mbox_t *mbox)
Definition: sys_arch.c:151
Definition: module.h:446
void sys_init(void)
Definition: sys_arch.c:310
static sys_mbox_t mbox
Definition: tcpip.c:56
void sys_mbox_free(sys_mbox_t *mbox)
Definition: sys_arch.c:157