From: <jsa...@us...> - 2009-02-14 16:13:38
|
Revision: 133 http://flexotask.svn.sourceforge.net/flexotask/?rev=133&view=rev Author: jsauerbach Date: 2009-02-14 16:13:35 +0000 (Sat, 14 Feb 2009) Log Message: ----------- Add priority control to the FlexotaskThreadFactory API; the new API provides that the scheduler would call setPriority on each FlexotaskSchedulerRunnable before calling the thread factory. The default is to use the max available priority. This change unavoidably puts the head release in sourceforge out of sync with the latest available IBM Runtime Provider code from alphaworks; thus, no new public release of the open source should be made until the alphaWorks release is updated. Developers using the bleeding edge code may need to comment out the vmBridge call in FlexotaskSystemSupport until alphaWorks catches up. Modified Paths: -------------- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/FlexotaskSchedulerRunnable.java trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskSystemSupport.java trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java trunk/flexotask/src/com/ibm/realtime/flexotask/vm/FlexotaskVMBridge.java Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/FlexotaskSchedulerRunnable.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/FlexotaskSchedulerRunnable.java 2009-02-13 15:22:34 UTC (rev 132) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/FlexotaskSchedulerRunnable.java 2009-02-14 16:13:35 UTC (rev 133) @@ -22,14 +22,24 @@ { /** The FlexotaskTimerService to use for this Runnable */ private FlexotaskTimerService timer; + + /** The priority (using the RTSJ scale of 1-28) at which this Runnable is to run */ + private int priority = 28; /** - * Set the timer service. Called exactly once from the thread factory - * @param timer the new timer to set + * @return the priority at which this Runnable should run, using the RTSJ scale of 1-28 (default is 28 if never set) */ - public void setTimerService(FlexotaskTimerService timer) + public int getPriority() { + return priority; + } + + /** + * Sleep until a specified time in the nanoTime scale + * @param deadline the time in nanoseconds at which to wake up (same time scale as nanoTime) + */ + public void nanosleep(long deadline) { - this.timer = timer; + timer.nanosleep(deadline); } /** @@ -42,15 +52,19 @@ } /** - * Sleep until a specified time in the nanoTime scale - * @param deadline the time in nanoseconds at which to wake up (same time scale as nanoTime) + * Set the priority at which this Runnable should run, using the RTSJ scale of 1-28 (default is 28 if never set). + * This method must be called prior to passing the Runnable to the thread factory. Otherwise, the call will have no + * effect. + * @param priority the new priority, which must be in the range 1-28 */ - public void nanosleep(long deadline) - { - timer.nanosleep(deadline); - } + public void setPriority(int priority) { + if (priority < 1 || priority > 28) { + throw new IllegalArgumentException("Priority must be in the range 1-28"); + } + this.priority = priority; + } - /** + /** * Method to implement to gain access to a set of locks residing on the public heap (and pinned there). This is necessary if * the scheduler thread will do any synchronization, either with external threads or with other scheduler threads. * Called exactly once from the thread factory. The default implementation does nothing. @@ -59,4 +73,13 @@ public void setSchedulerLocks(Object[] locks) { } + + /** + * Set the timer service. Called exactly once from the thread factory + * @param timer the new timer to set + */ + public void setTimerService(FlexotaskTimerService timer) + { + this.timer = timer; + } } Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskSystemSupport.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskSystemSupport.java 2009-02-13 15:22:34 UTC (rev 132) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskSystemSupport.java 2009-02-14 16:13:35 UTC (rev 133) @@ -178,6 +178,20 @@ } /** + * Cause the current thread to adopt the RT priority expressed by the priority argument (which should be in the RTSJ + * range 1-28). Mapping from these priorities to OS priorities is up to the VM provider; if the VM also supports RTSJ, + * the mapping should be the same as for RTSJ PriorityParameter objects, even though this interface currently does + * not use those objects + * @param priority the priority to adopt + */ + static void adoptPriority(int priority) { + // TODO should there be an error indication if this doesn't work? + if (vmBridge != null) { + vmBridge.adoptPriority(priority); + } // else do nothing + } + + /** * Allocates a primitive array in the stable area. This is designed to be used when the transient * policy is enabled and primitive array classes are not marked stable (note that in some cases, * for example using borrowed arguments in conjunction with the preemptive atomic regions feature, @@ -625,7 +639,7 @@ return true; } - /** + /** * Called when tracing time events only. Dumps the contents of the time trace when it fills. * @param time the time value to record * @param sleep indicates that the event is a sleep event, rather than a time query Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java 2009-02-13 15:22:34 UTC (rev 132) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java 2009-02-14 16:13:35 UTC (rev 133) @@ -132,7 +132,7 @@ */ private static class SchedulerWrapper implements Runnable { /** The actual scheduler runnable wrapped by this wrapper */ - private Runnable target; + private FlexotaskSchedulerRunnable target; /** The thread context to use for tracing */ private ThreadContext threadContext; /** The FlexotaskGraph of which this thread is a member */ @@ -146,7 +146,7 @@ * @param threadContext the context object to use for tracing * @param graph the FlexotaskGraph of which this thread is a member */ - SchedulerWrapper(Runnable target, ThreadContext threadContext, FlexotaskGraphImpl graph) + SchedulerWrapper(FlexotaskSchedulerRunnable target, ThreadContext threadContext, FlexotaskGraphImpl graph) { this.target = target; this.threadContext = threadContext; @@ -159,6 +159,7 @@ threadContext.activate(); FlexotaskSystemSupport.switchMemorySpace(target); FlexotaskSystemSupport.becomeFlexotaskThread(true); + FlexotaskSystemSupport.adoptPriority(target.getPriority()); try { target.run(); } catch(Throwable t) { Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/vm/FlexotaskVMBridge.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/vm/FlexotaskVMBridge.java 2009-02-13 15:22:34 UTC (rev 132) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/vm/FlexotaskVMBridge.java 2009-02-14 16:13:35 UTC (rev 133) @@ -28,7 +28,9 @@ public static final int NORMAL_MEMORY = 0; /** Indicator passed to createMemorySpace to indicate the scheduler heap */ public static final int SCHEDULER_MEMORY = 1; - /** @see FlexotaskSystemSupport#allocateStablePrimitiveArray(Class, int, StableArrayImpl) */ + /** @see FlexotaskSystemSupport#adoptPriority(int) */ + void adoptPriority(int priority); + /** @see FlexotaskSystemSupport#allocateStablePrimitiveArray(Class, int, StableArrayImpl) */ Object allocateStablePrimitiveArray(Class type, int size); /** @see FlexotaskSystemSupport#becomeFlexotaskThread(boolean) */ void becomeFlexotaskThread(boolean state); @@ -150,6 +152,6 @@ long startTransaction(Object target); /** @see FlexotaskSystemSupport#switchMemorySpace(Object) */ long switchMemorySpace(Object target); - /** @see FlexotaskSystemSupport#unpin(Object[]) */ + /** @see FlexotaskSystemSupport#unpin(Object[]) */ void unpin(Object[] objects); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |