Registry.st
branchjv
changeset 18800 02724cc719b6
parent 18630 a74d669db937
parent 18791 21a7db893c0e
child 20079 8d884971c2ed
equal deleted inserted replaced
18786:237a87b4fe8f 18800:02724cc719b6
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
    13 
    15 
    14 Object subclass:#Registry
    16 Object subclass:#Registry
    15 	instanceVariableNames:'registeredObjects handleArray tally indexTable'
    17 	instanceVariableNames:'registeredObjects handleArray tally indexTable'
    16 	classVariableNames:''
    18 	classVariableNames:''
    17 	poolDictionaries:''
    19 	poolDictionaries:''
   274 
   276 
   275 !Registry methodsFor:'queries'!
   277 !Registry methodsFor:'queries'!
   276 
   278 
   277 isEmpty
   279 isEmpty
   278     ^ tally == 0
   280     ^ tally == 0
       
   281 !
       
   282 
       
   283 size
       
   284     "answer the number of entries in the registry"
       
   285 
       
   286     tally isNil ifTrue:[
       
   287 	^ 0.
       
   288     ].
       
   289     ^ tally
   279 ! !
   290 ! !
   280 
   291 
   281 !Registry methodsFor:'registering objects'!
   292 !Registry methodsFor:'registering objects'!
   282 
   293 
   283 register:anObject
   294 register:anObject
   452      anObject (i.e. it no longer holds external resources)."
   463      anObject (i.e. it no longer holds external resources)."
   453 
   464 
   454     |index wasBlocked|
   465     |index wasBlocked|
   455 
   466 
   456     registeredObjects notNil ifTrue:[
   467     registeredObjects notNil ifTrue:[
   457 	wasBlocked := OperatingSystem blockInterrupts.
   468         wasBlocked := OperatingSystem blockInterrupts.
   458 	"/ index := registeredObjects identityIndexOf:anObject ifAbsent:0.
   469         "/ index := registeredObjects identityIndexOf:anObject ifAbsent:0.
   459 	index := indexTable at:anObject ifAbsent:0.
   470         index := indexTable at:anObject ifAbsent:0.
   460 	index ~~ 0 ifTrue:[
   471         index ~~ 0 ifTrue:[
   461 	    self unregister:anObject atIndex:index.
   472             self unregister:anObject atIndex:index.
   462 	].
   473             self resize.
   463 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   474         ].
   464 
   475         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   465 	self resize
       
   466     ]
   476     ]
   467 
   477 
   468     "Modified: 16.1.1997 / 18:08:42 / cg"
   478     "Modified: 16.1.1997 / 18:08:42 / cg"
   469 !
   479 !
   470 
   480 
   476 
   486 
   477     |n "{ Class: SmallInteger }"
   487     |n "{ Class: SmallInteger }"
   478      obj wasBlocked any|
   488      obj wasBlocked any|
   479 
   489 
   480     registeredObjects notNil ifTrue:[
   490     registeredObjects notNil ifTrue:[
   481 	any := false.
   491         any := false.
   482 	wasBlocked := OperatingSystem blockInterrupts.
   492         wasBlocked := OperatingSystem blockInterrupts.
   483 	n := registeredObjects size.
   493         n := registeredObjects size.
   484 
   494 
   485 	1 to:n do:[:index |
   495         1 to:n do:[:index |
   486 	    obj := registeredObjects at:index.
   496             obj := registeredObjects at:index.
   487 	    (obj notNil and:[obj class ~~ SmallInteger]) ifTrue:[
   497             (obj notNil and:[obj class ~~ SmallInteger]) ifTrue:[
   488 		(aBlock value:obj) ifTrue:[
   498                 (aBlock value:obj) ifTrue:[
   489 		    self unregister:obj atIndex:index.
   499                     self unregister:obj atIndex:index.
   490 		    any := true.
   500                     any := true.
   491 		]
   501                 ]
   492 	    ]
   502             ]
   493 	].
   503         ].
   494 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   504         any ifTrue:[ self resize ].
   495 	any ifTrue:[ self resize ]
   505         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   496     ]
   506     ]
   497 
   507 
   498     "Created: 16.1.1997 / 16:39:18 / cg"
   508     "Created: 16.1.1997 / 16:39:18 / cg"
   499     "Modified: 16.1.1997 / 18:08:47 / cg"
   509     "Modified: 16.1.1997 / 18:08:47 / cg"
   500 !
   510 !
   502 unregisterAllForWhichHandle:aBlock
   512 unregisterAllForWhichHandle:aBlock
   503     |n "{ Class: SmallInteger }"
   513     |n "{ Class: SmallInteger }"
   504      obj handle wasBlocked any|
   514      obj handle wasBlocked any|
   505 
   515 
   506     registeredObjects notNil ifTrue:[
   516     registeredObjects notNil ifTrue:[
   507 	any := false.
   517         any := false.
   508 	wasBlocked := OperatingSystem blockInterrupts.
   518         wasBlocked := OperatingSystem blockInterrupts.
   509 	n := registeredObjects size.
   519         n := registeredObjects size.
   510 
   520 
   511 	1 to:n do:[:index |
   521         1 to:n do:[:index |
   512 	    obj := registeredObjects at:index.
   522             obj := registeredObjects at:index.
   513 	    handle := handleArray at:index.
   523             handle := handleArray at:index.
   514 	    handle notNil ifTrue:[
   524             handle notNil ifTrue:[
   515 		(aBlock value:handle) ifTrue:[
   525                 (aBlock value:handle) ifTrue:[
   516 		    self unregister:obj atIndex:index.
   526                     self unregister:obj atIndex:index.
   517 		    any := true.
   527                     any := true.
   518 		]
   528                 ]
   519 	    ]
   529             ]
   520 	].
   530         ].
   521 	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   531         any ifTrue:[ self resize ].
   522 	any ifTrue:[ self resize ]
   532         wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
   523     ]
   533     ]
   524 ! !
   534 ! !
   525 
   535 
   526 !Registry class methodsFor:'documentation'!
   536 !Registry class methodsFor:'documentation'!
   527 
   537