ProcessorScheduler.st
changeset 22062 eda26ee1f6f5
parent 22060 19b51303fe00
child 22078 24f52f37b7c0
equal deleted inserted replaced
22061:6b7d60d13319 22062:eda26ee1f6f5
  2891      block will be interrupted for execution of the block.
  2891      block will be interrupted for execution of the block.
  2892      (if it is running, the interrupt will occur in whatever method it is
  2892      (if it is running, the interrupt will occur in whatever method it is
  2893       executing; if it is suspended, it will be resumed).
  2893       executing; if it is suspended, it will be resumed).
  2894      The block will be removed from the timed-block list after evaluation
  2894      The block will be removed from the timed-block list after evaluation
  2895      (i.e. it will trigger only once).
  2895      (i.e. it will trigger only once).
  2896      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2896      Returns an ID, which can be used in #removeTimeoutWithID:"
  2897 
  2897 
  2898     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:timeDuration getMilliseconds
  2898     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:timeDuration getMilliseconds
       
  2899 
       
  2900     "Modified (comment): / 20-07-2017 / 16:43:12 / cg"
  2899 !
  2901 !
  2900 
  2902 
  2901 addTimedBlock:aBlock afterMilliseconds:delta
  2903 addTimedBlock:aBlock afterMilliseconds:delta
  2902     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2904     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2903      evaluated after delta milliseconds. The process which installs this timed
  2905      evaluated after delta milliseconds. The process which installs this timed
  2904      block will be interrupted for execution of the block.
  2906      block will be interrupted for execution of the block.
  2905      (if it is running, the interrupt will occur in whatever method it is
  2907      (if it is running, the interrupt will occur in whatever method it is
  2906       executing; if it is suspended, it will be resumed).
  2908       executing; if it is suspended, it will be resumed).
  2907      The block will be removed from the timed-block list after evaluation
  2909      The block will be removed from the timed-block list after evaluation
  2908      (i.e. it will trigger only once).
  2910      (i.e. it will trigger only once).
  2909      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2911      Returns an ID, which can be used in #removeTimeoutWithID:"
  2910 
  2912 
  2911     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
  2913     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
  2912 
  2914 
  2913     "Modified: 23.9.1996 / 14:33:59 / cg"
  2915     "Modified: / 23-09-1996 / 14:33:59 / cg"
       
  2916     "Modified (comment): / 20-07-2017 / 16:43:17 / cg"
  2914 !
  2917 !
  2915 
  2918 
  2916 addTimedBlock:aBlock afterSeconds:delta
  2919 addTimedBlock:aBlock afterSeconds:delta
  2917     "add the argument, aBlock to the list of time-scheduled-blocks.
  2920     "add the argument, aBlock to the list of time-scheduled-blocks.
  2918      to be evaluated after delta seconds. The process which installs this timed
  2921      to be evaluated after delta seconds. The process which installs this timed
  2919      block will be interrupted for execution of the block.
  2922      block will be interrupted for execution of the block.
  2920      (if it is running, the interrupt will occur in whatever method it is
  2923      (if it is running, the interrupt will occur in whatever method it is
  2921       executing; if it is suspended, it will be resumed).
  2924       executing; if it is suspended, it will be resumed).
  2922      The block will be removed from the timed-block list after evaluation
  2925      The block will be removed from the timed-block list after evaluation
  2923      (i.e. it will trigger only once).
  2926      (i.e. it will trigger only once).
  2924      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2927      Returns an ID, which can be used in #removeTimeoutWithID:"
  2925 
  2928 
  2926     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
  2929     ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
  2927 
  2930 
  2928     "Modified: 23.9.1996 / 14:34:04 / cg"
  2931     "Modified: / 23-09-1996 / 14:34:04 / cg"
       
  2932     "Modified (comment): / 20-07-2017 / 16:42:54 / cg"
  2929 !
  2933 !
  2930 
  2934 
  2931 addTimedBlock:aBlock atMilliseconds:aMillisecondTime
  2935 addTimedBlock:aBlock atMilliseconds:aMillisecondTime
  2932     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2936     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2933      evaluated when the millisecondClock value passes aMillisecondTime.
  2937      evaluated when the millisecondClock value passes aMillisecondTime.
  2935      execution of the block.
  2939      execution of the block.
  2936      (if it is running, the interrupt will occur in whatever method it is
  2940      (if it is running, the interrupt will occur in whatever method it is
  2937       executing; if it is suspended, it will be resumed).
  2941       executing; if it is suspended, it will be resumed).
  2938      The block will be removed from the timed-block list after evaluation
  2942      The block will be removed from the timed-block list after evaluation
  2939      (i.e. it will trigger only once).
  2943      (i.e. it will trigger only once).
  2940      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2944      Returns an ID, which can be used in #removeTimeoutWithID:"
  2941 
  2945 
  2942     ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
  2946     ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
  2943 
  2947 
  2944     "Modified: 23.9.1996 / 14:34:09 / cg"
  2948     "Modified: / 23-09-1996 / 14:34:09 / cg"
       
  2949     "Modified (comment): / 20-07-2017 / 16:43:22 / cg"
  2945 !
  2950 !
  2946 
  2951 
  2947 addTimedBlock:aBlock for:aProcess after:timeDuration
  2952 addTimedBlock:aBlock for:aProcess after:timeDuration
  2948     "add the argument, aBlock to the list of time-scheduled-blocks.
  2953     "add the argument, aBlock to the list of time-scheduled-blocks.
  2949      to be evaluated after timeDuration. aProcess will be interrupted for
  2954      to be evaluated after timeDuration. aProcess will be interrupted for
  2952       executing; if it is suspended, it will be resumed).
  2957       executing; if it is suspended, it will be resumed).
  2953      If aProcess is nil, the block will be evaluated by the scheduler itself
  2958      If aProcess is nil, the block will be evaluated by the scheduler itself
  2954      (which is dangerous - the block should not raise any error conditions).
  2959      (which is dangerous - the block should not raise any error conditions).
  2955      The block will be removed from the timed-block list after evaluation
  2960      The block will be removed from the timed-block list after evaluation
  2956      (i.e. it will trigger only once).
  2961      (i.e. it will trigger only once).
  2957      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2962      Returns an ID, which can be used in #removeTimeoutWithID:"
  2958 
  2963 
  2959     ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds
  2964     ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds
  2960 
  2965 
  2961     "Modified: 23.9.1996 / 14:34:18 / cg"
  2966     "Modified: / 23-09-1996 / 14:34:18 / cg"
       
  2967     "Modified (comment): / 20-07-2017 / 16:43:26 / cg"
  2962 !
  2968 !
  2963 
  2969 
  2964 addTimedBlock:aBlock for:aProcess afterMilliseconds:delta
  2970 addTimedBlock:aBlock for:aProcess afterMilliseconds:delta
  2965     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2971     "add the argument, aBlock to the list of time-scheduled-blocks; to be
  2966      evaluated after delta milliseconds. The process specified by the argument,
  2972      evaluated after delta milliseconds. The process specified by the argument,
  2969       executing; if it is suspended, it will be resumed).
  2975       executing; if it is suspended, it will be resumed).
  2970      If aProcess is nil, the block will be evaluated by the scheduler itself
  2976      If aProcess is nil, the block will be evaluated by the scheduler itself
  2971      (which is dangerous - the block should not raise any error conditions).
  2977      (which is dangerous - the block should not raise any error conditions).
  2972      The block will be removed from the timed-block list after evaluation
  2978      The block will be removed from the timed-block list after evaluation
  2973      (i.e. it will trigger only once).
  2979      (i.e. it will trigger only once).
  2974      Returns an ID, which can be used in #removeTimeoutWidthID:"
  2980      Returns an ID, which can be used in #removeTimeoutWithID:"
  2975 
  2981 
  2976     |now then id|
  2982     |now then id|
  2977 
  2983 
  2978     now := OperatingSystem getMillisecondTime.
  2984     now := OperatingSystem getMillisecondTime.
  2979     then := OperatingSystem millisecondTimeAdd:now and:delta.
  2985     then := OperatingSystem millisecondTimeAdd:now and:delta.
  2980     id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then.
  2986     id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then.
  2981     ^ id
  2987     ^ id
  2982 
  2988 
  2983     "Modified: / 18-07-2017 / 14:04:31 / cg"
  2989     "Modified: / 18-07-2017 / 14:04:31 / cg"
       
  2990     "Modified (comment): / 20-07-2017 / 16:43:29 / cg"
  2984 !
  2991 !
  2985 
  2992 
  2986 addTimedBlock:aBlock for:aProcess afterSeconds:delta
  2993 addTimedBlock:aBlock for:aProcess afterSeconds:delta
  2987     "add the argument, aBlock to the list of time-scheduled-blocks.
  2994     "add the argument, aBlock to the list of time-scheduled-blocks.
  2988      to be evaluated after delta seconds. aProcess will be interrupted for
  2995      to be evaluated after delta seconds. aProcess will be interrupted for
  2991       executing; if it is suspended, it will be resumed).
  2998       executing; if it is suspended, it will be resumed).
  2992      If aProcess is nil, the block will be evaluated by the scheduler itself
  2999      If aProcess is nil, the block will be evaluated by the scheduler itself
  2993      (which is dangerous - the block should not raise any error conditions).
  3000      (which is dangerous - the block should not raise any error conditions).
  2994      The block will be removed from the timed-block list after evaluation
  3001      The block will be removed from the timed-block list after evaluation
  2995      (i.e. it will trigger only once).
  3002      (i.e. it will trigger only once).
  2996      Returns an ID, which can be used in #removeTimeoutWidthID:"
  3003      Returns an ID, which can be used in #removeTimeoutWithID:"
  2997 
  3004 
  2998     ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
  3005     ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
  2999 
  3006 
  3000     "Modified: 23.9.1996 / 14:34:18 / cg"
  3007     "Modified: / 23-09-1996 / 14:34:18 / cg"
       
  3008     "Modified (comment): / 20-07-2017 / 16:43:32 / cg"
  3001 !
  3009 !
  3002 
  3010 
  3003 addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime
  3011 addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime
  3004     "add the argument, aBlock to the list of time-scheduled-blocks; 
  3012     "add the argument, aBlock to the list of time-scheduled-blocks; 
  3005      to be evaluated by aProcess when the millisecondClock value passes
  3013      to be evaluated by aProcess when the millisecondClock value passes
  3012      If the process is active at trigger time, the interrupt will occur in
  3020      If the process is active at trigger time, the interrupt will occur in
  3013      whatever method it is executing; 
  3021      whatever method it is executing; 
  3014      if suspended at trigger time, it will be resumed.
  3022      if suspended at trigger time, it will be resumed.
  3015      The block will be removed from the timed-block list after evaluation
  3023      The block will be removed from the timed-block list after evaluation
  3016      (i.e. it will trigger only once).
  3024      (i.e. it will trigger only once).
  3017      Returns an ID, which can be used in #removeTimeoutWidthID:"
  3025      Returns an ID, which can be used in #removeTimeoutWithID:"
  3018 
  3026 
  3019     |index "{ Class: SmallInteger }"
  3027     |index "{ Class: SmallInteger }"
  3020      wasBlocked|
  3028      wasBlocked|
  3021 
  3029 
  3022     wasBlocked := OperatingSystem blockInterrupts.
  3030     wasBlocked := OperatingSystem blockInterrupts.
  3041 
  3049 
  3042     anyTimeouts := true.
  3050     anyTimeouts := true.
  3043     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  3051     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  3044     ^ index
  3052     ^ index
  3045 
  3053 
  3046     "Modified: 23.9.1996 / 14:34:23 / cg"
  3054     "Modified: / 23-09-1996 / 14:34:23 / cg"
       
  3055     "Modified (comment): / 20-07-2017 / 16:43:36 / cg"
  3047 !
  3056 !
  3048 
  3057 
  3049 addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
  3058 addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
  3050     "prepare for an external function to be called with a single argument
  3059     "prepare for an external function to be called with a single argument
  3051      after some millisecond-Delay.
  3060      after some millisecond-Delay.
  3052      If aProcess is nil, the block will be evaluated by the scheduler itself,
  3061      If aProcess is nil, the block will be evaluated by the scheduler itself,
  3053      otherwise, that process will be interrupted and the function is performed
  3062      otherwise, that process will be interrupted and the function is performed
  3054      in this processes context.
  3063      in this processes context.
  3055      The callBack will be removed from the timed-block list after evaluation
  3064      The callBack will be removed from the timed-block list after evaluation
  3056      (i.e. it will trigger only once).
  3065      (i.e. it will trigger only once).
  3057      Returns an ID, which can be used in #removeTimeoutWidthID:"
  3066      Returns an ID, which can be used in #removeTimeoutWithID:"
  3058 
  3067 
  3059     |now then wasBlocked id|
  3068     |now then wasBlocked id|
  3060 
  3069 
  3061     wasBlocked := OperatingSystem blockInterrupts.
  3070     wasBlocked := OperatingSystem blockInterrupts.
  3062     now := OperatingSystem getMillisecondTime.
  3071     now := OperatingSystem getMillisecondTime.
  3063     then := OperatingSystem millisecondTimeAdd:now and:delta.
  3072     then := OperatingSystem millisecondTimeAdd:now and:delta.
  3064 
  3073 
  3065     id := self
  3074     id := self
  3066 	addTimeoutFunctionCall:anExternalFunction
  3075         addTimeoutFunctionCall:anExternalFunction
  3067 	for:aProcess
  3076         for:aProcess
  3068 	atMilliseconds:then
  3077         atMilliseconds:then
  3069 	with:argument.
  3078         with:argument.
  3070 
  3079 
  3071     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  3080     wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
  3072     ^ id
  3081     ^ id
  3073 
  3082 
  3074     "Created: 23.9.1996 / 14:28:27 / cg"
  3083     "Created: / 23-09-1996 / 14:28:27 / cg"
  3075     "Modified: 23.9.1996 / 14:34:42 / cg"
  3084     "Modified (comment): / 20-07-2017 / 16:43:39 / cg"
  3076 !
  3085 !
  3077 
  3086 
  3078 addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument
  3087 addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument
  3079     "prepare for an external function to be called with a single argument
  3088     "prepare for an external function to be called with a single argument
  3080      at some millisecond-time.
  3089      at some millisecond-time.
  3081      If aProcess is nil, the block will be evaluated by the scheduler itself,
  3090      If aProcess is nil, the block will be evaluated by the scheduler itself,
  3082      otherwise, that process will be interrupted and the function is performed
  3091      otherwise, that process will be interrupted and the function is performed
  3083      in this processes context.
  3092      in this processes context.
  3084      The callBack will be removed from the timed-block list after evaluation
  3093      The callBack will be removed from the timed-block list after evaluation
  3085      (i.e. it will trigger only once).
  3094      (i.e. it will trigger only once).
  3086      Returns an ID, which can be used in #removeTimeoutWidthID:"
  3095      Returns an ID, which can be used in #removeTimeoutWithID:"
  3087 
  3096 
  3088     |action|
  3097     |action|
  3089 
  3098 
  3090     action := [anExternalFunction callWith:argument].
  3099     action := [anExternalFunction callWith:argument].
  3091     ^ self
  3100     ^ self
  3092 	addTimedBlock:action
  3101         addTimedBlock:action
  3093 	for:aProcess
  3102         for:aProcess
  3094 	atMilliseconds:milliTime.
  3103         atMilliseconds:milliTime.
  3095 
  3104 
  3096     "Created: 23.9.1996 / 14:29:30 / cg"
  3105     "Created: / 23-09-1996 / 14:29:30 / cg"
  3097     "Modified: 23.9.1996 / 14:34:57 / cg"
  3106     "Modified (comment): / 20-07-2017 / 16:43:42 / cg"
  3098 !
  3107 !
  3099 
  3108 
  3100 evaluateTimeouts
  3109 evaluateTimeouts
  3101     "walk through timeouts and evaluate blocks or signal semas that need to be .."
  3110     "walk through timeouts and evaluate blocks or signal semas that need to be .."
  3102 
  3111