1 |
/* |
/* |
2 |
* Copyright (c) 2001-2003 Swedish Institute of Computer Science. |
* Copyright (c) 2001-2003 Swedish Institute of Computer Science. |
3 |
* All rights reserved. |
* All rights reserved. |
4 |
* |
* |
5 |
* Redistribution and use in source and binary forms, with or without modification, |
* Redistribution and use in source and binary forms, with or without modification, |
6 |
* are permitted provided that the following conditions are met: |
* are permitted provided that the following conditions are met: |
7 |
* |
* |
8 |
* 1. Redistributions of source code must retain the above copyright notice, |
* 1. Redistributions of source code must retain the above copyright notice, |
11 |
* this list of conditions and the following disclaimer in the documentation |
* this list of conditions and the following disclaimer in the documentation |
12 |
* and/or other materials provided with the distribution. |
* and/or other materials provided with the distribution. |
13 |
* 3. The name of the author may not be used to endorse or promote products |
* 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. |
* 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 |
* 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 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
19 |
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
20 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
21 |
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
* 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 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
* 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 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
25 |
* OF SUCH DAMAGE. |
* OF SUCH DAMAGE. |
26 |
* |
* |
27 |
* This file is part of the lwIP TCP/IP stack. |
* This file is part of the lwIP TCP/IP stack. |
28 |
* |
* |
29 |
* Author: Adam Dunkels <adam@sics.se> |
* Author: Adam Dunkels <adam@sics.se> |
30 |
* |
* |
31 |
*/ |
*/ |
54 |
sys_timeout_handler h; |
sys_timeout_handler h; |
55 |
void *arg; |
void *arg; |
56 |
|
|
57 |
|
|
58 |
again: |
again: |
59 |
timeouts = sys_arch_timeouts(); |
timeouts = sys_arch_timeouts(); |
60 |
|
|
61 |
if (!timeouts || !timeouts->next) { |
if (!timeouts || !timeouts->next) { |
62 |
sys_arch_mbox_fetch(mbox, msg, 0); |
sys_arch_mbox_fetch(mbox, msg, 0); |
63 |
} else { |
} else { |
80 |
LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); |
LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); |
81 |
h(arg); |
h(arg); |
82 |
} |
} |
83 |
|
|
84 |
/* We try again to fetch a message from the mbox. */ |
/* We try again to fetch a message from the mbox. */ |
85 |
goto again; |
goto again; |
86 |
} else { |
} else { |
93 |
timeouts->next->time = 0; |
timeouts->next->time = 0; |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
97 |
} |
} |
98 |
} |
} |
99 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
105 |
struct sys_timeout *tmptimeout; |
struct sys_timeout *tmptimeout; |
106 |
sys_timeout_handler h; |
sys_timeout_handler h; |
107 |
void *arg; |
void *arg; |
108 |
|
|
109 |
/* while (sys_arch_sem_wait(sem, 1000) == 0); |
/* while (sys_arch_sem_wait(sem, 1000) == 0); |
110 |
return;*/ |
return;*/ |
111 |
|
|
112 |
again: |
again: |
113 |
|
|
114 |
timeouts = sys_arch_timeouts(); |
timeouts = sys_arch_timeouts(); |
115 |
|
|
116 |
if (!timeouts || !timeouts->next) { |
if (!timeouts || !timeouts->next) { |
117 |
sys_arch_sem_wait(sem, 0); |
sys_arch_sem_wait(sem, 0); |
118 |
} else { |
} else { |
135 |
LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); |
LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); |
136 |
h(arg); |
h(arg); |
137 |
} |
} |
138 |
|
|
139 |
|
|
140 |
/* We try again to fetch a message from the mbox. */ |
/* We try again to fetch a message from the mbox. */ |
141 |
goto again; |
goto again; |
142 |
} else { |
} else { |
149 |
timeouts->next->time = 0; |
timeouts->next->time = 0; |
150 |
} |
} |
151 |
} |
} |
152 |
|
|
153 |
} |
} |
154 |
} |
} |
155 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
167 |
timeout->h = h; |
timeout->h = h; |
168 |
timeout->arg = arg; |
timeout->arg = arg; |
169 |
timeout->time = msecs; |
timeout->time = msecs; |
170 |
|
|
171 |
timeouts = sys_arch_timeouts(); |
timeouts = sys_arch_timeouts(); |
172 |
|
|
173 |
LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg)); |
LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", |
174 |
|
(void *)timeout, msecs, (void *)h, (void *)arg)); |
175 |
|
|
176 |
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); |
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); |
177 |
if (timeouts->next == NULL) { |
if (timeouts->next == NULL) { |
178 |
timeouts->next = timeout; |
timeouts->next = timeout; |
179 |
return; |
return; |
180 |
} |
} |
181 |
|
|
182 |
if (timeouts->next->time > msecs) { |
if (timeouts->next->time > msecs) { |
183 |
timeouts->next->time -= msecs; |
timeouts->next->time -= msecs; |
184 |
timeout->next = timeouts->next; |
timeout->next = timeouts->next; |
197 |
} |
} |
198 |
} |
} |
199 |
} |
} |
200 |
|
|
201 |
} |
} |
202 |
|
|
203 |
/* Go through timeout list (for this task only) and remove the first matching entry, |
/* Go through timeout list (for this task only) and remove the first matching entry, |
211 |
struct sys_timeout *prev_t, *t; |
struct sys_timeout *prev_t, *t; |
212 |
|
|
213 |
timeouts = sys_arch_timeouts(); |
timeouts = sys_arch_timeouts(); |
214 |
|
|
215 |
if (timeouts->next == NULL) |
if (timeouts->next == NULL) |
216 |
return; |
return; |
217 |
|
|
235 |
return; |
return; |
236 |
} |
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
242 |
static void |
static void |
243 |
sswt_handler(void *arg) |
sswt_handler(void *arg) |
244 |
{ |
{ |
245 |
struct sswt_cb *sswt_cb = (struct sswt_cb *) arg; |
struct sswt_cb *sswt_cb = (struct sswt_cb *) arg; |
246 |
|
|
247 |
/* Timeout. Set flag to TRUE and signal semaphore */ |
/* Timeout. Set flag to TRUE and signal semaphore */ |
248 |
sswt_cb->timeflag = 1; |
sswt_cb->timeflag = 1; |
249 |
sys_sem_signal(*(sswt_cb->psem)); |
sys_sem_signal(*(sswt_cb->psem)); |
260 |
|
|
261 |
sswt_cb.psem = &sem; |
sswt_cb.psem = &sem; |
262 |
sswt_cb.timeflag = 0; |
sswt_cb.timeflag = 0; |
263 |
|
|
264 |
/* If timeout is zero, then just wait forever */ |
/* If timeout is zero, then just wait forever */ |
265 |
if (timeout > 0) |
if (timeout > 0) |
266 |
/* Create a timer and pass it the address of our flag */ |
/* Create a timer and pass it the address of our flag */ |
276 |
sys_untimeout(sswt_handler, &sswt_cb); |
sys_untimeout(sswt_handler, &sswt_cb); |
277 |
return 1; |
return 1; |
278 |
} |
} |
279 |
|
|
280 |
} |
} |
281 |
|
|
282 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |