author | hlopkmar |
Tue, 28 Aug 2012 16:09:58 +0000 | |
branch | jk_new_structure |
changeset 1690 | 2dbce03c979a |
parent 1689 | 5da8961dff01 |
child 1691 | 826f8d7dc0df |
permissions | -rw-r--r-- |
1142 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
1142 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
1142 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaMonitor |
|
1172 | 24 |
instanceVariableNames:'owningProcess processesEntered monitorSema count waitingSema |
1690 | 25 |
processesWaiting waitEnabled ownerPrintString' |
26 |
classVariableNames:'instVarAccess' |
|
1142 | 27 |
poolDictionaries:'' |
28 |
category:'Languages-Java-Support' |
|
29 |
! |
|
30 |
||
31 |
!JavaMonitor class methodsFor:'documentation'! |
|
32 |
||
33 |
copyright |
|
34 |
" |
|
35 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 36 |
|
1155 | 37 |
New code and modifications done at SWING Research Group [1]: |
1152 | 38 |
|
1142 | 39 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
40 |
SWING Research Group, Czech Technical University in Prague |
|
41 |
||
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
||
1155 | 49 |
[1] Code written at SWING Research Group contains a signature |
50 |
of one of the above copright owners. For exact set of such code, |
|
51 |
see the differences between this version and version stx:libjava |
|
1152 | 52 |
as of 1.9.2010 |
1142 | 53 |
|
54 |
" |
|
55 |
! ! |
|
56 |
||
1172 | 57 |
!JavaMonitor class methodsFor:'initialization'! |
58 |
||
59 |
initialize |
|
1690 | 60 |
instVarAccess := RecursionLock forMutualExclusion. |
1172 | 61 |
|
62 |
"Created: / 29-11-2011 / 11:23:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
63 |
! ! |
|
64 |
||
1142 | 65 |
!JavaMonitor class methodsFor:'instance creation'! |
66 |
||
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
67 |
for: owningObject |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
68 |
^ self basicNew initializeFor: owningObject. |
1142 | 69 |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
70 |
"Created: / 30-11-2011 / 20:39:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1142 | 71 |
! ! |
72 |
||
73 |
!JavaMonitor methodsFor:'accessing'! |
|
74 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
75 |
activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
76 |
^ Processor activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
77 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
78 |
|
1142 | 79 |
copyProcessesEntered |
80 |
^ processesEntered copy. |
|
81 |
||
82 |
"Created: / 20-11-2011 / 14:45:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
83 |
! |
|
84 |
||
85 |
processesEntered |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
86 |
"dont do anything to me, access needs to be sync'd" |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
87 |
^ processesEntered. |
1142 | 88 |
|
89 |
"Created: / 20-11-2011 / 13:22:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
90 |
! ! |
|
91 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
92 |
!JavaMonitor methodsFor:'atomic'! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
93 |
|
1172 | 94 |
addProcess: aProcess |
95 |
instVarAccess critical: [ processesEntered add: aProcess ]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
96 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
97 |
"Created: / 20-11-2011 / 20:30:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
98 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
99 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
100 |
clearOwningProcess |
1172 | 101 |
instVarAccess critical: [ owningProcess := nil ]. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
102 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
103 |
"Created: / 20-11-2011 / 20:34:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
104 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
105 |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
106 |
decrement |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
107 |
"owning process released monitor, lets lower our counter so we know how many times |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
108 |
do we have to release it" |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
109 |
|
1172 | 110 |
instVarAccess critical: [ count := count - 1 ]. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
111 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
112 |
"Created: / 22-11-2011 / 10:49:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
113 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
114 |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
115 |
disableWait |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
116 |
Logger log: ('Waiting is disabled on monitor for %1' bindWith: ownerPrintString) severity:#debug facility:#JVM. |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
117 |
instVarAccess critical: [ waitEnabled := false ]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
118 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
119 |
"Created: / 30-11-2011 / 20:34:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
120 |
"Modified: / 10-05-2012 / 00:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
121 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
122 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
123 |
enableWait |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
124 |
instVarAccess critical: [waitEnabled := true]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
125 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
126 |
"Created: / 30-11-2011 / 20:34:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
127 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
128 |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
129 |
increment |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
130 |
"owning process entered monitor again (recursion ...), lets raise our counter so we know how many times |
1172 | 131 |
do we have to release it" |
132 |
||
133 |
instVarAccess critical: [ count := count + 1 ]. |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
134 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
135 |
"Created: / 22-11-2011 / 10:49:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
136 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
137 |
|
1172 | 138 |
owningProcess: aProcess |
139 |
instVarAccess critical: [ owningProcess := aProcess ]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
140 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
141 |
"Created: / 20-11-2011 / 20:32:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
142 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
143 |
|
1146 | 144 |
processesWaitingAdd: aProcess |
1172 | 145 |
instVarAccess |
146 |
critical: [ |
|
147 |
self assert: (processesWaiting includesKey: aProcess) not. |
|
148 |
processesWaiting at: aProcess put: count |
|
149 |
]. |
|
1146 | 150 |
|
151 |
"Created: / 22-11-2011 / 11:57:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
152 |
! |
|
153 |
||
154 |
processesWaitingRestore: aProcess |
|
1172 | 155 |
instVarAccess |
156 |
critical: [ |
|
157 |
self assert: (processesWaiting includesKey: aProcess). |
|
158 |
self reinitCounter: (processesWaiting at: aProcess). |
|
159 |
processesWaiting removeKey: aProcess |
|
160 |
]. |
|
1146 | 161 |
|
162 |
"Created: / 22-11-2011 / 12:59:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
163 |
! |
|
164 |
||
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
165 |
reinitCounter |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
166 |
"owning process is different from previous, lets start counting from beginning" |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
167 |
|
1172 | 168 |
instVarAccess critical: [ count := 1 ]. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
169 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
170 |
"Created: / 22-11-2011 / 10:51:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
171 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
172 |
|
1146 | 173 |
reinitCounter: newCount |
1172 | 174 |
instVarAccess critical: [ count := newCount ]. |
1146 | 175 |
|
176 |
"Created: / 22-11-2011 / 13:00:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
177 |
! |
|
178 |
||
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
179 |
removeProcess: aProcess |
1172 | 180 |
instVarAccess |
1146 | 181 |
critical: [ |
182 |
self assert: processesEntered last == aProcess. |
|
183 |
processesEntered remove: aProcess |
|
184 |
]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
185 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
186 |
"Created: / 20-11-2011 / 20:28:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
187 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
188 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
189 |
waitEnabled |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
190 |
instVarAccess critical: [ ^ waitEnabled]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
191 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
192 |
"Created: / 30-11-2011 / 20:34:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
193 |
! ! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
194 |
|
1142 | 195 |
!JavaMonitor methodsFor:'initialization'! |
196 |
||
197 |
initialize |
|
198 |
owningProcess := nil. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
199 |
processesEntered := OrderedCollection new. |
1142 | 200 |
monitorSema := Semaphore new: 1. |
1146 | 201 |
processesWaiting := Dictionary new. |
202 |
waitingSema := Semaphore new: 0. |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
203 |
waitEnabled. |
1142 | 204 |
|
205 |
"Created: / 20-11-2011 / 13:28:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
206 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
207 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
208 |
initializeFor: owningObject |
1690 | 209 |
owningProcess := nil. |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
210 |
processesEntered := OrderedCollection new. |
1690 | 211 |
monitorSema := Semaphore new: 1. |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
212 |
processesWaiting := Dictionary new. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
213 |
waitingSema := Semaphore new: 0. |
1690 | 214 |
waitEnabled := true. |
215 |
ownerPrintString := owningObject class name , '@' , owningObject identityHash printString. |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
216 |
|
1690 | 217 |
"Created: / 30-11-2011 / 20:39:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
218 |
"Modified: / 10-05-2012 / 10:12:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1142 | 219 |
! ! |
220 |
||
221 |
!JavaMonitor methodsFor:'public'! |
|
222 |
||
223 |
acquire |
|
224 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
225 |
thisProcess := self activeProcess. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
226 |
(self isOwnedBy: thisProcess) ifTrue: [ |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
227 |
self increment. |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
228 |
^ self |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
229 |
]. |
1142 | 230 |
monitorSema wait. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
231 |
self owningProcess: thisProcess. |
1690 | 232 |
self reinitCounter. |
1142 | 233 |
|
234 |
"Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
235 |
! |
|
236 |
||
237 |
enter |
|
238 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
239 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
240 |
self addProcess: thisProcess. |
1142 | 241 |
self acquire. |
242 |
||
243 |
"Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
244 |
! |
|
245 |
||
246 |
exit |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
247 |
| thisProcess | |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
248 |
thisProcess := self activeProcess. |
1169 | 249 |
(self isOwnedBy: thisProcess) ifTrue: [ self release. ]. |
250 |
processesEntered remove: thisProcess ifAbsent: nil. |
|
1142 | 251 |
|
252 |
"Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
253 |
! |
|
254 |
||
1146 | 255 |
notify |
256 |
"wakeup one waiting process" |
|
257 |
||
258 |
| thisProcess | |
|
259 |
thisProcess := Processor activeProcess. |
|
1179 | 260 |
self assert: (self isOwnedBy: thisProcess). |
261 |
Logger |
|
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
262 |
log: ('%1: notifying %2 processes' bindWith: thisProcess printString |
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
263 |
with: processesWaiting size) |
1179 | 264 |
severity: #debug |
265 |
facility: #JVM. |
|
1146 | 266 |
waitingSema signal. |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
267 |
Processor yield. |
1146 | 268 |
|
269 |
"Created: / 22-11-2011 / 12:14:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
270 |
! |
|
271 |
||
272 |
notifyAll |
|
273 |
"wakeup one waiting process" |
|
274 |
||
275 |
| thisProcess | |
|
276 |
thisProcess := Processor activeProcess. |
|
277 |
self assert: (self isOwnedBy: thisProcess). |
|
1181
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
278 |
Logger |
1199 | 279 |
log: ('%1: notifying all %2 processes' bindWith: thisProcess printString |
280 |
with: processesWaiting size) |
|
281 |
severity: #debug |
|
282 |
facility: #JVM. |
|
1146 | 283 |
waitingSema signalForAll. |
1199 | 284 |
Processor yield. |
1146 | 285 |
|
286 |
"Created: / 22-11-2011 / 12:14:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
287 |
! |
|
288 |
||
1142 | 289 |
release |
290 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
291 |
thisProcess := self activeProcess. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
292 |
self assert: (self isOwnedBy: owningProcess). |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
293 |
count == 1 ifTrue: [ |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
294 |
self clearOwningProcess. |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
295 |
monitorSema signal. |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
296 |
] ifFalse: [ |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
297 |
self decrement. |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
298 |
] |
1142 | 299 |
|
300 |
"Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1146 | 301 |
! |
302 |
||
303 |
releaseAll |
|
304 |
count timesRepeat: [self release]. |
|
305 |
||
306 |
"Created: / 22-11-2011 / 13:05:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
307 |
! |
|
308 |
||
309 |
wait |
|
310 |
"make owning process to go to wait" |
|
311 |
||
312 |
self waitForMilliseconds: nil. |
|
313 |
||
314 |
"Created: / 22-11-2011 / 11:57:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
315 |
! |
|
316 |
||
317 |
waitForMilliseconds: timeOut |
|
318 |
"make owning process to go to wait, but not longer than timeout" |
|
319 |
||
320 |
| thisProcess | |
|
321 |
thisProcess := Processor activeProcess. |
|
322 |
self assert: (self isOwnedBy: thisProcess). |
|
1195 | 323 |
self waitEnabled ifFalse: [ |
324 |
Logger |
|
325 |
log: ('%1 wanted to go to sleep, but it cant, this monitor is for %2 which is already dead' |
|
326 |
bindWith: thisProcess printString |
|
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
327 |
with: ownerPrintString) |
1195 | 328 |
severity: #debug |
329 |
facility: #JVM. |
|
330 |
^ self. |
|
331 |
]. |
|
1179 | 332 |
Logger |
1195 | 333 |
log: ('%1 is going to wait on %3 for timeout: %2' |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
334 |
bindWith: thisProcess printString |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
335 |
with: timeOut |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
336 |
with: ownerPrintString printString) |
1181
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
337 |
severity: #debug |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
338 |
facility: #JVM. |
1146 | 339 |
self processesWaitingAdd: thisProcess. |
340 |
self releaseAll. |
|
1169 | 341 |
"JV@2011-11-25: zero timeout means wait without timeout!!!!!!" |
342 |
timeOut == 0 ifTrue: [ waitingSema wait ] ifFalse: [ |
|
1159 | 343 |
waitingSema waitWithTimeoutMs: timeOut |
344 |
]. |
|
1179 | 345 |
Logger |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
346 |
log: ('%1 has been notified and is trying to acquire monitor for %2 which is owned by %3' |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
347 |
bindWith: thisProcess printString with: ownerPrintString printString with: owningProcess printString) |
1179 | 348 |
severity: #debug |
349 |
facility: #JVM. |
|
1146 | 350 |
self acquire. |
351 |
self processesWaitingRestore: thisProcess. |
|
352 |
||
353 |
"Created: / 22-11-2011 / 12:52:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
354 |
"Modified: / 01-12-2011 / 10:57:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
355 |
"Modified: / 10-05-2012 / 00:24:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1142 | 356 |
! ! |
357 |
||
358 |
!JavaMonitor methodsFor:'queries'! |
|
359 |
||
360 |
isAcquired |
|
1172 | 361 |
^ instVarAccess critical: [ owningProcess notNil ]. |
1142 | 362 |
|
363 |
"Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
364 |
! |
|
365 |
||
366 |
isOwnedBy: aProcess |
|
1172 | 367 |
^ instVarAccess critical: [ owningProcess == aProcess ]. |
1142 | 368 |
|
369 |
"Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
370 |
! ! |
|
371 |
||
372 |
!JavaMonitor class methodsFor:'documentation'! |
|
373 |
||
374 |
version_SVN |
|
375 |
^ '$Id$' |
|
376 |
! ! |
|
1172 | 377 |
|
378 |
JavaMonitor initialize! |