Skip to content

Commit

Permalink
[feenkcom/gtoolkit#3771] lazy initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
akgrant43 committed May 15, 2024
1 parent 71629a8 commit 5c023dc
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/GToolkit-Utility-System/WeakArray.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WeakArray class >> gtSummaryFor: aView [
title: 'Summary';
priority: 10;
items: [ {
'FinalizationProcess' -> (FinalizationProcess isNotNil and: [ FinalizationProcess isTerminated not ]).
'FinalizationProcess' -> FinalizationProcess.
'FinalizationSemaphore' -> FinalizationSemaphore size.
'MournLoopProcess' -> MournLoopProcess.
'StopRequested' -> StopRequested.
Expand All @@ -44,22 +44,6 @@ WeakArray class >> gtSummaryFor: aView [
actionUpdateButton.
]

{ #category : #'*GToolkit-Utility-System' }
WeakArray class >> initialize [
"Do we need to initialize specialObjectsArray?"
<gtPharoPatch: #Pharo11>

Smalltalk specialObjectsArray size < 42
ifTrue: [Smalltalk recreateSpecialObjectsArray].

SessionManager default
registerSystemClassNamed: self name.

FinalizationSemaphore := Smalltalk specialObjectsArray at: 42.
StopRequested := false.
StoppedSemaphore := Semaphore new.
]

{ #category : #'*GToolkit-Utility-System' }
WeakArray class >> mournLoopWith: firstMourner [
"Send mourn to all the objects available in the mourn queue, starting
Expand All @@ -70,8 +54,8 @@ WeakArray class >> mournLoopWith: firstMourner [
<gtPharoPatch: #Pharo11>
| mourner |
mourner := firstMourner.
[ StopRequested ifTrue:
[ StoppedSemaphore signal.
[ self stopRequested ifTrue:
[ self stoppedSemaphore signal.
MournLoopProcess := nil.
^ self ].
mourner mourn.
Expand All @@ -88,8 +72,6 @@ WeakArray class >> restartFinalizationProcess [

FinalizationSemaphore := Smalltalk specialObjectsArray at: 42.
StopRequested := false.
StoppedSemaphore ifNil:
[ StoppedSemaphore := Semaphore new ].
FinalizationProcess := [self finalizationProcess]
forkAt: Processor userInterruptPriority.
FinalizationProcess name: 'WeakArray Finalization Process'
Expand Down Expand Up @@ -119,8 +101,20 @@ WeakArray class >> stopFinalizationProcess [

(MournLoopProcess isNil or: [ MournLoopProcess isTerminated ])
ifTrue: [ ^ self ].
self assert: StoppedSemaphore isSignaled not.
self assert: self stoppedSemaphore isSignaled not.
StopRequested := true.
StoppedSemaphore wait.

]

{ #category : #'*GToolkit-Utility-System' }
WeakArray class >> stopRequested [

^ StopRequested ifNil: [ false ]
]

{ #category : #'*GToolkit-Utility-System' }
WeakArray class >> stoppedSemaphore [

^ StoppedSemaphore ifNil: [ StoppedSemaphore := Semaphore new ]
]

0 comments on commit 5c023dc

Please sign in to comment.