List.st
changeset 4708 713e81a051ec
parent 4707 e0b53a001864
child 4793 435cf45a47eb
equal deleted inserted replaced
4707:e0b53a001864 4708:713e81a051ec
   121         ^ optionalAccessLock
   121         ^ optionalAccessLock
   122     ].
   122     ].
   123     ^ super synchronizationSemaphore.
   123     ^ super synchronizationSemaphore.
   124 
   124 
   125     "Created: / 01-08-2018 / 13:22:45 / Claus Gittinger"
   125     "Created: / 01-08-2018 / 13:22:45 / Claus Gittinger"
   126 !
       
   127 
       
   128 synchronizationSemaphore:aSemaphore
       
   129     "set the synchronization semaphore for myself"
       
   130 
       
   131     optionalAccessLock notNil ifTrue:[
       
   132         Logger warning:'trying to change the snchronization semaphore'.
       
   133         ^ self
       
   134     ].    
       
   135     optionalAccessLock := aSemaphore
       
   136 
       
   137     "Created: / 01-08-2018 / 13:25:58 / Claus Gittinger"
       
   138 ! !
   126 ! !
   139 
   127 
   140 !List methodsFor:'adding & removing'!
   128 !List methodsFor:'adding & removing'!
   141 
   129 
   142 add:anObject
   130 add:anObject
   452 
   440 
   453     "Created: 14.2.1997 / 16:25:55 / cg"
   441     "Created: 14.2.1997 / 16:25:55 / cg"
   454 !
   442 !
   455 
   443 
   456 asSharedCollection
   444 asSharedCollection
   457     |newList|
   445     optionalAccessLock notNil ifTrue:[
       
   446         "I am alreay protected agains concurrent access"
       
   447         ^ self
       
   448     ].
   458     
   449     
   459     optionalAccessLock notNil ifTrue:[^ self].
   450     ^ (List withAll:self)
   460     
   451             beSynchronized;
   461     self possiblySynchronized:[
   452             yourself.
   462         newList := List withAll:self.
       
   463         newList beSynchronized.
       
   464     ].    
       
   465     ^ newList
       
   466 
   453 
   467     "Created: / 01-08-2018 / 11:54:26 / Claus Gittinger"
   454     "Created: / 01-08-2018 / 11:54:26 / Claus Gittinger"
       
   455     "Modified (format): / 01-08-2018 / 15:07:20 / Stefan Vogel"
   468 ! !
   456 ! !
   469 
   457 
   470 !List methodsFor:'copying'!
   458 !List methodsFor:'copying'!
   471 
   459 
   472 skipInstvarIndexInDeepCopy:index
   460 skipInstvarIndexInDeepCopy:index
   683 !List methodsFor:'setup'!
   671 !List methodsFor:'setup'!
   684 
   672 
   685 beSynchronized
   673 beSynchronized
   686     "make the receiver a synchronized List"
   674     "make the receiver a synchronized List"
   687     
   675     
       
   676     |wasBlocked|
       
   677 
   688     optionalAccessLock isNil ifTrue:[
   678     optionalAccessLock isNil ifTrue:[
   689         optionalAccessLock := RecursionLock new
   679         wasBlocked := OperatingSystem blockInterrupts.
   690     ].
   680         optionalAccessLock isNil ifTrue:[
       
   681             "already a registered synchronizationSemaphore for myself in Object? 
       
   682              - then use it!!"
       
   683             optionalAccessLock := SynchronizationSemaphores removeKey:self ifAbsent:[].
       
   684             optionalAccessLock isNil ifTrue:[
       
   685                 optionalAccessLock := RecursionLock name:self className.
       
   686             ].
       
   687         ].
       
   688         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
       
   689     ].
       
   690 
       
   691     "
       
   692         |list oldSema|
       
   693 
       
   694         list := List new.
       
   695         list synchronized:[list add:1].
       
   696         oldSema := list synchronizationSemaphore.
       
   697         list beSynchronized.
       
   698         self assert:oldSema == list synchronizationSemaphore.
       
   699         oldSema
       
   700     "
   691 
   701 
   692     "Created: / 01-08-2018 / 11:44:37 / Claus Gittinger"
   702     "Created: / 01-08-2018 / 11:44:37 / Claus Gittinger"
       
   703     "Modified (comment): / 01-08-2018 / 15:10:45 / Stefan Vogel"
   693 ! !
   704 ! !
   694 
   705 
   695 !List methodsFor:'testing'!
   706 !List methodsFor:'testing'!
   696 
   707 
   697 isList
   708 isList