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" |