Package org.jcsp.lang

Class Alternative

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object altMonitor
      The monitor synchronising the writers and alting reader
      private boolean barrierPresent
      This indicates whether an AltingBarrier is one of the Guards.
      private int barrierSelected
      The index of a selected AltingBarrier.
      private boolean barrierTrigger
      This flag is set by a successful AltingBarrier enable/disable.
      private int enableIndex
      This is the index variable used during the enable/disable sequences.
      private static int enabling  
      private int favourite
      The index of the guard with highest priority for the next select.
      private Guard[] guard
      The array of guard events from which we are selecting.
      private static int inactive  
      private long msecs
      If one or more guards were CSTimers, this holds the earliest timeout.
      private int NONE_SELECTED  
      private static int ready  
      private int selected
      The index of the selected guard.
      private int state
      The state of the ALTing process.
      private int timeIndex
      If one or more guards were CSTimers, this holds the index of the one with the earliest timeout.
      private boolean timeout
      This flag is set if one of the enabled guards was a CSTimer guard.
      private static int waiting  
    • Constructor Summary

      Constructors 
      Constructor Description
      Alternative​(Guard[] guard)
      Construct an Alternative object operating on the Guard array of events.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void disableGuards()
      Disables the guards for selection.
      private void disableGuards​(boolean[] preCondition)
      Disables the guards for selection.
      private void enableGuards()
      Enables the guards for selection.
      private void enableGuards​(boolean[] preCondition)
      Enables the guards for selection.
      int fairSelect()
      Returns the index of one of the ready guards.
      int fairSelect​(boolean[] preCondition)
      Returns the index of one of the ready guards whose preCondition index is true.
      int priSelect()
      Returns the index of one of the ready guards.
      int priSelect​(boolean[] preCondition)
      Returns the index of one of the ready guards whose preCondition index is true.
      (package private) void schedule()
      This is the wake-up call to the process ALTing on guards controlled by this object.
      int select()
      Returns the index of one of the ready guards.
      int select​(boolean[] preCondition)
      Returns the index of one of the ready guards whose preCondition index is true.
      (package private) void setBarrierTrigger()
      This is a call-back from an AltingBarrier.
      (package private) void setTimeout​(long msecs)
      This is the call-back from enabling a CSTimer guard.
      • Methods inherited from class java.lang.Object

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

      • altMonitor

        protected java.lang.Object altMonitor
        The monitor synchronising the writers and alting reader
      • state

        private int state
        The state of the ALTing process.
      • guard

        private final Guard[] guard
        The array of guard events from which we are selecting.
      • favourite

        private int favourite
        The index of the guard with highest priority for the next select.
      • selected

        private int selected
        The index of the selected guard.
      • barrierPresent

        private boolean barrierPresent
        This indicates whether an AltingBarrier is one of the Guards.
      • barrierTrigger

        private boolean barrierTrigger
        This flag is set by a successful AltingBarrier enable/disable.
      • barrierSelected

        private int barrierSelected
        The index of a selected AltingBarrier.
      • enableIndex

        private int enableIndex
        This is the index variable used during the enable/disable sequences. This has been made global to simplify the call-back (setTimeout) from a CSTimer that is being enabled. That call-back sets the timeout, msecs and timeIndex variables below. The latter variable is needed only to work around the bug that Java wait-with-timeouts sometimes return early.
      • timeout

        private boolean timeout
        This flag is set if one of the enabled guards was a CSTimer guard.
      • msecs

        private long msecs
        If one or more guards were CSTimers, this holds the earliest timeout.
      • timeIndex

        private int timeIndex
        If one or more guards were CSTimers, this holds the index of the one with the earliest timeout.
    • Method Detail

      • select

        public final int select()
        Returns the index of one of the ready guards. The method will block until one of the guards becomes ready. If more than one is ready, an arbitrary choice is made.
      • priSelect

        public final int priSelect()
        Returns the index of one of the ready guards. The method will block until one of the guards becomes ready. If more than one is ready, the one with the lowest index is selected.
      • fairSelect

        public final int fairSelect()
        Returns the index of one of the ready guards. The method will block until one of the guards becomes ready. Consequetive invocations will service the guards `fairly' in the case when many guards are always ready. Implementation note: the last guard serviced has the lowest priority next time around.
      • enableGuards

        private final void enableGuards()
        Enables the guards for selection. If any of the guards are ready, it sets selected to the ready guard's index, state to ready and returns. Otherwise, it sets selected to NONE_SELECTED and returns.
      • disableGuards

        private void disableGuards()
        Disables the guards for selection. Sets selected to the index of the ready guard, taking care of priority/fair choice.
      • setTimeout

        void setTimeout​(long msecs)
        This is the call-back from enabling a CSTimer guard. It is part of the work-around for Java wait-with-timeouts sometimes returning early. It is still in the flow of control of the ALTing process.
      • setBarrierTrigger

        void setBarrierTrigger()
        This is a call-back from an AltingBarrier. It is still in the flow of control of the ALTing process.
      • schedule

        void schedule()
        This is the wake-up call to the process ALTing on guards controlled by this object. It is in the flow of control of a process writing to an enabled channel guard.
      • select

        public final int select​(boolean[] preCondition)
        Returns the index of one of the ready guards whose preCondition index is true. The method will block until one of these guards becomes ready. If more than one is ready, an arbitrary choice is made.

        Note: the length of the preCondition array must be the same as that of the array of guards with which this object was constructed.

        Parameters:
        preCondition - the guards from which to select
      • priSelect

        public final int priSelect​(boolean[] preCondition)
        Returns the index of one of the ready guards whose preCondition index is true. The method will block until one of these guards becomes ready. If more than one is ready, the one with the lowest index is selected.

        Note: the length of the preCondition array must be the same as that of the array of guards with which this object was constructed.

        Parameters:
        preCondition - the guards from which to select
      • fairSelect

        public final int fairSelect​(boolean[] preCondition)
        Returns the index of one of the ready guards whose preCondition index is true. The method will block until one of these guards becomes ready. Consequetive invocations will service the guards `fairly' in the case when many guards are always ready. Implementation note: the last guard serviced has the lowest priority next time around.

        Note: the length of the preCondition array must be the same as that of the array of guards with which this object was constructed.

        Parameters:
        preCondition - the guards from which to select
      • enableGuards

        private final void enableGuards​(boolean[] preCondition)
        Enables the guards for selection. The preCondition must be true for an guard to be selectable. If any of the guards are ready, it sets selected to the ready guard's index, state to ready and returns. Otherwise, it sets selected to NONE_SELECTED and returns.

      • disableGuards

        private void disableGuards​(boolean[] preCondition)
        Disables the guards for selection. The preCondition must be true for an guard to be selectable. Sets selected to the index of the ready guard, taking care of priority/fair choice.