#BUGFIX by stefan expecco_18_1_0_6496 expecco_18_1_0_6496_v2
authorStefan Vogel <sv@exept.de>
Wed, 01 Aug 2018 15:12:02 +0200
changeset 4708 713e81a051ec
parent 4707 e0b53a001864
child 4709 b26d6c21d910
#BUGFIX by stefan class: List removed: #synchronizationSemaphore: changed: #asSharedCollection #beSynchronized Do not make me implicitly #beSynchronized, if someone sends a #synchronized: message to myself.
List.st
--- a/List.st	Wed Aug 01 13:26:08 2018 +0200
+++ b/List.st	Wed Aug 01 15:12:02 2018 +0200
@@ -123,18 +123,6 @@
     ^ super synchronizationSemaphore.
 
     "Created: / 01-08-2018 / 13:22:45 / Claus Gittinger"
-!
-
-synchronizationSemaphore:aSemaphore
-    "set the synchronization semaphore for myself"
-
-    optionalAccessLock notNil ifTrue:[
-        Logger warning:'trying to change the snchronization semaphore'.
-        ^ self
-    ].    
-    optionalAccessLock := aSemaphore
-
-    "Created: / 01-08-2018 / 13:25:58 / Claus Gittinger"
 ! !
 
 !List methodsFor:'adding & removing'!
@@ -454,17 +442,17 @@
 !
 
 asSharedCollection
-    |newList|
-    
-    optionalAccessLock notNil ifTrue:[^ self].
+    optionalAccessLock notNil ifTrue:[
+        "I am alreay protected agains concurrent access"
+        ^ self
+    ].
     
-    self possiblySynchronized:[
-        newList := List withAll:self.
-        newList beSynchronized.
-    ].    
-    ^ newList
+    ^ (List withAll:self)
+            beSynchronized;
+            yourself.
 
     "Created: / 01-08-2018 / 11:54:26 / Claus Gittinger"
+    "Modified (format): / 01-08-2018 / 15:07:20 / Stefan Vogel"
 ! !
 
 !List methodsFor:'copying'!
@@ -685,11 +673,34 @@
 beSynchronized
     "make the receiver a synchronized List"
     
+    |wasBlocked|
+
     optionalAccessLock isNil ifTrue:[
-        optionalAccessLock := RecursionLock new
+        wasBlocked := OperatingSystem blockInterrupts.
+        optionalAccessLock isNil ifTrue:[
+            "already a registered synchronizationSemaphore for myself in Object? 
+             - then use it!!"
+            optionalAccessLock := SynchronizationSemaphores removeKey:self ifAbsent:[].
+            optionalAccessLock isNil ifTrue:[
+                optionalAccessLock := RecursionLock name:self className.
+            ].
+        ].
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
     ].
 
+    "
+        |list oldSema|
+
+        list := List new.
+        list synchronized:[list add:1].
+        oldSema := list synchronizationSemaphore.
+        list beSynchronized.
+        self assert:oldSema == list synchronizationSemaphore.
+        oldSema
+    "
+
     "Created: / 01-08-2018 / 11:44:37 / Claus Gittinger"
+    "Modified (comment): / 01-08-2018 / 15:10:45 / Stefan Vogel"
 ! !
 
 !List methodsFor:'testing'!