Class TimedEventsProcessor


  • @ThreadSafe
    public class TimedEventsProcessor
    extends java.lang.Object
    Timed events processing is a soft real-time system based on a logical system clock, interpreted as number of passed CPU cycles.

    Events (Runnable objects) are scheduled to be run every given cycles. Scheduling events is a thread-safe operation, so any device can register an event handler (= schedule an event) from any thread.

    CPU is responsible for advancing the clock after each executed instruction (see advanceClock method), which is supposed to be run on the CPU emulator thread. The events which passed their deadline are then triggered on the same thread (CPU thread).

    If the CPU supports timed events processing, it should return an instance of this class in the getTimedEventsProcessor method.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void advanceClock​(int cycles)
      Advances system clock (number of passed CPU cycles) and triggers all events which passed their deadline.
      void remove​(int cycles, java.lang.Runnable function)
      Remove scheduled event from this processor.
      void schedule​(int cycles, java.lang.Runnable event)
      Schedule a repeated event to be run every given cycles.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TimedEventsProcessor

        public TimedEventsProcessor()
    • Method Detail

      • schedule

        public void schedule​(int cycles,
                             java.lang.Runnable event)
        Schedule a repeated event to be run every given cycles.

        This function is thread-safe.

        Parameters:
        cycles - the number of cycles (must be > 0)
        event - event to be triggered every given cycles
      • remove

        public void remove​(int cycles,
                           java.lang.Runnable function)
        Remove scheduled event from this processor.

        This function is thread-safe.

        Parameters:
        cycles - the number of cycles
        function - the scheduled event
      • advanceClock

        public void advanceClock​(int cycles)
        Advances system clock (number of passed CPU cycles) and triggers all events which passed their deadline.

        This function should be called from a CPU emulation thread; thus it is not thread-safe.

        Parameters:
        cycles - passed cycles in the system