diff options
| author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-08 22:16:46 +0000 |
|---|---|---|
| committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-08 22:16:46 +0000 |
| commit | e75e64e6b93800116de5e7da5f16a87006d20b22 (patch) | |
| tree | 44ea3c9fd203fce5d7c12d752fdc75c5cd1b9d01 /java/src/TimerQueue.java | |
| parent | 4c8e64c42a2a50576b94bcdcaab3af11ef69106e (diff) | |
| download | ATCD-e75e64e6b93800116de5e7da5f16a87006d20b22.tar.gz | |
*** NOTE:
Changed the semantics of Condition, TimedWait, MessageQueue,
Task, Mutex, Semaphore, and Token to use absolute times for
their timeouts.
Changed the semantics of EventHandler, ServiceObject, and
SvcHandler such that handleTimeout receives a TimeValue
representing when the event occured.
Changed TimerQueue internally to reflect the above changes.
Also made better checks in Token and Mutex so that non-owners
can call release without adverse effects. I plan to try to
do this with Semaphore and RWMutex as well.
Fixed several bugs in Token tryacquire and renew. Added
relativeTimeOfDay methods to TimeValue.
Diffstat (limited to 'java/src/TimerQueue.java')
| -rw-r--r-- | java/src/TimerQueue.java | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/java/src/TimerQueue.java b/java/src/TimerQueue.java index e3aa30d9472..a374a9603cd 100644 --- a/java/src/TimerQueue.java +++ b/java/src/TimerQueue.java @@ -40,7 +40,7 @@ class TimerNode // Argument to pass to <handleTimeout>. public TimeValue timerValue_; - // Time until the timer expires. + // Time when the timer expires. (absolute time) public TimeValue interval_; // If this is a periodic timer this holds the time until the next @@ -124,29 +124,26 @@ public class TimerQueue implements Runnable this.eventLoopRunning_ = true; TimeValue timeout = null; - TimeValue earliest = null; for (;;) { synchronized (this.obj_) { - earliest = this.earliestTime (); - if (earliest != null) - timeout = TimeValue.minus (earliest, TimeValue.getTimeOfDay ()); - else - timeout = new TimeValue (); + timeout = this.earliestTime (); + try { // Extract the earliest time from the queue and do a timed wait + // Note that this does a blocking wait if timeout is null this.obj_.timedWait (timeout); - // We have been notified. Check to see if we need to - // restart the wait with a different timeout + // We have been notified. if (this.reset_) { this.reset_ = false; this.obj_.condition (false); - timeout = TimeValue.minus (this.earliestTime (), TimeValue.getTimeOfDay ()); + // Don't need to change the timer since it's an absolute + // time value. } } catch (TimeoutException e) @@ -196,7 +193,7 @@ public class TimerQueue implements Runnable *@param handler Event Handler that is to be scheduled with the timer *@param obj Object that is passed back to the Event Handler when * timeout occurs (Asynchronous Completion Token) - *@param delta amount of time for which to schedule the timer + *@param delta amount of time for which to schedule the timer (relative time) *@return id of the timer scheduled */ public int scheduleTimer (EventHandler handler, @@ -217,23 +214,25 @@ public class TimerQueue implements Runnable *@param handler Event Handler that is to be scheduled with the timer *@param arg Object that is passed back to the Event Handler when * timeout occurs (Asynchronous Completion Token) - *@param timeout amount of time for which to schedule the timer + *@param delta amount of time for which to schedule the timer (relative time) *@param interval amount of time to use to reschedule the timer *@return id of the timer scheduled */ public int scheduleTimer (EventHandler handler, Object arg, - TimeValue timeout, + TimeValue delta, TimeValue interval) { // Increment the sequence number (it will wrap around). this.timerId_++; - ACE.DEBUG("scheduleTimer (" + this.timerId_ + "): " + timeout + ", " + interval); + ACE.DEBUG("scheduleTimer (" + this.timerId_ + "): " + + delta + ", " + interval); + // futureTime is the current time of day plus the given delta + TimeValue futureTime = TimeValue.relativeTimeOfDay (delta); - TimeValue futureTime = TimeValue.plus (timeout, TimeValue.getTimeOfDay ()); TimerNode node = new TimerNode (handler, arg, futureTime, |
