start-up and shut-down lists

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

start-up and shut-down lists

Eliot Miranda-2
Hi All,

    I'm profiling image startup and consequently want to pause a MessageTally during a snapshot.  So I want to add MessageTally to the StartUpList immediately after Delay (the first entry in StartUpList) and to the ShutDownList immediately before Delay.  But when I look at the SmalltalkImage accessor I see some confusion:
 
SmalltalkImage>add: aClass toList: startUpOrShutDownList after: predecessor
"Add the name of aClass to the startUp or shutDown list.
Add it after the name of predecessor, or at the end if predecessor is nil."

| name earlierName |
name := aClass name.
(self at: name ifAbsent: [nil]) == aClass ifFalse:
[self error: name , ' cannot be found in Smalltalk dictionary.'].
predecessor == nil
ifTrue: ["No-op if alredy in the list."
(startUpOrShutDownList includes: name) ifFalse:
[startUpOrShutDownList == StartUpList
ifTrue: ["Add to end of startUp list"
startUpOrShutDownList addLast: name]
ifFalse: ["Add to front of shutDown list"
startUpOrShutDownList addFirst: name]]]
ifFalse: ["Add after predecessor, moving it if already there."
earlierName := predecessor name.
(self at: earlierName) == predecessor ifFalse:
[self error: earlierName , ' cannot be found in Smalltalk dictionary.'].
(startUpOrShutDownList includes: earlierName) ifFalse:
[self error: earlierName , ' cannot be found in the list.'].
startUpOrShutDownList remove: name ifAbsent:[].
startUpOrShutDownList add: name after: earlierName]

In the predecessor == nil arm adding to the StartUpList adds at the end and adding to the ShutDownList adds at the beginning, which makes sense, at least to me.  But if predecessor is not nil then adding to either adds after.  The asymmetry is troubling.  I guess in the name of stability the only way to solve this is to add an explicit add:toList:before: and sugar (add:toStartUpListBefore: add:toShutDownListBefore:).  So what's the rationale for the asymmetry, or is it an unintentional mistake?
--
best,
Eliot

Reply | Threaded
Open this post in threaded view
|

Re: start-up and shut-down lists

Marcus Denker-4

On Jul 13, 2012, at 9:09 PM, Eliot Miranda wrote:

> Hi All,
>
>     I'm profiling image startup and consequently want to pause a MessageTally during a snapshot.  So I want to add MessageTally to the StartUpList immediately after Delay (the first entry in StartUpList) and to the ShutDownList immediately before Delay.  But when I look at the SmalltalkImage accessor I see some confusion:
>  

In Pharo I have rewritting this: you can add either before or after, so there is support for both adding before and after:


add: aClass toList: startUpOrShutDownList after: predecessor
        "Add the name of aClass to the startUp or shutDown list.
        Add it after the name of predecessor"

        (Smalltalk globals includes: aClass)
                ifFalse: [self error: aClass name , ' cannot be found in Smalltalk dictionary.'].

        "Add after predecessor, moving it if already there."
        (Smalltalk globals includes: predecessor)  
                ifFalse: [self error: predecessor name , ' cannot be found in Smalltalk dictionary.'].
        (startUpOrShutDownList includes: predecessor name)
                ifFalse: [self error: predecessor name , ' cannot be found in the list.'].
        startUpOrShutDownList remove: aClass name ifAbsent:[].
        startUpOrShutDownList add: aClass name after: predecessor name


add: aClass toList: startUpOrShutDownList before: successor
        "Add the name of aClass to the startUp or shutDown list.
        Add it before the name of successor"

        (Smalltalk globals includes: aClass)
                ifFalse: [self error: aClass name , ' cannot be found in Smalltalk dictionary.'].
               
        "Add before successor, moving it if already there."
        (Smalltalk globals includes: successor)  
                ifFalse: [self error: successor name , ' cannot be found in Smalltalk dictionary.'].
        (startUpOrShutDownList includes: successor name)
                ifFalse: [self error: successor name , ' cannot be found in the list.'].
        startUpOrShutDownList remove: aClass name ifAbsent: [].
        startUpOrShutDownList add: aClass name before: successor name.


 


--
Marcus Denker -- http://marcusdenker.de