Process.st
changeset 25244 6df56799dd3e
parent 25222 2140d86c8d42
equal deleted inserted replaced
25243:bbe58e262b5a 25244:6df56799dd3e
   642     "change my dynamic priority range"
   642     "change my dynamic priority range"
   643 
   643 
   644     |lowPri hiPri newPrio|
   644     |lowPri hiPri newPrio|
   645 
   645 
   646     priorityRange := anInterval.
   646     priorityRange := anInterval.
   647     anInterval notNil ifTrue:[
   647     anInterval isNil ifTrue:[
   648 	lowPri := priorityRange start.
   648         ^ self.
   649 	hiPri := priorityRange stop.
   649     ].
   650 	(newPrio := prio) isNil ifTrue:[
   650     
   651 	    newPrio := lowPri
   651     lowPri := priorityRange start.
   652 	] ifFalse:[
   652     hiPri := priorityRange stop.
   653 	    prio < lowPri ifTrue:[
   653     (newPrio := prio) isNil ifTrue:[
   654 		newPrio := lowPri
   654         newPrio := lowPri
   655 	    ] ifFalse:[
   655     ] ifFalse:[
   656 		prio > hiPri ifTrue:[
   656         prio < lowPri ifTrue:[
   657 		    newPrio := hiPri
   657             newPrio := lowPri
   658 		].
   658         ] ifFalse:[
   659 	    ].
   659             prio > hiPri ifTrue:[
   660 	].
   660                 newPrio := hiPri
   661 	newPrio ~~ prio ifTrue:[
   661             ].
   662 	    self priority:newPrio
   662         ].
   663 	]
   663     ].
   664     ].
   664     newPrio ~~ prio ifTrue:[
   665 
   665         self priority:newPrio
   666     "Modified: / 3.8.1998 / 22:56:05 / cg"
   666     ]
       
   667 
       
   668     "Modified: / 03-08-1998 / 22:56:05 / cg"
       
   669     "Modified: / 05-02-2020 / 16:33:30 / Stefan Vogel"
   667 !
   670 !
   668 
   671 
   669 processGroupId
   672 processGroupId
   670     "return the processes processGroup id.
   673     "return the processes processGroup id.
   671      Normally, when created, a processes creator id is taken and used
   674      Normally, when created, a processes creator id is taken and used
  2266 	ifAbsent:[
  2269 	ifAbsent:[
  2267 	    self errorKeyNotFound:aKey.
  2270 	    self errorKeyNotFound:aKey.
  2268 	]
  2271 	]
  2269 !
  2272 !
  2270 
  2273 
  2271 environmentAt:aKey ifAbsent:defaultValue
  2274 environmentAt:aKey ifAbsent:aBlock
  2272     "return the value of a thread local variable, or the value of defaultValue if no such variable exists"
  2275     "return the value of a thread local variable, or the value of defaultValue if no such variable exists"
  2273 
  2276 
  2274     |val|
  2277     environment isNil ifTrue:[
  2275 
  2278         ^ aBlock value
  2276     environment isNil ifTrue:[^ defaultValue value].
  2279     ].
  2277     val := environment at:aKey ifAbsent:[^ defaultValue value].
  2280     ^ environment at:aKey ifAbsent:aBlock.
  2278     ^ val value.
  2281 
       
  2282     "Modified: / 05-02-2020 / 16:51:35 / Stefan Vogel"
  2279 !
  2283 !
  2280 
  2284 
  2281 environmentAt:aKey put:aValue
  2285 environmentAt:aKey put:aValue
  2282     "set the value of a thread local variable. Returns aValue"
  2286     "set the value of a thread local variable. Returns aValue"
  2283 
  2287 
  2284     |var|
       
  2285 
       
  2286     environment isNil ifTrue:[
  2288     environment isNil ifTrue:[
  2287         environment := IdentityDictionary new
  2289         environment := IdentityDictionary new
  2288     ].
  2290     ].
  2289     var := environment at:aKey ifAbsentPut:[ValueHolder new].
  2291     ^ environment at:aKey put:aValue.
  2290     var value:aValue.
  2292 
  2291     ^ aValue
  2293     "Modified: / 05-02-2020 / 16:52:33 / Stefan Vogel"
  2292 !
  2294 !
  2293 
  2295 
  2294 environmentIncludesKey:aKey
  2296 environmentIncludesKey:aKey
  2295     "true if there is a thread local variable, false if no such variable exists"
  2297     "true if there is a thread local variable, false if no such variable exists"
  2296 
  2298 
  2353 transcript
  2355 transcript
  2354     "the processes transcript.
  2356     "the processes transcript.
  2355      By default, this is Transcript, but it can be overwritten
  2357      By default, this is Transcript, but it can be overwritten
  2356      (for example to redirect a thread's output to some other place"
  2358      (for example to redirect a thread's output to some other place"
  2357 
  2359 
  2358     ^ self environmentAt:#Transcript ifAbsent:[Transcript]
  2360     ^ self environmentAt:#Transcript ifAbsent:Transcript.
       
  2361 
       
  2362     "Modified: / 05-02-2020 / 17:11:14 / Stefan Vogel"
  2359 !
  2363 !
  2360 
  2364 
  2361 withThreadLocalVariables:aDictionary do:aBlock
  2365 withThreadLocalVariables:aDictionary do:aBlock
  2362     "evaluate a block with threadLocalVariables from aDictionary;
  2366     "evaluate a block with threadLocalVariables from aDictionary;
  2363      restore the old bindings afterwards."
  2367      restore the old bindings afterwards."
  2364 
  2368 
  2365     |oldEnv result|
  2369     |oldEnv|
  2366 
  2370 
  2367     oldEnv := environment.
  2371     oldEnv := environment.
  2368 
  2372     environment := aDictionary.
  2369     [
  2373 
  2370 	environment := aDictionary.
  2374     ^ aBlock ensure:[
  2371 	result := aBlock value.
  2375         environment := oldEnv.
  2372     ] ensure:[
  2376     ].
  2373 	environment := oldEnv.
  2377 
  2374     ].
  2378     "Modified: / 05-02-2020 / 16:29:08 / Stefan Vogel"
  2375     ^ result
       
  2376 !
  2379 !
  2377 
  2380 
  2378 withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock
  2381 withThreadVariable:variableNameSymbol boundTo:aValue do:aBlock
  2379     "evaluate a block with the threadLocalVariable being bound to aValue;
  2382     "evaluate a block with the threadLocalVariable being bound to aValue;
  2380      undo the variable binding afterwards."
  2383      undo the variable binding afterwards."
  2381 
  2384 
  2382     |var oldValue|
  2385     |oldValue|
  2383 
  2386 
  2384     environment isNil ifTrue:[
  2387     environment isNil ifTrue:[
  2385         environment := IdentityDictionary new
  2388         environment := IdentityDictionary new
  2386     ].
  2389     ].
  2387     var := environment at:variableNameSymbol ifAbsent:nil.
  2390     oldValue := environment at:variableNameSymbol ifAbsent:Void.
  2388     var isNil ifTrue:[
  2391     environment at:variableNameSymbol put:aValue.
  2389         var := ValueHolder new.
  2392     
  2390         environment at:variableNameSymbol put:var.
  2393     ^ aBlock ensure:[
  2391     ].
  2394         oldValue == Void
  2392 
       
  2393     oldValue := var value.
       
  2394     ^ [
       
  2395         var value:aValue.
       
  2396         aBlock value.
       
  2397     ] ensure:[
       
  2398         oldValue isNil
       
  2399             ifTrue:[ environment removeKey:variableNameSymbol]
  2395             ifTrue:[ environment removeKey:variableNameSymbol]
  2400             ifFalse:[ var value:oldValue ]
  2396             ifFalse:[ environment at:variableNameSymbol put:oldValue ]
  2401     ].
  2397     ].
  2402 
  2398 
  2403     "
  2399     "
  2404      |printIt|
  2400      |printIt|
  2405 
  2401 
  2421                     printIt value
  2417                     printIt value
  2422                 ].
  2418                 ].
  2423             ]
  2419             ]
  2424     "
  2420     "
  2425 
  2421 
  2426     "Modified: / 05-06-2018 / 16:41:11 / Stefan Vogel"
  2422     "Modified: / 05-02-2020 / 16:50:19 / Stefan Vogel"
  2427 ! !
  2423 ! !
  2428 
  2424 
  2429 !Process class methodsFor:'documentation'!
  2425 !Process class methodsFor:'documentation'!
  2430 
  2426 
  2431 version
  2427 version