>From ef15f20cd3ea884b77a50f78b58047cac3a60891 Mon Sep 17 00:00:00 2001 From: Gwenael Casaccio Date: Mon, 31 Mar 2014 09:45:24 +0200 Subject: [PATCH 2/2] kernel: Make Object>>FinalizableObjects thread safe 2014-03-31 Gwenael Casaccio * kernel/Object.st: Make Object>>FinalizableObjects thread safe. --- ChangeLog | 4 ++++ kernel/Object.st | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 62ae7b3..7369612 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-03-31 Gwenael Casaccio + + * kernel/Object.st: Make Object>>FinalizableObjects thread safe. + 2014-03-30 Gwenael Casaccio * kernel/Process.st: Make Process>>queueInterrupt: atomic. diff --git a/kernel/Object.st b/kernel/Object.st index 3d18a2c..b5179ed 100644 --- a/kernel/Object.st +++ b/kernel/Object.st @@ -40,6 +40,7 @@ All classes in the system are subclasses of me.'> Dependencies := nil. FinalizableObjects := nil. + FinalSemaphore := nil. Object class >> update: aspect [ "Do any global tasks for the ObjectMemory events." @@ -64,6 +65,16 @@ All classes in the system are subclasses of me.'> Dependencies := anObject ] + Object class >> finalSemaphore [ + + + FinalSemaphore isNil ifFalse: [ ^FinalSemaphore ]. + ^ [ + FinalSemaphore isNil ifTrue: [ FinalSemaphore := Semaphore forMutualExclusion ]. + FinalSemaphore + ] valueWithoutPreemption + ] + Object class >> finalizableObjects [ "Answer a set of finalizable objects." @@ -346,12 +357,12 @@ All classes in the system are subclasses of me.'> collector finds out there are only weak references to it." - self class finalizableObjects add: ((HomedAssociation + self class finalSemaphore critical: [ self class finalizableObjects add: ((HomedAssociation key: self value: nil environment: FinalizableObjects) makeEphemeron; - yourself) + yourself) ] ] removeToBeFinalized [ @@ -359,11 +370,11 @@ All classes in the system are subclasses of me.'> when the garbage collector finds out there are only weak references to it." - self class finalizableObjects remove: (HomedAssociation + self class finalSemaphore critical: [ self class finalizableObjects remove: (HomedAssociation key: self value: nil environment: self class finalizableObjects) - ifAbsent: [] + ifAbsent: [] ] ] mourn [ -- 1.8.3.2