Klasse EventScheduler

java.lang.Object
libsidplay.common.EventScheduler

public final class EventScheduler extends Object
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
  • Felddetails

    • THREAD_SAFE_KEY_EVENT_QUEUE_CHECK_INTERVAL

      private static final int THREAD_SAFE_KEY_EVENT_QUEUE_CHECK_INTERVAL
      Interval to check thread-safe queue for key-events
      Siehe auch:
    • THREAD_SAFE_QUEUE_CHECK_INTERVAL

      private static final int THREAD_SAFE_QUEUE_CHECK_INTERVAL
      Interval to check thread-safe queue for events
      Siehe auch:
    • currentTime

      private long currentTime
      EventScheduler's current clock
    • cyclesPerSecond

      private double cyclesPerSecond
    • threadSafeKeyQueue

      private List<Event> threadSafeKeyQueue
    • threadSafeQueue

      private List<Event> threadSafeQueue
    • lastEvent

      private final Event lastEvent
      The tail event, always after every other event.
    • firstEvent

      private final Event firstEvent
      The root of event chain, always before and after every other event.
    • threadSafeQueueingEvent

      private final Event threadSafeQueueingEvent
      Periodic thread-safe event scheduling mechanism.
    • threadSafeQueueingKeyEvent

      private final Event threadSafeQueueingKeyEvent
      Periodic thread-safe event scheduling mechanism for key events.
  • Konstruktordetails

    • EventScheduler

      public EventScheduler()
  • Methodendetails

    • scheduleThreadSafeKeyEvent

      public void scheduleThreadSafeKeyEvent(Event event)
      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

      public void scheduleThreadSafe(Event event)
      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

      public void schedule(Event event, long cycles, Event.Phase phase)
      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 add
      cycles - How many cycles from now to fire
      phase - The phase when to fire the event.
    • schedule

      public void schedule(Event event, long cycles)
      Add event to pending queue in the same phase as current event.
      Parameter:
      event - The event to add
      cycles - How many cycles from now to fire.
    • scheduleAbsolute

      public void scheduleAbsolute(Event event, long absoluteCycles, Event.Phase phase)
      Schedule event to occur at some absolute time.
      Parameter:
      event - The event to add
      absoluteCycles - When to fire
      phase - Phase when event fires
    • addEventToSchedule

      private void addEventToSchedule(Event event)
      Scan the event queue and schedule event for execution.
      Parameter:
      event - The event to add
    • cancel

      public boolean cancel(Event event)
      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

      public void clock() throws InterruptedException
      Fire next event, advance system time to that event
      Löst aus:
      InterruptedException
    • clockThreadSafeEvents

      public void clockThreadSafeEvents() throws InterruptedException
      Process next thread-save event
      Löst aus:
      InterruptedException
    • isPending

      public boolean isPending(Event event)
      Is the event pending in this scheduler?
      Parameter:
      event - the event
      Gibt zurück:
      true when pending
    • getTime

      public long getTime(Event.Phase phase)
      Get time with respect to a specific clock phase
      Parameter:
      phase - The phase
      Gibt zurück:
      the time according to specified phase.
    • phase

      public Event.Phase phase()
      Return current clock phase
      Gibt zurück:
      The current phase
    • getCyclesPerSecond

      public double getCyclesPerSecond()
    • setCyclesPerSecond

      public void setCyclesPerSecond(double cyclesPerSecond)