[squeak-dev] The Inbox: Collections-cmm.361.mcz

commits at source.squeak.org commits at source.squeak.org
Thu May 20 16:56:51 UTC 2010


A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-cmm.361.mcz

==================== Summary ====================

Name: Collections-cmm.361
Author: cmm
Time: 20 May 2010, 11:56:29.407 am
UUID: 1e07a98f-d8f8-41f7-8a37-7d3b125c5de5
Ancestors: Collections-cmm.360

- WeakFinalizationRegistry now protects itself from access by multiple Processes.

=============== Diff against Collections-cmm.360 ===============

Item was changed:
  ----- Method: WeakFinalizationRegistry>>keys (in category 'accessing') -----
  keys
+ 	^ self accessLock: [ valueDictionary keys ]!
- 
- 	^ valueDictionary keys!

Item was added:
+ ----- Method: WeakFinalizationRegistry>>accessLock: (in category 'private') -----
+ accessLock: aBlock
+ 	^ accessLock critical: aBlock!

Item was changed:
  ----- Method: WeakFinalizationRegistry>>do: (in category 'accessing') -----
+ do: aBlock 
+ 	^ accessLock critical: [ valueDictionary keysDo: aBlock ]!
- do: aBlock
- 	^ valueDictionary keysDo: aBlock
- !

Item was changed:
+ ----- Method: WeakFinalizationRegistry>>remove:ifAbsent: (in category 'private') -----
+ remove: oldObject ifAbsent: exceptionBlock 
- ----- Method: WeakFinalizationRegistry>>remove:ifAbsent: (in category 'accessing') -----
- remove: oldObject ifAbsent: exceptionBlock
  	"Remove oldObject as one of the receiver's elements."
+ 	^ self
+ 		accessLock: 
+ 			[ | value |
+ 			oldObject ifNil: [^ nil].
+ 			value := valueDictionary
+ 				removeKey: oldObject
+ 				ifAbsent: [^ exceptionBlock value].
+ 			value clear.
+ 			oldObject ]!
- 	| value |
- 	oldObject ifNil: [ ^nil ].
- 	
- 	value := valueDictionary removeKey: oldObject ifAbsent: [ ^ exceptionBlock value ].
- 	value clear.
- 	^ oldObject!

Item was changed:
  ----- Method: WeakFinalizationRegistry>>add:executor: (in category 'adding') -----
+ add: anObject executor: anExecutor 
+ 	^ self accessLock:
+ 		[ valueDictionary
+ 			at: anObject
+ 			put: 
+ 				(WeakFinalizerItem new
+ 					list: list
+ 					object: anObject
+ 					executor: anExecutor).
+ 		anObject ]!
- add: anObject executor: anExecutor
- 
- 	valueDictionary at: anObject put: 
- 		(WeakFinalizerItem new list: list object: anObject executor: anExecutor).
- 		
- 	^ anObject
- !

Item was changed:
  ----- Method: WeakFinalizationRegistry>>postCopy (in category 'copying') -----
  postCopy
  	"should we prohibit any attempts to copy receiver?"
  	| oldDict |
  	oldDict := valueDictionary.
  	list := WeakFinalizationList new.
  	valueDictionary := WeakIdentityKeyDictionary new.
+ 	self accessLock:		 
+ 		[ oldDict keysAndValuesDo: 
+ 			[ : key : value | valueDictionary
+ 				at: key
+ 				put: (value copyWithList: list) ] ].
+ 	self resetAccessLock!
- 	
- 	oldDict keysAndValuesDo: [:key :value |
- 		valueDictionary at: key put: (value copyWithList: list)
- 		]!

Item was changed:
  ----- Method: WeakFinalizationRegistry>>initialize (in category 'initialize-release') -----
  initialize
  	valueDictionary := WeakIdentityKeyDictionary new.
+ 	list ifNil: [ list := WeakFinalizationList new  ].
+ 	self resetAccessLock!
- 	list ifNil: [ list := WeakFinalizationList new  ].!

Item was added:
+ ----- Method: WeakFinalizationRegistry>>resetAccessLock (in category 'initialize-release') -----
+ resetAccessLock
+ 	accessLock := Mutex new!

Item was changed:
  Collection subclass: #WeakFinalizationRegistry
+ 	instanceVariableNames: 'list valueDictionary accessLock'
- 	instanceVariableNames: 'list valueDictionary'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Collections-Weak'!
  
  !WeakFinalizationRegistry commentStamp: 'Igor.Stasenko 3/8/2010 23:04' prior: 0!
  This kind of WeakRegistry using a new VM feature,
  which allows a more robust finalization support.
  
  In contrast to old implementation, it doesn't spending linear time , checking what elements became garbage.!




More information about the Squeak-dev mailing list