RetroArch
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 <[email protected]>
30  *
31  */
32 #ifndef __LWIP_SYS_H__
33 #define __LWIP_SYS_H__
34 
35 #include "arch/cc.h"
36 
37 #include "lwip/opt.h"
38 
39 
40 #if NO_SYS
41 
42 /* For a totally minimal and standalone system, we provide null
43  definitions of the sys_ functions. */
44 #include "arch/sys_arch.h"
45 
46 struct sys_timeout {u8_t dummy;};
47 
48 #define sys_init()
49 #define sys_timeout(m,h,a)
50 #define sys_untimeout(m,a)
51 #define sys_sem_new(c) c
52 #define sys_sem_signal(s)
53 #define sys_sem_wait(s)
54 #define sys_sem_free(s)
55 #define sys_mbox_new() 0
56 #define sys_mbox_fetch(m,d)
57 #define sys_mbox_post(m,d)
58 #define sys_mbox_free(m)
59 
60 #define sys_thread_new(t,a,p)
61 
62 #else /* NO_SYS */
63 
64 #include "arch/sys_arch.h"
65 
67 #define SYS_ARCH_TIMEOUT 0xffffffff
68 
69 typedef void (* sys_timeout_handler)(void *arg);
70 
71 struct sys_timeout {
72  struct sys_timeout *next;
75  void *arg;
76 };
77 
78 struct sys_timeouts {
79  struct sys_timeout *next;
80 };
81 
82 /* sys_init() must be called before anthing else. */
83 void sys_init(void);
84 
85 /*
86  * sys_timeout():
87  *
88  * Schedule a timeout a specified amount of milliseconds in the
89  * future. When the timeout occurs, the specified timeout handler will
90  * be called. The handler will be passed the "arg" argument when
91  * called.
92  *
93  */
94 void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
96 struct sys_timeouts *sys_arch_timeouts(void);
97 
98 /* Semaphore functions. */
100 void sys_sem_signal(sys_sem_t sem);
102 void sys_sem_free(sys_sem_t sem);
103 void sys_sem_wait(sys_sem_t sem);
105 
106 /* Time functions. */
107 #ifndef sys_msleep
108 void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
109 #endif
110 #ifndef sys_jiffies
111 u32_t sys_jiffies(void); /* since power up. */
112 #endif
113 
114 /* Mailbox functions. */
116 void sys_mbox_post(sys_mbox_t mbox, void *msg);
118 void sys_mbox_free(sys_mbox_t mbox);
119 void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
120 
121 
122 /* Thread functions. */
123 sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio);
124 
125 /* The following functions are used only in Unix code, and
126  can be omitted when porting the stack. */
127 /* Returns the current time in microseconds. */
128 unsigned long sys_now(void);
129 
130 #endif /* NO_SYS */
131 
132 /* Critical Region Protection */
133 /* These functions must be implemented in the sys_arch.c file.
134  In some implementations they can provide a more light-weight protection
135  mechanism than using semaphores. Otherwise semaphores can be used for
136  implementation */
137 #ifndef SYS_ARCH_PROTECT
138 
143 #if SYS_LIGHTWEIGHT_PROT
144 
150 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
151 
160 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
161 
169 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
170 sys_prot_t sys_arch_protect(void);
171 void sys_arch_unprotect(sys_prot_t pval);
172 
173 #else
174 
175 #define SYS_ARCH_DECL_PROTECT(lev)
176 #define SYS_ARCH_PROTECT(lev)
177 #define SYS_ARCH_UNPROTECT(lev)
178 
179 #endif /* SYS_LIGHTWEIGHT_PROT */
180 
181 #endif /* SYS_ARCH_PROTECT */
182 
183 #endif /* __LWIP_SYS_H__ */
GLbitfield GLuint64 timeout
Definition: glext.h:7831
u32_t time
Definition: sys.h:73
Definition: sys.h:78
void * arg
Definition: sys.h:75
struct sys_timeouts * sys_arch_timeouts(void)
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
void sys_mbox_post(sys_mbox_t mbox, void *msg)
int dummy
Definition: lstrlib.c:1125
GLuint GLuint GLsizei count
Definition: glext.h:6292
int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
Definition: sys.c:257
Definition: sys.h:71
void(* sys_timeout_handler)(void *arg)
Definition: sys.h:69
void sys_mbox_fetch(sys_mbox_t mbox, void **msg)
Definition: sys.c:49
mqbox_t * sys_mbox_t
Definition: sys_arch.h:50
lwp_t * sys_thread_t
Definition: sys_arch.h:53
sys_mbox_t sys_mbox_new(void)
sys_timeout_handler h
Definition: sys.h:74
static const unsigned char msg[]
Definition: ccm.c:375
struct sys_timeout * next
Definition: sys.h:72
void sys_untimeout(sys_timeout_handler h, void *arg)
Definition: sys.c:208
u8 u8_t
Definition: cc.h:43
Definition: implement.h:136
struct sys_timeout * next
Definition: sys.h:79
unsigned long sys_now(void)
void sys_sem_signal(sys_sem_t sem)
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
void sys_msleep(u32_t ms)
Definition: sys.c:284
void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
Definition: sys.c:157
void sys_sem_wait(sys_sem_t sem)
Definition: sys.c:101
void sys_init(void)
u32 u32_t
Definition: cc.h:47
sys_thread_t sys_thread_new(void(*thread)(void *arg), void *arg, int prio)
void sys_sem_free(sys_sem_t sem)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
void sys_mbox_free(sys_mbox_t mbox)
sys_sem_t sys_sem_new(u8_t count)
u32_t sys_jiffies(void)