From 83a864997df53831cb6eb466d4f0524d9f6d50a8 Mon Sep 17 00:00:00 2001 From: "W. Eric Norum" Date: Fri, 18 May 2001 19:36:03 +0000 Subject: [PATCH] Implement agreed-upon semantics for delay/timeout arguments. A delay/timeout <=0.0 results in a yield/poll. A delay/timeout >0.0 is rounded up to 1 tick. --- src/libCom/osi/os/RTEMS/osdEvent.c | 16 ++++++++++++---- src/libCom/osi/os/RTEMS/osdMutex.c | 18 +++++++++++++----- src/libCom/osi/os/RTEMS/osdThread.c | 11 ++++++++--- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/libCom/osi/os/RTEMS/osdEvent.c b/src/libCom/osi/os/RTEMS/osdEvent.c index 9ba549ffa..f6bc2a2f9 100644 --- a/src/libCom/osi/os/RTEMS/osdEvent.c +++ b/src/libCom/osi/os/RTEMS/osdEvent.c @@ -125,14 +125,22 @@ epicsEventWaitWithTimeout(epicsEventId id, double timeOut) { rtems_id sid = (rtems_id)id; rtems_status_code sc; + rtems_unsigned32 wait; rtems_interval delay; extern double rtemsTicksPerSecond_double; SEMSTAT(1) - delay = timeOut * rtemsTicksPerSecond_double; - if (delay == 0) - delay = 1; - sc = rtems_semaphore_obtain (sid, RTEMS_WAIT, delay); + if (timeOut <= 0.0) { + wait = RTEMS_NO_WAIT; + delay = 0; + } + else { + wait = RTEMS_WAIT; + delay = timeOut * rtemsTicksPerSecond_double; + if (delay == 0) + delay++; + } + sc = rtems_semaphore_obtain (sid, wait, delay); if (sc == RTEMS_SUCCESSFUL) return epicsEventWaitOK; else if (sc == RTEMS_TIMEOUT) diff --git a/src/libCom/osi/os/RTEMS/osdMutex.c b/src/libCom/osi/os/RTEMS/osdMutex.c index 5c5a34fca..8152c107e 100644 --- a/src/libCom/osi/os/RTEMS/osdMutex.c +++ b/src/libCom/osi/os/RTEMS/osdMutex.c @@ -153,19 +153,27 @@ epicsMutexLockStatus epicsMutexLockWithTimeout( #ifdef RTEMS_FAST_MUTEX Semaphore_Control *the_semaphore = (Semaphore_Control *)id; ISR_Level level; + boolean wait; rtems_interval delay; extern double rtemsTicksPerSecond_double; SEMSTAT(1) - delay = timeOut * rtemsTicksPerSecond_double; - if (delay == 0) - delay = 1; + if (timeOut <= 0.0) { + wait = FALSE; + delay = 0; + } + else { + wait = TRUE; + delay = timeOut * rtemsTicksPerSecond_double; + if (delay == 0) + delay++; + } _ISR_Disable( level ); _CORE_mutex_Seize( &the_semaphore->Core_control.mutex, the_semaphore->Object.id, - 1, /* TRUE or FALSE */ - delay, /* same as passed to obtain -- ticks */ + wait, + delay, level ); if (_Thread_Executing->Wait.return_code == 0) diff --git a/src/libCom/osi/os/RTEMS/osdThread.c b/src/libCom/osi/os/RTEMS/osdThread.c index ea459bfa0..d33357b71 100644 --- a/src/libCom/osi/os/RTEMS/osdThread.c +++ b/src/libCom/osi/os/RTEMS/osdThread.c @@ -371,9 +371,14 @@ epicsThreadSleep (double seconds) rtems_interval delay; extern double rtemsTicksPerSecond_double; - delay = seconds * rtemsTicksPerSecond_double; - if (delay == 0) - delay++; + if (seconds <= 0.0) { + delay = 0; + } + else { + delay = seconds * rtemsTicksPerSecond_double; + if (delay == 0) + delay++; + } sc = rtems_task_wake_after (delay); if(sc != RTEMS_SUCCESSFUL) errlogPrintf("epicsThreadSleep: %s\n", rtems_status_text (sc));