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:''
|
|
19 |
category:'Interface-Tools'
|
|
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
|
993
|
70 |
^ ' id name count waiting process(es) '.
|
980
|
71 |
|
|
72 |
"
|
|
73 |
SemaphoreMonitor open
|
|
74 |
"
|
|
75 |
|
993
|
76 |
"Modified: 24.1.1997 / 23:03: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 |
|
|
110 |
|oldList list |
|
|
111 |
|
|
112 |
shown ifTrue:[
|
|
113 |
oldList := listView list.
|
|
114 |
|
|
115 |
semaphores notNil ifTrue:[
|
|
116 |
list := OrderedCollection new:(semaphores size + 2).
|
|
117 |
list add:self titleLine.
|
|
118 |
list add:(String new:self titleLine size withAll:$-).
|
|
119 |
|
|
120 |
semaphores validElementsDo:[:aSemaphore |
|
984
|
121 |
|waiters waitersNames nm id str|
|
980
|
122 |
|
|
123 |
waiters := aSemaphore waitingProcesses.
|
|
124 |
|
|
125 |
str := '' writeStream.
|
|
126 |
str writeLimit:80.
|
|
127 |
waiters notNil ifTrue:[
|
|
128 |
waiters do:[:aProcess |
|
|
129 |
str nextPut:$[.
|
|
130 |
str nextPutAll:aProcess name.
|
|
131 |
str nextPut:$].
|
|
132 |
str space.
|
|
133 |
].
|
|
134 |
].
|
|
135 |
waitersNames := str contents.
|
|
136 |
|
984
|
137 |
(aSemaphore respondsTo:#name) ifTrue:[
|
|
138 |
nm := aSemaphore name.
|
|
139 |
] ifFalse:[
|
|
140 |
nm := ''
|
|
141 |
].
|
980
|
142 |
id := aSemaphore identityHash bitShift:-12.
|
984
|
143 |
list add:(
|
|
144 |
(id printStringPaddedTo:6)
|
980
|
145 |
, ' '
|
993
|
146 |
, ((nm contractTo:25) paddedTo:25)
|
984
|
147 |
, ' '
|
993
|
148 |
, (aSemaphore count printStringLeftPaddedTo:3)
|
984
|
149 |
, ' '
|
993
|
150 |
, (waiters size printStringLeftPaddedTo:3)
|
980
|
151 |
, ' '
|
|
152 |
, waitersNames).
|
|
153 |
|
|
154 |
].
|
|
155 |
].
|
|
156 |
"avoid flicker"
|
|
157 |
(oldList notNil and:[oldList size == list size]) ifTrue:[
|
|
158 |
list keysAndValuesDo:[:idx :entry |
|
|
159 |
(oldList at:idx) ~= entry ifTrue:[
|
|
160 |
listView at:idx put:entry
|
|
161 |
]
|
|
162 |
]
|
|
163 |
] ifFalse:[
|
|
164 |
listView setList:list.
|
|
165 |
"the first two entries cannot be selected"
|
|
166 |
listView attributeAt:1 put:#disabled.
|
|
167 |
listView attributeAt:2 put:#disabled.
|
|
168 |
].
|
|
169 |
listView flush
|
|
170 |
].
|
|
171 |
updateBlock notNil ifTrue:[
|
|
172 |
Processor removeTimedBlock:updateBlock.
|
|
173 |
Processor addTimedBlock:updateBlock afterSeconds:updateDelay
|
|
174 |
]
|
|
175 |
|
|
176 |
"Modified: 3.7.1996 / 13:56:01 / stefan"
|
993
|
177 |
"Modified: 24.1.1997 / 23:04:20 / cg"
|
980
|
178 |
! !
|
|
179 |
|
|
180 |
!SemaphoreMonitor methodsFor:'menu'!
|
|
181 |
|
|
182 |
inspectSelection
|
|
183 |
"open an inspector on the selected semaphores"
|
|
184 |
|
|
185 |
self selectedSemaphoresDo:[:aSema | aSema inspect]
|
|
186 |
|
|
187 |
"Created: 23.1.1997 / 03:11:46 / cg"
|
|
188 |
"Modified: 23.1.1997 / 03:12:06 / cg"
|
|
189 |
!
|
|
190 |
|
|
191 |
selectedSemaphoresDo:aBlock
|
|
192 |
"evaluate aBlock on all selected semaphores"
|
|
193 |
|
|
194 |
|p nr sel|
|
|
195 |
|
|
196 |
sel := listView selection.
|
|
197 |
sel isNil ifTrue:[^ self].
|
|
198 |
|
|
199 |
(sel isKindOf:Collection) ifTrue:[
|
|
200 |
sel do:[:n |
|
|
201 |
nr := n - 2. "for headlines"
|
|
202 |
nr notNil ifTrue:[
|
|
203 |
nr > 0 ifTrue:[
|
|
204 |
p := semaphores at:nr.
|
|
205 |
(p notNil and:[p ~~ 0]) ifTrue:[
|
|
206 |
aBlock value:p
|
|
207 |
]
|
|
208 |
]
|
|
209 |
]
|
|
210 |
]
|
|
211 |
] ifFalse:[
|
|
212 |
nr := sel - 2. "for headlines"
|
|
213 |
nr notNil ifTrue:[
|
|
214 |
nr > 0 ifTrue:[
|
|
215 |
p := semaphores at:nr.
|
|
216 |
(p notNil and:[p ~~ 0]) ifTrue:[
|
|
217 |
aBlock value:p
|
|
218 |
]
|
|
219 |
]
|
|
220 |
]
|
|
221 |
].
|
|
222 |
|
|
223 |
"Created: 23.1.1997 / 03:11:24 / cg"
|
|
224 |
!
|
|
225 |
|
|
226 |
signalSemaphore
|
|
227 |
"signal all selected semaphores"
|
|
228 |
|
|
229 |
self selectedSemaphoresDo:[:aSema | aSema signal]
|
|
230 |
|
|
231 |
"Created: 23.1.1997 / 03:12:30 / cg"
|
|
232 |
!
|
|
233 |
|
|
234 |
statusMenu
|
|
235 |
"return a popUpMenu"
|
|
236 |
|
|
237 |
|labels selectors m sel|
|
|
238 |
|
|
239 |
labels := resources array:#(
|
|
240 |
'inspect'
|
|
241 |
'-'
|
|
242 |
'signal'
|
|
243 |
).
|
|
244 |
selectors := #(
|
|
245 |
inspectSemaphore
|
|
246 |
nil
|
|
247 |
signalSemaphore
|
|
248 |
).
|
|
249 |
|
|
250 |
updateProcess isNil ifTrue:[
|
|
251 |
labels := (resources array:#('update' '-')) , labels.
|
|
252 |
selectors := #(updateView nil) , selectors
|
|
253 |
].
|
|
254 |
|
|
255 |
m := PopUpMenu labels:labels
|
|
256 |
selectors:selectors.
|
|
257 |
|
|
258 |
|
|
259 |
listView hasSelection ifFalse:[
|
|
260 |
m disableAll:#(
|
|
261 |
inspectSemaphore
|
|
262 |
signalSemaphore
|
|
263 |
)
|
|
264 |
].
|
|
265 |
^ m
|
|
266 |
|
|
267 |
"Modified: 23.1.1997 / 03:08:19 / cg"
|
|
268 |
! !
|
|
269 |
|
|
270 |
!SemaphoreMonitor methodsFor:'queries'!
|
|
271 |
|
|
272 |
preferredExtent
|
|
273 |
"return my preferred extent"
|
|
274 |
|
|
275 |
^ (font widthOf:self titleLine) + 40 @ 250
|
|
276 |
|
|
277 |
"Modified: 23.1.1997 / 02:35:01 / cg"
|
|
278 |
"Created: 23.1.1997 / 03:04:58 / cg"
|
|
279 |
! !
|
|
280 |
|
|
281 |
!SemaphoreMonitor methodsFor:'user actions'!
|
|
282 |
|
|
283 |
doubleClicked
|
|
284 |
"open an inspector on the selected semaphore"
|
|
285 |
|
|
286 |
self inspectSelection
|
|
287 |
|
|
288 |
"Created: 23.1.1997 / 03:22:04 / cg"
|
|
289 |
! !
|
|
290 |
|
|
291 |
!SemaphoreMonitor class methodsFor:'documentation'!
|
|
292 |
|
|
293 |
version
|
993
|
294 |
^ '$Header: /cvs/stx/stx/libtool/SemaphoreMonitor.st,v 1.4 1997-01-24 22:05:05 cg Exp $'
|
980
|
295 |
! !
|