980
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
|
|
14 |
|
982
|
15 |
SystemStatusMonitor subclass:#SemaphoreMonitor
|
980
|
16 |
instanceVariableNames:'semaphores'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
1053
|
19 |
category:'Monitors-ST/X'
|
980
|
20 |
!
|
|
21 |
|
|
22 |
!SemaphoreMonitor class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1997 by Claus Gittinger
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
|
|
37 |
|
|
38 |
!
|
|
39 |
|
|
40 |
documentation
|
|
41 |
"
|
|
42 |
This view shows smalltalks semaphores - a debugging tool.
|
|
43 |
|
|
44 |
[see also:]
|
|
45 |
Semaphore SemaphoreSet
|
|
46 |
Process ProcessorScheduler
|
|
47 |
WindowGroup
|
|
48 |
ProcessMonitor
|
|
49 |
|
|
50 |
[author:]
|
|
51 |
Claus Gittinger
|
|
52 |
|
|
53 |
[start with:]
|
|
54 |
SemaphoreMonitor open
|
|
55 |
"
|
|
56 |
|
|
57 |
! !
|
|
58 |
|
|
59 |
!SemaphoreMonitor class methodsFor:'defaults'!
|
|
60 |
|
|
61 |
defaultLabel
|
|
62 |
^ 'Semaphore Monitor'
|
|
63 |
|
|
64 |
"Created: 23.1.1997 / 02:52:53 / cg"
|
|
65 |
! !
|
|
66 |
|
|
67 |
!SemaphoreMonitor methodsFor:'drawing'!
|
|
68 |
|
|
69 |
titleLine
|
1692
|
70 |
^ ' id name count owner waiting process(es) '.
|
980
|
71 |
|
|
72 |
"
|
|
73 |
SemaphoreMonitor open
|
|
74 |
"
|
|
75 |
|
1692
|
76 |
"Modified: / 17.6.1998 / 14:52:48 / cg"
|
980
|
77 |
!
|
|
78 |
|
|
79 |
updateList
|
|
80 |
"update list of semaphores"
|
|
81 |
|
|
82 |
|newList|
|
|
83 |
|
|
84 |
shown ifTrue:[
|
984
|
85 |
newList := Semaphore allSubInstances.
|
980
|
86 |
|
|
87 |
"sort by hashKey - will not always generate unique numbers,
|
|
88 |
but most of the time, this works ... for now"
|
|
89 |
|
|
90 |
newList sort:[:s1 :s2 | s1 identityHash < s2 identityHash].
|
|
91 |
|
|
92 |
newList ~= semaphores ifTrue:[
|
|
93 |
semaphores := WeakArray withAll:newList.
|
|
94 |
self updateStatus
|
|
95 |
].
|
|
96 |
].
|
|
97 |
updateBlock notNil ifTrue:[
|
|
98 |
Processor removeTimedBlock:listUpdateBlock.
|
|
99 |
Processor addTimedBlock:listUpdateBlock afterSeconds:listUpdateDelay
|
|
100 |
].
|
|
101 |
|
|
102 |
"Modified: 3.7.1996 / 13:37:29 / stefan"
|
|
103 |
"Created: 23.1.1997 / 02:44:48 / cg"
|
984
|
104 |
"Modified: 23.1.1997 / 04:10:22 / cg"
|
980
|
105 |
!
|
|
106 |
|
|
107 |
updateStatus
|
|
108 |
"update status display of semaphores"
|
|
109 |
|
1692
|
110 |
|oldList list oldSelection newSelection|
|
980
|
111 |
|
|
112 |
shown ifTrue:[
|
|
113 |
oldList := listView list.
|
1692
|
114 |
oldSelection := listView selectionValue.
|
|
115 |
oldSelection notNil ifTrue:[
|
|
116 |
oldSelection := oldSelection collect:[:line | line asCollectionOfWords first asNumber].
|
|
117 |
newSelection := OrderedCollection new.
|
|
118 |
].
|
980
|
119 |
|
|
120 |
semaphores notNil ifTrue:[
|
|
121 |
list := OrderedCollection new:(semaphores size + 2).
|
|
122 |
list add:self titleLine.
|
|
123 |
list add:(String new:self titleLine size withAll:$-).
|
|
124 |
|
|
125 |
semaphores validElementsDo:[:aSemaphore |
|
995
|
126 |
|waiters waitersNames nm id str owner|
|
980
|
127 |
|
999
|
128 |
"/ need a copy - it may change while being enumerated
|
|
129 |
|
|
130 |
waiters := aSemaphore waitingProcesses copy.
|
980
|
131 |
|
|
132 |
str := '' writeStream.
|
|
133 |
waiters notNil ifTrue:[
|
|
134 |
waiters do:[:aProcess |
|
|
135 |
str nextPut:$[.
|
1692
|
136 |
str nextPutAll:(aProcess id printString).
|
|
137 |
str nextPutAll:' '''.
|
1028
|
138 |
str nextPutAll:(aProcess name contractTo:40).
|
1692
|
139 |
str nextPutAll:''']'.
|
980
|
140 |
str space.
|
|
141 |
].
|
|
142 |
].
|
|
143 |
waitersNames := str contents.
|
|
144 |
|
984
|
145 |
(aSemaphore respondsTo:#name) ifTrue:[
|
|
146 |
nm := aSemaphore name.
|
1022
|
147 |
nm isNil ifTrue:[
|
|
148 |
nm := ''
|
|
149 |
]
|
984
|
150 |
] ifFalse:[
|
|
151 |
nm := ''
|
|
152 |
].
|
980
|
153 |
id := aSemaphore identityHash bitShift:-12.
|
995
|
154 |
owner := aSemaphore lastOwnerId.
|
|
155 |
owner isNil ifTrue:[
|
1692
|
156 |
owner := ' '
|
995
|
157 |
] ifFalse:[
|
1692
|
158 |
owner := owner printStringLeftPaddedTo:5
|
995
|
159 |
].
|
984
|
160 |
list add:(
|
|
161 |
(id printStringPaddedTo:6)
|
980
|
162 |
, ' '
|
993
|
163 |
, ((nm contractTo:25) paddedTo:25)
|
984
|
164 |
, ' '
|
993
|
165 |
, (aSemaphore count printStringLeftPaddedTo:3)
|
984
|
166 |
, ' '
|
995
|
167 |
, owner
|
|
168 |
, ' '
|
993
|
169 |
, (waiters size printStringLeftPaddedTo:3)
|
980
|
170 |
, ' '
|
|
171 |
, waitersNames).
|
1692
|
172 |
oldSelection notNil ifTrue:[
|
|
173 |
(oldSelection includes:id) ifTrue:[
|
|
174 |
newSelection add:list size.
|
|
175 |
]
|
|
176 |
]
|
980
|
177 |
].
|
|
178 |
].
|
|
179 |
"avoid flicker"
|
|
180 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
|
181 |
list keysAndValuesDo:[:idx :entry |
|
|
182 |
(oldList at:idx) ~= entry ifTrue:[
|
|
183 |
listView at:idx put:entry
|
|
184 |
]
|
|
185 |
]
|
|
186 |
] ifFalse:[
|
|
187 |
listView setList:list.
|
|
188 |
"the first two entries cannot be selected"
|
|
189 |
listView attributeAt:1 put:#disabled.
|
|
190 |
listView attributeAt:2 put:#disabled.
|
|
191 |
].
|
1692
|
192 |
newSelection notNil ifTrue:[
|
|
193 |
listView selectWithoutScroll:newSelection
|
|
194 |
].
|
980
|
195 |
listView flush
|
|
196 |
].
|
|
197 |
updateBlock notNil ifTrue:[
|
|
198 |
Processor removeTimedBlock:updateBlock.
|
|
199 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay
|
|
200 |
]
|
|
201 |
|
1692
|
202 |
"Modified: / 3.7.1996 / 13:56:01 / stefan"
|
|
203 |
"Modified: / 17.6.1998 / 14:53:44 / cg"
|
980
|
204 |
! !
|
|
205 |
|
|
206 |
!SemaphoreMonitor methodsFor:'menu'!
|
|
207 |
|
1692
|
208 |
debugWaiters
|
|
209 |
"open a debugger on the selected semaphores waiting processes"
|
|
210 |
|
|
211 |
self selectedSemaphoresDo:[:aSema |
|
|
212 |
aSema waitingProcesses do:[:aProcess |
|
|
213 |
DebugView openOn:aProcess
|
|
214 |
]
|
|
215 |
]
|
|
216 |
|
|
217 |
"Modified: / 23.1.1997 / 03:12:06 / cg"
|
|
218 |
"Created: / 17.6.1998 / 14:56:55 / cg"
|
|
219 |
!
|
|
220 |
|
995
|
221 |
inspectSemaphore
|
980
|
222 |
"open an inspector on the selected semaphores"
|
|
223 |
|
|
224 |
self selectedSemaphoresDo:[:aSema | aSema inspect]
|
|
225 |
|
|
226 |
"Modified: 23.1.1997 / 03:12:06 / cg"
|
995
|
227 |
"Created: 24.1.1997 / 23:11:50 / cg"
|
980
|
228 |
!
|
|
229 |
|
1692
|
230 |
inspectWaiters
|
|
231 |
"open an inspector on the selected semaphores waiting processes"
|
|
232 |
|
|
233 |
self selectedSemaphoresDo:[:aSema |
|
|
234 |
aSema waitingProcesses do:[:aProcess |
|
|
235 |
aProcess inspect
|
|
236 |
]
|
|
237 |
]
|
|
238 |
|
|
239 |
"Modified: / 23.1.1997 / 03:12:06 / cg"
|
|
240 |
"Created: / 17.6.1998 / 14:17:41 / cg"
|
|
241 |
!
|
|
242 |
|
980
|
243 |
selectedSemaphoresDo:aBlock
|
|
244 |
"evaluate aBlock on all selected semaphores"
|
|
245 |
|
|
246 |
|p nr sel|
|
|
247 |
|
|
248 |
sel := listView selection.
|
|
249 |
sel isNil ifTrue:[^ self].
|
|
250 |
|
|
251 |
(sel isKindOf:Collection) ifTrue:[
|
|
252 |
sel do:[:n |
|
|
253 |
nr := n - 2. "for headlines"
|
|
254 |
nr notNil ifTrue:[
|
|
255 |
nr > 0 ifTrue:[
|
|
256 |
p := semaphores at:nr.
|
|
257 |
(p notNil and:[p ~~ 0]) ifTrue:[
|
|
258 |
aBlock value:p
|
|
259 |
]
|
|
260 |
]
|
|
261 |
]
|
|
262 |
]
|
|
263 |
] ifFalse:[
|
|
264 |
nr := sel - 2. "for headlines"
|
|
265 |
nr notNil ifTrue:[
|
|
266 |
nr > 0 ifTrue:[
|
|
267 |
p := semaphores at:nr.
|
|
268 |
(p notNil and:[p ~~ 0]) ifTrue:[
|
|
269 |
aBlock value:p
|
|
270 |
]
|
|
271 |
]
|
|
272 |
]
|
|
273 |
].
|
|
274 |
|
|
275 |
"Created: 23.1.1997 / 03:11:24 / cg"
|
|
276 |
!
|
|
277 |
|
|
278 |
signalSemaphore
|
|
279 |
"signal all selected semaphores"
|
|
280 |
|
|
281 |
self selectedSemaphoresDo:[:aSema | aSema signal]
|
|
282 |
|
|
283 |
"Created: 23.1.1997 / 03:12:30 / cg"
|
|
284 |
!
|
|
285 |
|
|
286 |
statusMenu
|
|
287 |
"return a popUpMenu"
|
|
288 |
|
1692
|
289 |
<resource: #programMenu>
|
|
290 |
|
980
|
291 |
|labels selectors m sel|
|
|
292 |
|
|
293 |
labels := resources array:#(
|
|
294 |
'inspect'
|
1692
|
295 |
'inspect waiters'
|
|
296 |
'debug waiters'
|
980
|
297 |
'-'
|
|
298 |
'signal'
|
|
299 |
).
|
|
300 |
selectors := #(
|
|
301 |
inspectSemaphore
|
1692
|
302 |
inspectWaiters
|
|
303 |
debugWaiters
|
980
|
304 |
nil
|
|
305 |
signalSemaphore
|
|
306 |
).
|
|
307 |
|
|
308 |
updateProcess isNil ifTrue:[
|
|
309 |
labels := (resources array:#('update' '-')) , labels.
|
|
310 |
selectors := #(updateView nil) , selectors
|
|
311 |
].
|
|
312 |
|
|
313 |
m := PopUpMenu labels:labels
|
|
314 |
selectors:selectors.
|
|
315 |
|
|
316 |
|
|
317 |
listView hasSelection ifFalse:[
|
|
318 |
m disableAll:#(
|
|
319 |
inspectSemaphore
|
|
320 |
signalSemaphore
|
|
321 |
)
|
|
322 |
].
|
|
323 |
^ m
|
|
324 |
|
1692
|
325 |
"Modified: / 17.6.1998 / 14:17:05 / cg"
|
980
|
326 |
! !
|
|
327 |
|
|
328 |
!SemaphoreMonitor methodsFor:'queries'!
|
|
329 |
|
|
330 |
preferredExtent
|
|
331 |
"return my preferred extent"
|
|
332 |
|
|
333 |
^ (font widthOf:self titleLine) + 40 @ 250
|
|
334 |
|
|
335 |
"Modified: 23.1.1997 / 02:35:01 / cg"
|
|
336 |
"Created: 23.1.1997 / 03:04:58 / cg"
|
|
337 |
! !
|
|
338 |
|
|
339 |
!SemaphoreMonitor methodsFor:'user actions'!
|
|
340 |
|
|
341 |
doubleClicked
|
|
342 |
"open an inspector on the selected semaphore"
|
|
343 |
|
1023
|
344 |
self inspectSemaphore
|
980
|
345 |
|
|
346 |
"Created: 23.1.1997 / 03:22:04 / cg"
|
1023
|
347 |
"Modified: 31.1.1997 / 22:33:27 / cg"
|
980
|
348 |
! !
|
|
349 |
|
|
350 |
!SemaphoreMonitor class methodsFor:'documentation'!
|
|
351 |
|
|
352 |
version
|
1692
|
353 |
^ '$Header: /cvs/stx/stx/libtool/SemaphoreMonitor.st,v 1.12 1998-06-17 12:58:41 cg Exp $'
|
980
|
354 |
! !
|