Package libsidplay.common
Klasse EventScheduler
java.lang.Object
libsidplay.common.EventScheduler
Fast EventScheduler, which maintains a linked list of Events. This scheduler
takes neglible time even when it is used to schedule events for nearly every
clock.
Events occur on an internal clock which is 2x the visible clock. The visible
clock is divided to two phases called phi1 and phi2.
The phi1 clocks are used by VIC and CIA chips, phi2 clocks by CPU.
Scheduling an event for a phi1 clock when system is in phi2 causes the event
to be moved to the next phi1 cycle. Correspondingly, requesting a phi1 time
when system is in phi2 returns the value of the next phi1.
- Autor:
- Antti S. Lankila
-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprivate longEventScheduler's current clockprivate doubleprivate final EventThe root of event chain, always before and after every other event.private final EventThe tail event, always after every other event.private static final intInterval to check thread-safe queue for key-eventsprivate static final intInterval to check thread-safe queue for eventsprivate final EventPeriodic thread-safe event scheduling mechanism.private final EventPeriodic thread-safe event scheduling mechanism for key events. -
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungprivate voidaddEventToSchedule(Event event) Scan the event queue and schedule event for execution.booleanCancel the specified event.voidclock()Fire next event, advance system time to that eventvoidProcess next thread-save eventdoublelonggetTime(Event.Phase phase) Get time with respect to a specific clock phasebooleanIs the event pending in this scheduler?phase()Return current clock phasevoidreset()Cancel all pending events and reset time.voidAdd event to pending queue in the same phase as current event.voidschedule(Event event, long cycles, Event.Phase phase) Add event to pending queue.voidscheduleAbsolute(Event event, long absoluteCycles, Event.Phase phase) Schedule event to occur at some absolute time.voidscheduleThreadSafe(Event event) Schedule an event in a thread-safe manner.voidscheduleThreadSafeKeyEvent(Event event) Schedule a key event in a thread-safe manner.voidsetCyclesPerSecond(double cyclesPerSecond)
-
Felddetails
-
THREAD_SAFE_KEY_EVENT_QUEUE_CHECK_INTERVAL
private static final int THREAD_SAFE_KEY_EVENT_QUEUE_CHECK_INTERVALInterval to check thread-safe queue for key-events- Siehe auch:
-
THREAD_SAFE_QUEUE_CHECK_INTERVAL
private static final int THREAD_SAFE_QUEUE_CHECK_INTERVALInterval to check thread-safe queue for events- Siehe auch:
-
currentTime
private long currentTimeEventScheduler's current clock -
cyclesPerSecond
private double cyclesPerSecond -
threadSafeKeyQueue
-
threadSafeQueue
-
lastEvent
The tail event, always after every other event. -
firstEvent
The root of event chain, always before and after every other event. -
threadSafeQueueingEvent
Periodic thread-safe event scheduling mechanism. -
threadSafeQueueingKeyEvent
Periodic thread-safe event scheduling mechanism for key events.
-
-
Konstruktordetails
-
EventScheduler
public EventScheduler()
-
-
Methodendetails
-
scheduleThreadSafeKeyEvent
Schedule a key event in a thread-safe manner. The thread-safe queue is moved to the unsafe queue periodically, and specific execution time is unpredictable, but will always occur during the PHI1 phase.- Parameter:
event- The event to schedule.
-
scheduleThreadSafe
Schedule an event in a thread-safe manner. The thread-safe queue is moved to the unsafe queue periodically, and specific execution time is unpredictable, but will always occur during the PHI1 phase.- Parameter:
event- The event to schedule.
-
schedule
Add event to pending queue. At PHI2, specify cycles=0 and Phase=PHI1 to fire on the very next PHI1.- Parameter:
event- The event to addcycles- How many cycles from now to firephase- The phase when to fire the event.
-
schedule
Add event to pending queue in the same phase as current event.- Parameter:
event- The event to addcycles- How many cycles from now to fire.
-
scheduleAbsolute
Schedule event to occur at some absolute time.- Parameter:
event- The event to addabsoluteCycles- When to firephase- Phase when event fires
-
addEventToSchedule
Scan the event queue and schedule event for execution.- Parameter:
event- The event to add
-
cancel
Cancel the specified event.- Parameter:
event- The event to cancel- Gibt zurück:
- true if an event was actually removed
-
reset
public void reset()Cancel all pending events and reset time. -
clock
Fire next event, advance system time to that event- Löst aus:
InterruptedException
-
clockThreadSafeEvents
Process next thread-save event- Löst aus:
InterruptedException
-
isPending
Is the event pending in this scheduler?- Parameter:
event- the event- Gibt zurück:
- true when pending
-
getTime
Get time with respect to a specific clock phase- Parameter:
phase- The phase- Gibt zurück:
- the time according to specified phase.
-
phase
Return current clock phase- Gibt zurück:
- The current phase
-
getCyclesPerSecond
public double getCyclesPerSecond() -
setCyclesPerSecond
public void setCyclesPerSecond(double cyclesPerSecond)
-