﻿'From Squeak6.0rc1 of 1 July 2022 [latest update: #22088] on 4 July 2022 at 2:46:35 pm'!

!MorphicProject methodsFor: 'active process' stamp: 'jar 7/4/2022 14:33'!
spawnNewProcess

	uiProcess := [
		[world doOneCycle. uiProcess isActiveProcess ifFalse: [Processor terminateActive]. Processor yield] repeat.
	] newProcess priority: Processor userSchedulingPriority.
	uiProcess resume! !

!MorphicProject methodsFor: 'active process' stamp: 'jar 7/4/2022 14:10'!
spawnNewProcessIfThisIsUI: suspendedProcess
	"Initialize a UI process if needed. Answer true if suspendedProcess was interrupted
	from a UI process."
	self uiProcess == suspendedProcess ifTrue: [
		self spawnNewProcess.
		^true
	].

	"Ensure that the UI process is running."
	self uiProcess
		ifNil: [self spawnNewProcess]
		ifNotNil: [:uip |
			uip isSuspended ifTrue: [
				self restoreDisplay.
				self uiProcess resume].
			uip isBlocked ifTrue: [
				"UI cannot respond because it is waiting on a semaphore. To keep
				the system responsive, start a new UI process and let the current one
				finish its last cycle and terminate... see MorphicProject >> #spawnNewProcess"
				self flag: #discuss. "mt: How can we now that that #isBlocked state
				will not resolve itself soon? Can we? Hmm... see WorldState >> #interCyclePause:
				jar: Do we need to care? Would it be ok to start a new UI regardless of whether 
				the UI is blocked on a custom semaphore or an intercycle delay?"
				self spawnNewProcess]].

	^false		"no new process was created"
! !

