Process.st
changeset 19860 324edacff5cc
parent 19751 4e212ebc3961
child 19863 513bd7237fe7
child 19969 654d2e1a2dc4
--- a/Process.st	Tue May 17 00:56:14 2016 +0200
+++ b/Process.st	Tue May 17 02:04:25 2016 +0200
@@ -42,7 +42,7 @@
 
 documentation
 "
-    WARNING: 
+    WARNING:
 	the offsets of the instance variables lookupActivations and lookupDisabled are known in the VM
 	do not remove them, and do not insert/remove instance variables before them
 
@@ -377,7 +377,7 @@
     "return the default max stack size. All new processes get
      this limit initially.
      It may be changed for individual processes with:
-        aProcess setMaximumStackSize:limit"
+	aProcess setMaximumStackSize:limit"
 
 %{  /* NOCONTEXT */
     extern INT __defaultThreadMaxStackSize();
@@ -396,16 +396,16 @@
     "set the default max stack size, return the previous value.
      All new processes get this stack limit initially.
      It may be changed for individual processes with:
-        aProcess setMaximumStackSize:limit
+	aProcess setMaximumStackSize:limit
      Notice:
-        There is seldom any need to change the default setting,
-        except for highly recursive programs."
+	There is seldom any need to change the default setting,
+	except for highly recursive programs."
 
 %{  /* NOCONTEXT */
     extern INT __threadSetDefaultMaxStackSize();
 
     if (__isSmallInteger(numberOfBytes)) {
-        RETURN ( __mkSmallInteger(__threadSetDefaultMaxStackSize(__intVal(numberOfBytes)) ));
+	RETURN ( __mkSmallInteger(__threadSetDefaultMaxStackSize(__intVal(numberOfBytes)) ));
     }
 %}
 
@@ -417,7 +417,7 @@
 !
 
 wrapStackSize
-    "return the wrap stack size. 
+    "return the wrap stack size.
      Under windows, blocking API calls are executed on a separate stack with this size.
      If you ever encounter that a call to n external library function requires more stack than
      this, you may change this size in your startup (or programmatically) during early startup.
@@ -426,7 +426,7 @@
 %{  /* NOCONTEXT */
     INT sz = 0;
 
-#ifdef WIN32
+#ifdef __win32__
     extern INT __getWrapStackSize();
 
     sz = __getWrapStackSize();
@@ -436,7 +436,7 @@
 !
 
 wrapStackSize:newSize
-    "set the wrap stack size. 
+    "set the wrap stack size.
      Under windows, blocking API calls are executed on a separate stack with this size.
      If you ever encounter that a call to n external library function requires more stack than
      this, you may change this size in your startup (or programmatically) during early startup.
@@ -447,15 +447,15 @@
     INT __oldSize = 0;
 
     if (__isSmallInteger(newSize)) {
-        INT __newSize = __intVal(newSize);
-
-        if (__newSize >= 0) {
-#ifdef WIN32
-            extern INT __setWrapStackSize(INT);
-
-            __oldSize = __setWrapStackSize(__newSize);
+	INT __newSize = __intVal(newSize);
+
+	if (__newSize >= 0) {
+#ifdef __win32__
+	    extern INT __setWrapStackSize(INT);
+
+	    __oldSize = __setWrapStackSize(__newSize);
 #endif
-        }
+	}
     }
     RETURN (__MKINT(__oldSize));
 %}
@@ -835,7 +835,7 @@
     OBJ i;
 
     if (__isSmallInteger(i = __INST(id))) {
-        RETURN( __MKINT(__threadMaxStackSize(__intVal(i))) );
+	RETURN( __MKINT(__threadMaxStackSize(__intVal(i))) );
     }
 %}.
     ^ nil
@@ -853,7 +853,7 @@
 
     if (__isSmallInteger(i = __INST(id))
      && __isSmallInteger(limit) ) {
-        RETURN ( __MKINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) );
+	RETURN ( __MKINT(__threadSetMaxStackSize(__intVal(i), __intVal(limit))) );
     }
 %}.
     ^ nil
@@ -872,7 +872,7 @@
      && __isSmallInteger(initial)
      && __isSmallInteger(increment)
      && __isSmallInteger(safe)) {
-        RETURN ( __threadSetJunkSizes(__intVal(i), __intVal(initial), __intVal(increment), __intVal(safe)) ? true : false );
+	RETURN ( __threadSetJunkSizes(__intVal(i), __intVal(initial), __intVal(increment), __intVal(safe)) ? true : false );
     }
 %}.
     ^ false
@@ -1077,9 +1077,9 @@
     OBJ i;
 
     if (__isSmallInteger(i = __INST(id))) {
-        n = __threadNumberOfStackBoundaryHits(__intVal(i));
-        n &= _MAX_INT;
-        RETURN( __mkSmallInteger(n) );
+	n = __threadNumberOfStackBoundaryHits(__intVal(i));
+	n &= _MAX_INT;
+	RETURN( __mkSmallInteger(n) );
     }
 %}.
     ^ nil
@@ -1094,7 +1094,7 @@
     OBJ i;
 
     if (__isSmallInteger(i = __INST(id))) {
-        RETURN( __mkSmallInteger((INT)__threadStackSegments(__intVal(i))) );
+	RETURN( __mkSmallInteger((INT)__threadStackSegments(__intVal(i))) );
     }
 %}.
     ^ nil
@@ -1109,7 +1109,7 @@
     OBJ i;
 
     if (__isSmallInteger(i = __INST(id))) {
-        RETURN( __MKINT(__threadTotalStackSize(__intVal(i))) );
+	RETURN( __MKINT(__threadTotalStackSize(__intVal(i))) );
     }
 %}.
     ^ nil
@@ -1124,7 +1124,7 @@
     OBJ i;
 
     if (__isSmallInteger(i = __INST(id))) {
-        RETURN( __MKINT(__threadUsedStackSize(__intVal(i))) );
+	RETURN( __MKINT(__threadUsedStackSize(__intVal(i))) );
     }
 %}.
     ^ nil
@@ -1814,22 +1814,22 @@
 
     suspendSemaphore notNil ifTrue:[suspendSemaphore signalForAll].
     suspendActions notNil ifTrue:[
-        |savedState|
-
-        savedState := state.
-        state := #aboutToSuspend.
-        suspendActions do:[:action | action value].
-        state ~~ #aboutToSuspend ifTrue:[
-            "/ mhmh - one of the suspendActions lead to making me active again;
-            "/ bail out.
-            "/ This fixes the Semaphore was signalled, but process did not run error,
-            "/ which can happen when a process with a suspend action goes into a readWait,
-            "/ and the suspend action does a thread switch, and the readWait semaphore gets
-            "/ signalled before we come back here. Then the semaphore wakeup will have already
-            "/ place me back into the run state, so I should not go into a suspend below.
-            ^ self.
-        ].
-        state := savedState.
+	|savedState|
+
+	savedState := state.
+	state := #aboutToSuspend.
+	suspendActions do:[:action | action value].
+	state ~~ #aboutToSuspend ifTrue:[
+	    "/ mhmh - one of the suspendActions lead to making me active again;
+	    "/ bail out.
+	    "/ This fixes the Semaphore was signalled, but process did not run error,
+	    "/ which can happen when a process with a suspend action goes into a readWait,
+	    "/ and the suspend action does a thread switch, and the readWait semaphore gets
+	    "/ signalled before we come back here. Then the semaphore wakeup will have already
+	    "/ place me back into the run state, so I should not go into a suspend below.
+	    ^ self.
+	].
+	state := savedState.
     ].
 
     "
@@ -1841,7 +1841,7 @@
     (state == #active
     or:[state == #run
     or:[aStateSymbol == #stopped]]) ifTrue:[
-        state := aStateSymbol.
+	state := aStateSymbol.
     ].
     Processor suspend:self
 !
@@ -1913,26 +1913,26 @@
       the receiver itself)."
 
     id isNil ifTrue:[
-        "/ problem:
-        "/ if receiver is already dead, its id is nil.
-        "/ children are found by looking for processes with a parentID identical to
-        "/ mine - ifNil, system processes are found, which is probably not what you
-        "/ want ...
-        "/ FIX: remember the id (or dont nil it when terminating)
-        "/ requires VM changes.
-        ProcessorScheduler invalidProcessSignal
-            raiseRequestWith:self
-            errorString:'process is already dead - cannot determine child processes'.
-        ^ self
+	"/ problem:
+	"/ if receiver is already dead, its id is nil.
+	"/ children are found by looking for processes with a parentID identical to
+	"/ mine - ifNil, system processes are found, which is probably not what you
+	"/ want ...
+	"/ FIX: remember the id (or dont nil it when terminating)
+	"/ requires VM changes.
+	ProcessorScheduler invalidProcessSignal
+	    raiseRequestWith:self
+	    errorString:'process is already dead - cannot determine child processes'.
+	^ self
     ].
     ProcessorScheduler knownProcesses do:[:aProcess |
-        aProcess ~~ self ifTrue:[
-            aProcess creatorId == id ifTrue:[
-                aProcess isGUIProcess ifTrue:[
-                    aProcess terminateWithAllGUISubprocesses
-                ]
-            ]
-        ]
+	aProcess ~~ self ifTrue:[
+	    aProcess creatorId == id ifTrue:[
+		aProcess isGUIProcess ifTrue:[
+		    aProcess terminateWithAllGUISubprocesses
+		]
+	    ]
+	]
     ].
 
     "Created: / 28-10-1996 / 20:43:32 / cg"
@@ -1946,17 +1946,17 @@
       and recursively oll of their group processes.)."
 
     id isNil ifTrue:[
-        "/ problem:
-        "/ if receiver is already dead, its id is nil.
-        "/ children are found by looking for processes with a parentID identical to
-        "/ mine - ifNil, system processes are found, which is probably not what you
-        "/ want ...
-        "/ FIX: remember the id (or dont nil it when terminating)
-        "/ requires VM changes.
-        ProcessorScheduler invalidProcessSignal
-            raiseRequestWith:self
-            errorString:'process is already dead - cannot determine child processes'.
-        ^ self
+	"/ problem:
+	"/ if receiver is already dead, its id is nil.
+	"/ children are found by looking for processes with a parentID identical to
+	"/ mine - ifNil, system processes are found, which is probably not what you
+	"/ want ...
+	"/ FIX: remember the id (or dont nil it when terminating)
+	"/ requires VM changes.
+	ProcessorScheduler invalidProcessSignal
+	    raiseRequestWith:self
+	    errorString:'process is already dead - cannot determine child processes'.
+	^ self
     ].
     self terminateAllSubprocessesInGroup:id
 !
@@ -1968,11 +1968,11 @@
       and recursively oll of their group processes.)."
 
     ProcessorScheduler knownProcesses do:[:aProcess |
-        aProcess ~~ self ifTrue:[
-            (aProcess processGroupId == aGroup) ifTrue:[
-                aProcess terminateWithAllSubprocessesInGroup
-            ]
-        ]
+	aProcess ~~ self ifTrue:[
+	    (aProcess processGroupId == aGroup) ifTrue:[
+		aProcess terminateWithAllSubprocessesInGroup
+	    ]
+	]
     ].
 
     "Created: / 28.10.1996 / 20:43:32 / cg"
@@ -1984,24 +1984,24 @@
      that are in the receiver's process group."
 
     id isNil ifTrue:[
-        "/ problem:
-        "/ if receiver is already dead, its id is nil.
-        "/ children are found by looking for processes with a parentID identical to
-        "/ mine - ifNil, system processes are found, which is probably not what you
-        "/ want ...
-        "/ FIX: remember the id (or dont nil it when terminating)
-        "/ requires VM changes.
-        ProcessorScheduler invalidProcessSignal
-            raiseRequestWith:self
-            errorString:'process is already dead - cannot determine child processes'.
-        ^ self
+	"/ problem:
+	"/ if receiver is already dead, its id is nil.
+	"/ children are found by looking for processes with a parentID identical to
+	"/ mine - ifNil, system processes are found, which is probably not what you
+	"/ want ...
+	"/ FIX: remember the id (or dont nil it when terminating)
+	"/ requires VM changes.
+	ProcessorScheduler invalidProcessSignal
+	    raiseRequestWith:self
+	    errorString:'process is already dead - cannot determine child processes'.
+	^ self
     ].
     ProcessorScheduler knownProcesses do:[:aProcess |
-        aProcess ~~ self ifTrue:[
-            aProcess processGroupId == id ifTrue:[
-                aProcess terminate
-            ]
-        ]
+	aProcess ~~ self ifTrue:[
+	    aProcess processGroupId == id ifTrue:[
+		aProcess terminate
+	    ]
+	]
     ].
     self terminate
 !
@@ -2041,29 +2041,29 @@
       the receiver itself)."
 
     id isNil ifTrue:[
-        "/ problem:
-        "/ if receiver is already dead, its id is nil.
-        "/ children are found by looking for processes with a parentID identical to
-        "/ mine - ifNil, system processes are found, which is probably not what you
-        "/ want ...
-        "/ FIX: remember the id (or dont nil it when terminating)
-        "/ requires VM changes.
-        ProcessorScheduler invalidProcessSignal
-            raiseRequestWith:self
-            errorString:'process is already dead - cannot determine child processes'.
-        ^ self
+	"/ problem:
+	"/ if receiver is already dead, its id is nil.
+	"/ children are found by looking for processes with a parentID identical to
+	"/ mine - ifNil, system processes are found, which is probably not what you
+	"/ want ...
+	"/ FIX: remember the id (or dont nil it when terminating)
+	"/ requires VM changes.
+	ProcessorScheduler invalidProcessSignal
+	    raiseRequestWith:self
+	    errorString:'process is already dead - cannot determine child processes'.
+	^ self
     ].
     processGroupId == 0 ifTrue:[
-        ProcessorScheduler invalidProcessSignal
-            raiseWith:self errorString:'trying to terminate the system process group'.
+	ProcessorScheduler invalidProcessSignal
+	    raiseWith:self errorString:'trying to terminate the system process group'.
     ].
     ProcessorScheduler knownProcesses do:[:aProcess |
-        aProcess ~~ self ifTrue:[
-            (aProcess processGroupId == processGroupId
-            or:[aProcess processGroupId == id]) ifTrue:[
-                aProcess terminate
-            ]
-        ]
+	aProcess ~~ self ifTrue:[
+	    (aProcess processGroupId == processGroupId
+	    or:[aProcess processGroupId == id]) ifTrue:[
+		aProcess terminate
+	    ]
+	]
     ].
 
     "Created: 28.10.1996 / 20:41:49 / cg"
@@ -2145,7 +2145,7 @@
     ^ aValue
 !
 
-environmentIncludesKey:aKey 
+environmentIncludesKey:aKey
     "true if there is a thread local variable, false if no such variable exists"
 
     environment isNil ifTrue:[^ false].
@@ -2156,23 +2156,23 @@
     "the processes stderr.
      By default, this is Stderr, but it can be overwritten
      (for example to redirect a thread's error output to some other place"
-     
+
     ^ self environmentAt:#Stderr ifAbsent:Stderr
 
     "
      Processor activeProcess stdout
     "
-    
+
     "
      |out sema|
-     
+
      out := WriteStream on:''.
      sema := Semaphore new.
      [
-        Processor activeProcess environmentAt:#Stdout put:out.
-        'hello world' printCR.
-        sema signal.
-     ] fork. 
+	Processor activeProcess environmentAt:#Stdout put:out.
+	'hello world' printCR.
+	sema signal.
+     ] fork.
      sema wait.
      Transcript showCR:('output was: ''',out contents,'''').
     "
@@ -2182,7 +2182,7 @@
     "the processes stdin.
      By default, this is Stdin, but it can be overwritten
      (for example to redirect a thread's input from some other place"
-     
+
     ^ self environmentAt:#Stdin ifAbsent:Stdin
 !
 
@@ -2190,7 +2190,7 @@
     "the processes stdout.
      By default, this is Stdout, but it can be overwritten
      (for example to redirect a thread's output to some other place"
-     
+
     ^ self environmentAt:#Stdout ifAbsent:Stdout
 !
 
@@ -2208,7 +2208,7 @@
     "the processes transcript.
      By default, this is Transcript, but it can be overwritten
      (for example to redirect a thread's output to some other place"
-     
+
     ^ self environmentAt:#Transcript ifAbsent:[Transcript]
 !
 
@@ -2221,10 +2221,10 @@
     oldEnv := environment.
 
     [
-        environment := aDictionary.
-        result := aBlock value.
+	environment := aDictionary.
+	result := aBlock value.
     ] ensure:[
-        environment := oldEnv.
+	environment := oldEnv.
     ].
     ^ result
 !