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 { |
64 |
if(timeouts->next->time > 0) { |
if (timeouts->next->time > 0) { |
65 |
time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time); |
time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time); |
66 |
} else { |
} else { |
67 |
time = 0xffffffff; |
time = 0xffffffff; |
68 |
} |
} |
69 |
|
|
70 |
if(time == 0xffffffff) { |
if (time == 0xffffffff) { |
71 |
/* If time == 0xffffffff, a timeout occured before a message could be |
/* If time == 0xffffffff, a timeout occured before a message could be |
72 |
fetched. We should now call the timeout handler and |
fetched. We should now call the timeout handler and |
73 |
deallocate the memory allocated for the timeout. */ |
deallocate the memory allocated for the timeout. */ |
76 |
h = tmptimeout->h; |
h = tmptimeout->h; |
77 |
arg = tmptimeout->arg; |
arg = tmptimeout->arg; |
78 |
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); |
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); |
79 |
if(h != NULL) { |
if (h != NULL) { |
80 |
DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); |
DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); |
81 |
h(arg); |
h(arg); |
82 |
} |
} |
87 |
/* If time != 0xffffffff, a message was received before the timeout |
/* If time != 0xffffffff, a message was received before the timeout |
88 |
occured. The time variable is set to the number of |
occured. The time variable is set to the number of |
89 |
milliseconds we waited for the message. */ |
milliseconds we waited for the message. */ |
90 |
if(time <= timeouts->next->time) { |
if (time <= timeouts->next->time) { |
91 |
timeouts->next->time -= time; |
timeouts->next->time -= time; |
92 |
} else { |
} else { |
93 |
timeouts->next->time = 0; |
timeouts->next->time = 0; |
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 { |
119 |
if(timeouts->next->time > 0) { |
if (timeouts->next->time > 0) { |
120 |
time = sys_arch_sem_wait(sem, timeouts->next->time); |
time = sys_arch_sem_wait(sem, timeouts->next->time); |
121 |
} else { |
} else { |
122 |
time = 0xffffffff; |
time = 0xffffffff; |
123 |
} |
} |
124 |
|
|
125 |
if(time == 0xffffffff) { |
if (time == 0xffffffff) { |
126 |
/* If time == 0xffffffff, a timeout occured before a message could be |
/* If time == 0xffffffff, a timeout occured before a message could be |
127 |
fetched. We should now call the timeout handler and |
fetched. We should now call the timeout handler and |
128 |
deallocate the memory allocated for the timeout. */ |
deallocate the memory allocated for the timeout. */ |
131 |
h = tmptimeout->h; |
h = tmptimeout->h; |
132 |
arg = tmptimeout->arg; |
arg = tmptimeout->arg; |
133 |
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); |
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); |
134 |
if(h != NULL) { |
if (h != NULL) { |
135 |
DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); |
DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); |
136 |
h(arg); |
h(arg); |
137 |
} |
} |
143 |
/* If time != 0xffffffff, a message was received before the timeout |
/* If time != 0xffffffff, a message was received before the timeout |
144 |
occured. The time variable is set to the number of |
occured. The time variable is set to the number of |
145 |
milliseconds we waited for the message. */ |
milliseconds we waited for the message. */ |
146 |
if(time <= timeouts->next->time) { |
if (time <= timeouts->next->time) { |
147 |
timeouts->next->time -= time; |
timeouts->next->time -= time; |
148 |
} else { |
} else { |
149 |
timeouts->next->time = 0; |
timeouts->next->time = 0; |
160 |
struct sys_timeout *timeout, *t; |
struct sys_timeout *timeout, *t; |
161 |
|
|
162 |
timeout = memp_malloc(MEMP_SYS_TIMEOUT); |
timeout = memp_malloc(MEMP_SYS_TIMEOUT); |
163 |
if(timeout == NULL) { |
if (timeout == NULL) { |
164 |
return; |
return; |
165 |
} |
} |
166 |
timeout->next = NULL; |
timeout->next = NULL; |
173 |
DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg)); |
DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg)); |
174 |
|
|
175 |
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); |
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); |
176 |
if(timeouts->next == NULL) { |
if (timeouts->next == NULL) { |
177 |
timeouts->next = timeout; |
timeouts->next = timeout; |
178 |
return; |
return; |
179 |
} |
} |
180 |
|
|
181 |
if(timeouts->next->time > msecs) { |
if (timeouts->next->time > msecs) { |
182 |
timeouts->next->time -= msecs; |
timeouts->next->time -= msecs; |
183 |
timeout->next = timeouts->next; |
timeout->next = timeouts->next; |
184 |
timeouts->next = timeout; |
timeouts->next = timeout; |
185 |
} else { |
} else { |
186 |
for(t = timeouts->next; t != NULL; t = t->next) { |
for(t = timeouts->next; t != NULL; t = t->next) { |
187 |
timeout->time -= t->time; |
timeout->time -= t->time; |
188 |
if(t->next == NULL || |
if (t->next == NULL || |
189 |
t->next->time > timeout->time) { |
t->next->time > timeout->time) { |
190 |
if(t->next != NULL) { |
if (t->next != NULL) { |
191 |
t->next->time -= timeout->time; |
t->next->time -= timeout->time; |
192 |
} |
} |
193 |
timeout->next = t->next; |
timeout->next = t->next; |