mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-06-11 09:29:40 +00:00
Made lwip timeout measurements accurate by no longer returning 1 millisecond
whenever sys_arch_mbox_wait() and sys_arch_sem_wait() get a message or semaphore immediately. Updated documentation for this change. Unix port and Coldfire port have been updated.
This commit is contained in:
parent
2afa3c2f95
commit
0a27425c3e
|
@ -68,6 +68,7 @@ static struct sys_hisr *hisrs = NULL;
|
|||
#define TICKS_PER_SECOND 10000
|
||||
#define MS_TO_TICKS(MS) (MS * (TICKS_PER_SECOND / 1000))
|
||||
#define TICKS_TO_MS(TICKS) ((unsigned long)((1000ULL * TICKS) / TICKS_PER_SECOND))
|
||||
#define TICKS_TO_HUNDMICROSEC(TICKS) TICKS
|
||||
|
||||
#define SYS_MBOX_SIZE 128 // Number of elements in mbox queue
|
||||
#define SYS_STACK_SIZE 2048 // A minimum Nucleus stack for coldfire
|
||||
|
@ -278,12 +279,13 @@ sys_arch_sem_wait(sys_sem_t sem, u32_t timeout)
|
|||
status = NU_Obtain_Semaphore(sem,
|
||||
timeout ? MS_TO_TICKS(timeout) : NU_SUSPEND);
|
||||
/* This next statement takes wraparound into account. It works. Really! */
|
||||
timespent = TICKS_TO_MS(((s32_t) ((s32_t) NU_Retrieve_Clock() - (s32_t) timestart)));
|
||||
timespent = TICKS_TO_HUNDMICROSEC(((s32_t) ((s32_t) NU_Retrieve_Clock() - (s32_t) timestart)));
|
||||
|
||||
if (status == NU_TIMEOUT)
|
||||
return 0;
|
||||
return 0xffffffff;
|
||||
else
|
||||
return timespent ? timespent : 1;
|
||||
/* Round off to milliseconds */
|
||||
return (timespent+5)/10;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -423,12 +425,13 @@ sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
|
|||
|
||||
|
||||
/* This next statement takes wraparound into account. It works. Really! */
|
||||
timespent = TICKS_TO_MS(((s32_t) ((s32_t) NU_Retrieve_Clock() - (s32_t) timestart)));
|
||||
timespent = TICKS_TO_HUNDMICROSEC(((s32_t) ((s32_t) NU_Retrieve_Clock() - (s32_t) timestart)));
|
||||
|
||||
if (status == NU_TIMEOUT)
|
||||
return 0;
|
||||
return 0xffffffff;
|
||||
else
|
||||
return timespent ? timespent : 1;
|
||||
/* Round off to milliseconds */
|
||||
return (timespent+5)/10;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -251,7 +251,7 @@ sys_mbox_post(struct sys_mbox *mbox, void *msg)
|
|||
u32_t
|
||||
sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, u32_t timeout)
|
||||
{
|
||||
u32_t time = 1;
|
||||
u32_t time = 0;
|
||||
|
||||
/* The mutex lock is quick so we don't bother with the timeout
|
||||
stuff here. */
|
||||
|
@ -266,8 +266,8 @@ sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, u32_t timeout)
|
|||
time = sys_arch_sem_wait(mbox->mail, timeout);
|
||||
|
||||
/* If time == 0, the sem_wait timed out, and we return 0. */
|
||||
if(time == 0) {
|
||||
return 0;
|
||||
if(time == 0xffffffff) {
|
||||
return 0xffffffff;
|
||||
}
|
||||
} else {
|
||||
sys_arch_sem_wait(mbox->mail, 0);
|
||||
|
@ -345,7 +345,7 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
|
|||
retval = pthread_cond_timedwait(cond, mutex, &ts);
|
||||
|
||||
if(retval == ETIMEDOUT) {
|
||||
return 0;
|
||||
return 0xffffffff;
|
||||
} else {
|
||||
/* Calculate for how long we waited for the cond. */
|
||||
gettimeofday(&rtime2, &tz);
|
||||
|
@ -353,30 +353,30 @@ cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex, u32_t timeout)
|
|||
(rtime2.tv_usec - rtime1.tv_usec) / 1000;
|
||||
|
||||
if(tdiff <= 0) {
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return tdiff;
|
||||
}
|
||||
} else {
|
||||
pthread_cond_wait(cond, mutex);
|
||||
return 0;
|
||||
return 0xffffffff;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u32_t
|
||||
sys_arch_sem_wait(struct sys_sem *sem, u32_t timeout)
|
||||
{
|
||||
u32_t time = 1;
|
||||
u32_t time = 0;
|
||||
|
||||
pthread_mutex_lock(&(sem->mutex));
|
||||
while(sem->c <= 0) {
|
||||
if(timeout > 0) {
|
||||
time = cond_wait(&(sem->cond), &(sem->mutex), timeout);
|
||||
|
||||
if(time == 0) {
|
||||
if(time == 0xffffffff) {
|
||||
pthread_mutex_unlock(&(sem->mutex));
|
||||
return 0;
|
||||
return 0xffffffff;
|
||||
}
|
||||
/* pthread_mutex_unlock(&(sem->mutex));
|
||||
return time; */
|
||||
|
|
Loading…
Reference in New Issue
Block a user