Fix timeout values in epicsEventWaitWithTimeout()
isnan(timeOut) => wait forever 0 < timeOut < 1/rate => 1 tick rtems_interval is a typedef for uint32_t
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
#include <rtems.h>
|
||||
#include <rtems/error.h>
|
||||
|
||||
@@ -66,7 +66,7 @@ epicsEventWaitWithTimeout(epicsEventId pSem, double timeOut)
|
||||
{
|
||||
int sc;
|
||||
rtems_interval delay;
|
||||
int rate = rtems_clock_get_ticks_per_second();
|
||||
rtems_interval rate = rtems_clock_get_ticks_per_second();
|
||||
|
||||
if (!rate)
|
||||
return epicsEventError;
|
||||
@@ -78,11 +78,16 @@ epicsEventWaitWithTimeout(epicsEventId pSem, double timeOut)
|
||||
else
|
||||
return epicsEventWaitTimeout;
|
||||
}
|
||||
else if (timeOut >= (double) INT_MAX / rate) {
|
||||
delay = 0;
|
||||
else if (timeOut < (double) UINT32_MAX / rate) {
|
||||
delay = timeOut * rate;
|
||||
if (delay == 0) {
|
||||
/* 0 < timeOut < 1/rate; round up */
|
||||
delay = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
delay = timeOut * rate;
|
||||
/* timeOut is NaN or too big to represent; wait forever */
|
||||
delay = RTEMS_NO_TIMEOUT;
|
||||
}
|
||||
|
||||
sc = rtems_binary_semaphore_wait_timed_ticks(&pSem->rbs, delay);
|
||||
|
||||
Reference in New Issue
Block a user