mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-25 00:14:02 +00:00
move sys_timeouts_mbox_fetch() to tcpip_timeouts_mbox_fetch()
This cleans up the code: sys_timeouts_mbox_fetch() was only used from tcpip.c anyway, so let's move it there. Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
parent
39ada6ec0e
commit
c257b56a39
@ -65,15 +65,53 @@ static sys_mbox_t mbox;
|
|||||||
sys_mutex_t lock_tcpip_core;
|
sys_mutex_t lock_tcpip_core;
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
#if LWIP_TIMERS
|
static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
|
||||||
/* wait for a message, timeouts are processed while waiting */
|
|
||||||
#define TCPIP_MBOX_FETCH(mbox, msg) sys_timeouts_mbox_fetch(mbox, msg)
|
#if !LWIP_TIMERS
|
||||||
#else /* LWIP_TIMERS */
|
|
||||||
/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
|
/* wait for a message with timers disabled (e.g. pass a timer-check trigger into tcpip_thread) */
|
||||||
#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
|
#define TCPIP_MBOX_FETCH(mbox, msg) sys_mbox_fetch(mbox, msg)
|
||||||
#endif /* LWIP_TIMERS */
|
#else /* !LWIP_TIMERS */
|
||||||
|
/* wait for a message, timeouts are processed while waiting */
|
||||||
|
#define TCPIP_MBOX_FETCH(mbox, msg) tcpip_timeouts_mbox_fetch(mbox, msg)
|
||||||
|
/**
|
||||||
|
* Wait (forever) for a message to arrive in an mbox.
|
||||||
|
* While waiting, timeouts are processed.
|
||||||
|
*
|
||||||
|
* @param mbox the mbox to fetch the message from
|
||||||
|
* @param msg the place to store the message
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
tcpip_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
||||||
|
{
|
||||||
|
u32_t sleeptime, res;
|
||||||
|
|
||||||
static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
|
again:
|
||||||
|
LWIP_ASSERT_CORE_LOCKED();
|
||||||
|
|
||||||
|
sleeptime = sys_timeouts_sleeptime();
|
||||||
|
if (sleeptime == SYS_TIMEOUTS_SLEEPTIME_INFINITE) {
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
sys_arch_mbox_fetch(mbox, msg, 0);
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
return;
|
||||||
|
} else if (sleeptime == 0) {
|
||||||
|
sys_check_timeouts();
|
||||||
|
/* We try again to fetch a message from the mbox. */
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK_TCPIP_CORE();
|
||||||
|
res = sys_arch_mbox_fetch(mbox, msg, sleeptime);
|
||||||
|
LOCK_TCPIP_CORE();
|
||||||
|
if (res == SYS_ARCH_TIMEOUT) {
|
||||||
|
/* If a SYS_ARCH_TIMEOUT value is returned, a timeout occurred
|
||||||
|
before a message could be fetched. */
|
||||||
|
sys_check_timeouts();
|
||||||
|
/* We try again to fetch a message from the mbox. */
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* !LWIP_TIMERS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main lwIP thread. This thread has exclusive access to lwIP core functions
|
* The main lwIP thread. This thread has exclusive access to lwIP core functions
|
||||||
|
@ -66,8 +66,10 @@
|
|||||||
#define HANDLER(x) x
|
#define HANDLER(x) x
|
||||||
#endif /* LWIP_DEBUG_TIMERNAMES */
|
#endif /* LWIP_DEBUG_TIMERNAMES */
|
||||||
|
|
||||||
|
#define LWIP_MAX_TIMEOUT 0x7fffffff
|
||||||
|
|
||||||
/* Check if timer's expiry time is greater than time and care about u32_t wraparounds */
|
/* Check if timer's expiry time is greater than time and care about u32_t wraparounds */
|
||||||
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) > 0x7fffffff) ? 1 : 0 )
|
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) > LWIP_MAX_TIMEOUT) ? 1 : 0 )
|
||||||
|
|
||||||
/** This array contains all stack-internal cyclic timers. To get the number of
|
/** This array contains all stack-internal cyclic timers. To get the number of
|
||||||
* timers, use LWIP_ARRAYSIZE() */
|
* timers, use LWIP_ARRAYSIZE() */
|
||||||
@ -340,9 +342,6 @@ sys_untimeout(sys_timeout_handler handler, void *arg)
|
|||||||
*
|
*
|
||||||
* Must be called periodically from your main loop.
|
* Must be called periodically from your main loop.
|
||||||
*/
|
*/
|
||||||
#if !LWIP_TESTMODE && !NO_SYS && !defined __DOXYGEN__
|
|
||||||
static
|
|
||||||
#endif /* !NO_SYS */
|
|
||||||
void
|
void
|
||||||
sys_check_timeouts(void)
|
sys_check_timeouts(void)
|
||||||
{
|
{
|
||||||
@ -417,9 +416,6 @@ sys_restart_timeouts(void)
|
|||||||
/** Return the time left before the next timeout is due. If no timeouts are
|
/** Return the time left before the next timeout is due. If no timeouts are
|
||||||
* enqueued, returns 0xffffffff
|
* enqueued, returns 0xffffffff
|
||||||
*/
|
*/
|
||||||
#if !LWIP_TESTMODE && !NO_SYS
|
|
||||||
static
|
|
||||||
#endif /* !NO_SYS */
|
|
||||||
u32_t
|
u32_t
|
||||||
sys_timeouts_sleeptime(void)
|
sys_timeouts_sleeptime(void)
|
||||||
{
|
{
|
||||||
@ -428,61 +424,18 @@ sys_timeouts_sleeptime(void)
|
|||||||
LWIP_ASSERT_CORE_LOCKED();
|
LWIP_ASSERT_CORE_LOCKED();
|
||||||
|
|
||||||
if (next_timeout == NULL) {
|
if (next_timeout == NULL) {
|
||||||
return 0xffffffff;
|
return SYS_TIMEOUTS_SLEEPTIME_INFINITE;
|
||||||
}
|
}
|
||||||
now = sys_now();
|
now = sys_now();
|
||||||
if (TIME_LESS_THAN(next_timeout->time, now)) {
|
if (TIME_LESS_THAN(next_timeout->time, now)) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return (u32_t)(next_timeout->time - now);
|
u32_t ret = (u32_t)(next_timeout->time - now);
|
||||||
|
LWIP_ASSERT("invalid sleeptime", ret <= LWIP_MAX_TIMEOUT);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NO_SYS
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wait (forever) for a message to arrive in an mbox.
|
|
||||||
* While waiting, timeouts are processed.
|
|
||||||
*
|
|
||||||
* @param mbox the mbox to fetch the message from
|
|
||||||
* @param msg the place to store the message
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
|
||||||
{
|
|
||||||
u32_t sleeptime, res;
|
|
||||||
|
|
||||||
again:
|
|
||||||
LWIP_ASSERT_CORE_LOCKED();
|
|
||||||
|
|
||||||
if (!next_timeout) {
|
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
sys_arch_mbox_fetch(mbox, msg, 0);
|
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sleeptime = sys_timeouts_sleeptime();
|
|
||||||
if (sleeptime == 0) {
|
|
||||||
sys_check_timeouts();
|
|
||||||
/* We try again to fetch a message from the mbox. */
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
|
|
||||||
UNLOCK_TCPIP_CORE();
|
|
||||||
res = sys_arch_mbox_fetch(mbox, msg, sleeptime);
|
|
||||||
LOCK_TCPIP_CORE();
|
|
||||||
if (res == SYS_ARCH_TIMEOUT) {
|
|
||||||
/* If a SYS_ARCH_TIMEOUT value is returned, a timeout occurred
|
|
||||||
before a message could be fetched. */
|
|
||||||
sys_check_timeouts();
|
|
||||||
/* We try again to fetch a message from the mbox. */
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
|
|
||||||
#else /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */
|
#else /* LWIP_TIMERS && !LWIP_TIMERS_CUSTOM */
|
||||||
/* Satisfy the TCP code which calls this function */
|
/* Satisfy the TCP code which calls this function */
|
||||||
void
|
void
|
||||||
|
@ -56,6 +56,11 @@ extern "C" {
|
|||||||
#endif /* LWIP_DEBUG*/
|
#endif /* LWIP_DEBUG*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** Returned by sys_timeouts_sleeptime() to indicate there is no timer, so we
|
||||||
|
* can sleep forever.
|
||||||
|
*/
|
||||||
|
#define SYS_TIMEOUTS_SLEEPTIME_INFINITE 0xFFFFFFFF
|
||||||
|
|
||||||
/** Function prototype for a stack-internal timer function that has to be
|
/** Function prototype for a stack-internal timer function that has to be
|
||||||
* called at a defined interval */
|
* called at a defined interval */
|
||||||
typedef void (* lwip_cyclic_timer_handler)(void);
|
typedef void (* lwip_cyclic_timer_handler)(void);
|
||||||
@ -106,13 +111,8 @@ void sys_timeout(u32_t msecs, sys_timeout_handler handler, void *arg);
|
|||||||
|
|
||||||
void sys_untimeout(sys_timeout_handler handler, void *arg);
|
void sys_untimeout(sys_timeout_handler handler, void *arg);
|
||||||
void sys_restart_timeouts(void);
|
void sys_restart_timeouts(void);
|
||||||
#if LWIP_TESTMODE || NO_SYS
|
|
||||||
void sys_check_timeouts(void);
|
void sys_check_timeouts(void);
|
||||||
u32_t sys_timeouts_sleeptime(void);
|
u32_t sys_timeouts_sleeptime(void);
|
||||||
#endif
|
|
||||||
#if !NO_SYS
|
|
||||||
void sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg);
|
|
||||||
#endif /* NO_SYS */
|
|
||||||
|
|
||||||
#if LWIP_TESTMODE
|
#if LWIP_TESTMODE
|
||||||
struct sys_timeo** lwip_sys_timers_get_next_timout(void);
|
struct sys_timeo** lwip_sys_timers_get_next_timout(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user