diff -r 20376737bdaf -r e8658d38abfb ProcessorScheduler.st --- a/ProcessorScheduler.st Sat May 06 06:26:35 1995 +0200 +++ b/ProcessorScheduler.st Mon May 08 05:31:14 1995 +0200 @@ -34,7 +34,7 @@ COPYRIGHT (c) 1993 by Claus Gittinger All Rights Reserved -$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.37 1995-05-04 12:48:05 claus Exp $ +$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.38 1995-05-08 03:30:32 claus Exp $ '! Smalltalk at:#Processor put:nil! @@ -57,7 +57,7 @@ version " -$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.37 1995-05-04 12:48:05 claus Exp $ +$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.38 1995-05-08 03:30:32 claus Exp $ " ! @@ -258,17 +258,20 @@ %} ! -threadCreate:aProcess +threadCreate:aProcess withId:id "physical creation of a process. (warning: low level entry, no administration done). - This may return nil, if a VM process could not be created." + This may raise an exception, if a VM process could not be created." %{ /* NOCONTEXT */ int tid; extern int __threadCreate(); - tid = __threadCreate(aProcess, 0 /* stackSize no longer needed */); - if (tid != 0) { + tid = __threadCreate(aProcess, + 0 /* stackSize: no longer needed */, + __isSmallInteger(id) ? _intVal(id) /* assign id */ + : -1 /* let VM assign one */ ); + if (tid) { RETURN ( _MKSMALLINT(tid)); } %} @@ -527,12 +530,15 @@ "how, exactly should this be done ?" p isRestartable == true ifTrue:[ + p nextLink:nil. processesToRestart add:p - ]. - p setId:nil state:#dead + ] ifFalse:[ + p setId:nil state:#dead + ] ]. scheduler setId:nil state:#dead ]. + scheduler setId:nil state:#dead. " now, start from scratch @@ -607,14 +613,30 @@ !ProcessorScheduler methodsFor:'process creation'! +newProcessFor:aProcess withId:idWant + "private entry for Process restart - do not use in your program" + + |id| + + (self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ + ^ false + ]. + + aProcess state:#light. "meaning: has no stack yet" + self remember:aProcess. + ^ true +! + newProcessFor:aProcess "create a physical (VM-) process for aProcess. Return true if ok, false if something went wrong. - The process is not scheduled; to start it running, it needs a Process>>resume." + The process is not scheduled; to start it running, + it needs a Process>>resume. Once resumed, the process will later + get control in its #start method." |id| - id := self class threadCreate:aProcess. + id := self class threadCreate:aProcess withId:nil. id isNil ifTrue:[^ false]. aProcess setId:id state:#light. "meaning: has no stack yet" @@ -693,7 +715,7 @@ ^ self ]. aProcess == scheduler ifTrue:[ - 'scheduler should never be suspended' printNL. + 'scheduler should never be suspended' errorPrintNL. MiniDebugger enterWithMessage:'scheduler should never be suspended'. ^ self ]. @@ -709,7 +731,7 @@ l isNil ifTrue:[ wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. - 'bad suspend: empty run list' printNL. + 'bad suspend: empty run list' errorPrintNL. "/ MiniDebugger enterWithMessage:'bad suspend: empty run list'. self threadSwitch:scheduler. ^ self @@ -720,7 +742,7 @@ " (l remove:aProcess ifAbsent:[]) isNil ifTrue:[ wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. - 'bad suspend: not on run list' printNL. + 'bad suspend: not on run list' errorPrintNL. "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'. self threadSwitch:scheduler. ^ self @@ -983,11 +1005,11 @@ highestPriorityRunnableProcess "return the highest prio runnable process" - |listArray l p maxPri "{ Class: SmallInteger }" | + |listArray l p prio "{ Class: SmallInteger }" | - maxPri := HighestPriority. + prio := HighestPriority. listArray := quiescentProcessLists. - maxPri to:1 by:-1 do:[:prio | + [prio >= 1] whileTrue:[ l := listArray at:prio. l notNil ifTrue:[ l isEmpty ifTrue:[ @@ -998,16 +1020,17 @@ ] ifFalse:[ p := l first. " - if it got corrupted somehow + if it got corrupted somehow ... " p id isNil ifTrue:[ - 'process with nil id removed' printNL. + 'process with nil id removed' errorPrintNL. l removeFirst. ^ nil. ]. ^ p ]. - ] + ]. + prio := prio - 1 ]. ^ nil !