SemaphoreMonitor.st
changeset 17169 91a80ba50915
parent 14202 336beb9d98f6
child 17215 4a42de8e888a
child 17226 66b523a67429
equal deleted inserted replaced
17168:26ea2eb499bf 17169:91a80ba50915
     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:libtool' }"
    12 "{ Package: 'stx:libtool' }"
    13 
    13 
       
    14 "{ NameSpace: Smalltalk }"
       
    15 
    14 SystemStatusMonitor subclass:#SemaphoreMonitor
    16 SystemStatusMonitor subclass:#SemaphoreMonitor
    15 	instanceVariableNames:'semaphores'
    17 	instanceVariableNames:'semaphores'
    16 	classVariableNames:''
    18 	classVariableNames:''
    17 	poolDictionaries:''
    19 	poolDictionaries:''
    18 	category:'Monitors-ST/X'
    20 	category:'Monitors-ST/X'
    36 
    38 
    37 !
    39 !
    38 
    40 
    39 documentation
    41 documentation
    40 "
    42 "
    41     This view shows smalltalks semaphores - a debugging tool.
    43     This view shows smalltalk's semaphores - a debugging tool.
    42 
    44 
       
    45     [disclaimer:]
       
    46         this is one of the oldest tools in the system, written in the early 90's.
       
    47         It does in no way reflect the way GUIs are designed/written these days.
       
    48         
    43     [see also:]
    49     [see also:]
    44 	Semaphore SemaphoreSet
    50         Semaphore SemaphoreSet
    45 	Process ProcessorScheduler
    51         Process ProcessorScheduler
    46 	WindowGroup
    52         WindowGroup
    47 	ProcessMonitor
    53         ProcessMonitor
    48 
    54 
    49     [author:]
    55     [author:]
    50 	Claus Gittinger
    56         Claus Gittinger
    51 
    57 
    52     [start with:]
    58     [start with:]
    53 	SemaphoreMonitor open
    59         SemaphoreMonitor open
    54 "
    60 "
    55 
       
    56 ! !
    61 ! !
    57 
    62 
    58 !SemaphoreMonitor class methodsFor:'defaults'!
    63 !SemaphoreMonitor class methodsFor:'defaults'!
    59 
    64 
    60 defaultLabel
    65 defaultLabel
   106     "update status display of semaphores"
   111     "update status display of semaphores"
   107 
   112 
   108     |oldList list oldSelection newSelection|
   113     |oldList list oldSelection newSelection|
   109 
   114 
   110     shown ifTrue:[
   115     shown ifTrue:[
   111 	oldList := listView list.
   116         oldList := listView list.
   112 	oldSelection := listView selectionValue.
   117         oldSelection := listView selectionValue.
   113 	oldSelection notNil ifTrue:[
   118         oldSelection notNil ifTrue:[
   114 	    oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber].
   119             oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber].
   115 	    newSelection := OrderedCollection new.
   120             newSelection := OrderedCollection new.
   116 	].
   121         ].
   117 
   122 
   118 	newSemaphoreList notNil ifTrue:[
   123         newSemaphoreList notNil ifTrue:[
   119 	    semaphores := WeakArray withAll:newSemaphoreList.
   124             semaphores := WeakArray withAll:newSemaphoreList.
   120 	].
   125         ].
   121 	semaphores notNil ifTrue:[
   126         semaphores notNil ifTrue:[
   122 	    list := OrderedCollection new:(semaphores size + 2).
   127             list := OrderedCollection new:(semaphores size + self numberOfHeadlines).
   123 	    list add:self titleLine.
   128             list add:self titleLine.
   124 	    list add:(String new:self titleLine size withAll:$-).
   129             list add:(String new:self titleLine size withAll:$-).
   125 
   130 
   126 	    semaphores validElementsDo:[:aSemaphore |
   131             semaphores validElementsDo:[:aSemaphore |
   127 		|waiters waitersNames nm id str owner color line count|
   132                 |waiters waitersNames nm id str owner color line count|
   128 
   133 
   129 		"/ need a copy - it may change while being enumerated
   134                 "/ need a copy - it may change while being enumerated
   130 		[
   135                 [
   131 		    count := aSemaphore count.
   136                     count := aSemaphore count.
   132 		    waiters := aSemaphore waitingProcesses copy.
   137                     waiters := aSemaphore waitingProcesses copy.
   133 		] valueUninterruptably.
   138                 ] valueUninterruptably.
   134 
   139 
   135 		str := '' writeStream.
   140                 str := '' writeStream.
   136 		[
   141                 [
   137 		    waiters notNil ifTrue:[
   142                     waiters notNil ifTrue:[
   138 			waiters do:[:aProcess |
   143                         waiters do:[:aProcess |
   139 			    str nextPut:$[.
   144                             str nextPut:$[.
   140 			    aProcess id printOn:str.
   145                             aProcess id printOn:str.
   141 			    str nextPutAll:' '''.
   146                             str nextPutAll:' '''.
   142 			    str nextPutAll:(aProcess name contractTo:40).
   147                             str nextPutAll:(aProcess name contractTo:40).
   143 			    str nextPutAll:'''<'.
   148                             str nextPutAll:'''<'.
   144 			    aProcess priority printOn:str.
   149                             aProcess priority printOn:str.
   145 			    str nextPutAll:'>]'.
   150                             str nextPutAll:'>]'.
   146 			    str space.
   151                             str space.
   147 			].
   152                         ].
   148 		    ]
   153                     ]
   149 		] valueUninterruptably.
   154                 ] valueUninterruptably.
   150 		waitersNames := str contents.
   155                 waitersNames := str contents.
   151 
   156 
   152 		(aSemaphore respondsTo:#name) ifTrue:[
   157                 (aSemaphore respondsTo:#name) ifTrue:[
   153 		    nm := aSemaphore name.
   158                     nm := aSemaphore name.
   154 		    nm isNil ifTrue:[
   159                     nm isNil ifTrue:[
   155 			nm := ''
   160                         nm := ''
   156 		    ]
   161                     ]
   157 		] ifFalse:[
   162                 ] ifFalse:[
   158 		    nm := ''
   163                     nm := ''
   159 		].
   164                 ].
   160 		id := aSemaphore identityHash bitShift:-12.
   165                 id := aSemaphore identityHash bitShift:-12.
   161 		owner := aSemaphore lastOwnerId.
   166                 owner := aSemaphore lastOwnerId.
   162 		owner isNil ifTrue:[
   167                 owner isNil ifTrue:[
   163 		    owner := '     '
   168                     owner := '     '
   164 		] ifFalse:[
   169                 ] ifFalse:[
   165 		    owner := owner printStringLeftPaddedTo:5
   170                     owner := owner printStringLeftPaddedTo:5
   166 		].
   171                 ].
   167 		line := (id printStringPaddedTo:6)
   172                 line := (id printStringPaddedTo:6)
   168 			  , ' '
   173                           , ' '
   169 			  , ((nm contractTo:25) paddedTo:25)
   174                           , ((nm contractTo:25) paddedTo:25)
   170 			  , ' '
   175                           , ' '
   171 			  , (count printStringLeftPaddedTo:3)
   176                           , (count printStringLeftPaddedTo:3)
   172 			  , ' '
   177                           , ' '
   173 			  , owner printString
   178                           , owner printString
   174 			  , ' '
   179                           , ' '
   175 			  , (waiters size printStringLeftPaddedTo:3)
   180                           , (waiters size printStringLeftPaddedTo:3)
   176 			  , ' '
   181                           , ' '
   177 			  , waitersNames.
   182                           , waitersNames.
   178 
   183 
   179 		count > 0 ifTrue:[
   184                 count > 0 ifTrue:[
   180 		    waiters size > 0 ifTrue:[
   185                     waiters size > 0 ifTrue:[
   181 			"this happens if a low priority process is ready to run but didn't wake up yet"
   186                         "this happens if a low priority process is ready to run but didn't wake up yet"
   182 			color := Color red.
   187                         color := Color red.
   183 "/                        self beep.
   188 "/                        self beep.
   184 		    ] ifFalse:[
   189                     ] ifFalse:[
   185 			"fine, this semaphore is available"
   190                         "fine, this semaphore is available"
   186 			color := Color blue.
   191                         color := Color blue.
   187 		    ].
   192                     ].
   188 		    line := line colorizeAllWith:color.
   193                     line := line colorizeAllWith:color.
   189 		] ifFalse:[
   194                 ] ifFalse:[
   190 		    waiters size > 0 ifTrue:[
   195                     waiters size > 0 ifTrue:[
   191 			line := line colorizeAllWith:Color brown.
   196                         line := line colorizeAllWith:Color brown.
   192 		    ].
   197                     ].
   193 		].
   198                 ].
   194 
   199 
   195 		list add:line.
   200                 list add:line.
   196 		oldSelection notNil ifTrue:[
   201                 oldSelection notNil ifTrue:[
   197 		    (oldSelection includes:id) ifTrue:[
   202                     (oldSelection includes:id) ifTrue:[
   198 			newSelection add:list size.
   203                         newSelection add:list size.
   199 		    ]
   204                     ]
   200 		]
   205                 ]
   201 	    ].
   206             ].
   202 	].
   207         ].
   203 	"avoid flicker"
   208         "avoid flicker"
   204 	(oldList notNil and:[oldList size == list size]) ifTrue:[
   209         (oldList notNil and:[oldList size == list size]) ifTrue:[
   205 	    list keysAndValuesDo:[:idx :entry |
   210             list keysAndValuesDo:[:idx :entry |
   206 		(oldList at:idx) ~= entry ifTrue:[
   211                 (oldList at:idx) ~= entry ifTrue:[
   207 		    listView at:idx put:entry
   212                     listView at:idx put:entry
   208 		]
   213                 ]
   209 	    ]
   214             ]
   210 	] ifFalse:[
   215         ] ifFalse:[
   211 	    listView setList:list.
   216             listView setList:list.
   212 	    "the first two entries cannot be selected"
   217             "the first two entries cannot be selected"
   213 	    listView attributeAt:1 put:#disabled.
   218             listView attributeAt:1 put:#disabled.
   214 	    listView attributeAt:2 put:#disabled.
   219             listView attributeAt:2 put:#disabled.
   215 	].
   220         ].
   216 	newSelection notNil ifTrue:[
   221         newSelection notNil ifTrue:[
   217 	    listView selectWithoutScroll:newSelection
   222             listView selectWithoutScroll:newSelection
   218 	].
   223         ].
   219 	listView flush
   224         listView flush
   220     ].
   225     ].
   221     updateBlock notNil ifTrue:[
   226     updateBlock notNil ifTrue:[
   222 	Processor removeTimedBlock:updateBlock.
   227         Processor removeTimedBlock:updateBlock.
   223 	Processor addTimedBlock:updateBlock afterSeconds:updateDelay
   228         Processor addTimedBlock:updateBlock afterSeconds:updateDelay
   224     ]
   229     ]
   225 
   230 
   226     "Modified: / 3.7.1996 / 13:56:01 / stefan"
   231     "Modified: / 3.7.1996 / 13:56:01 / stefan"
   227     "Created: / 14.12.1999 / 20:52:29 / cg"
   232     "Created: / 14.12.1999 / 20:52:29 / cg"
   228     "Modified: / 14.12.1999 / 20:53:14 / cg"
   233     "Modified: / 14.12.1999 / 20:53:14 / cg"
   272 
   277 
   273     sel := listView selection.
   278     sel := listView selection.
   274     sel isNil ifTrue:[^ self].
   279     sel isNil ifTrue:[^ self].
   275 
   280 
   276     (sel isKindOf:Collection) ifTrue:[
   281     (sel isKindOf:Collection) ifTrue:[
   277 	sel do:[:n |
   282         sel do:[:n |
   278 	    nr := n - 2.   "for headlines"
   283             nr := n - self numberOfHeadlines.
   279 	    nr notNil ifTrue:[
   284             nr notNil ifTrue:[
   280 		nr > 0 ifTrue:[
   285                 nr > 0 ifTrue:[
   281 		    p := semaphores at:nr.
   286                     p := semaphores at:nr.
   282 		    (p notNil and:[p ~~ 0]) ifTrue:[
   287                     (p notNil and:[p ~~ 0]) ifTrue:[
   283 		       aBlock value:p
   288                        aBlock value:p
   284 		    ]
   289                     ]
   285 		]
   290                 ]
   286 	    ]
   291             ]
   287 	]
   292         ]
   288     ] ifFalse:[
   293     ] ifFalse:[
   289 	nr := sel - 2.     "for headlines"
   294         nr := sel - self numberOfHeadlines.    
   290 	nr notNil ifTrue:[
   295         nr notNil ifTrue:[
   291 	    nr > 0 ifTrue:[
   296             nr > 0 ifTrue:[
   292 		p := semaphores at:nr.
   297                 p := semaphores at:nr.
   293 		(p notNil and:[p ~~ 0]) ifTrue:[
   298                 (p notNil and:[p ~~ 0]) ifTrue:[
   294 		   aBlock value:p
   299                    aBlock value:p
   295 		]
   300                 ]
   296 	    ]
   301             ]
   297 	]
   302         ]
   298     ].
   303     ].
   299 
   304 
   300     "Created: 23.1.1997 / 03:11:24 / cg"
   305     "Created: 23.1.1997 / 03:11:24 / cg"
   301 !
   306 !
   302 
   307 
   350     "Modified: / 17.6.1998 / 14:17:05 / cg"
   355     "Modified: / 17.6.1998 / 14:17:05 / cg"
   351 ! !
   356 ! !
   352 
   357 
   353 !SemaphoreMonitor methodsFor:'queries'!
   358 !SemaphoreMonitor methodsFor:'queries'!
   354 
   359 
   355 preferredExtent
   360 numberOfHeadlines
   356     "return my preferred extent"
   361     ^ 2
   357 
       
   358     ^ (self font widthOf:self titleLine) + 40 @ 250
       
   359 
       
   360     "Modified: 23.1.1997 / 02:35:01 / cg"
       
   361     "Created: 23.1.1997 / 03:04:58 / cg"
       
   362 ! !
   362 ! !
   363 
   363 
   364 !SemaphoreMonitor methodsFor:'user actions'!
   364 !SemaphoreMonitor methodsFor:'user actions'!
   365 
   365 
   366 doubleClicked
   366 doubleClicked
   373 ! !
   373 ! !
   374 
   374 
   375 !SemaphoreMonitor class methodsFor:'documentation'!
   375 !SemaphoreMonitor class methodsFor:'documentation'!
   376 
   376 
   377 version
   377 version
   378     ^ '$Header: /cvs/stx/stx/libtool/SemaphoreMonitor.st,v 1.18 2014-04-11 14:22:55 stefan Exp $'
   378     ^ '$Header$'
   379 ! !
   379 ! !
   380 
   380