author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 05 Feb 2013 23:46:53 +0100 | |
branch | refactoring-javalibrary |
changeset 2026 | ef494c184c8b |
parent 1926 | 32f3cef32ca5 |
child 2069 | 75d40b7b986f |
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 |
|
1926
32f3cef32ca5
Improvements in Java>>flushAllJavaResources.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1864
diff
changeset
|
60 |
instVarAccess := RecursionLock forMutualExclusion. |
1172 | 61 |
|
62 |
"Created: / 29-11-2011 / 11:23:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1926
32f3cef32ca5
Improvements in Java>>flushAllJavaResources.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1864
diff
changeset
|
63 |
"Modified (format): / 09-01-2013 / 16:10:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 64 |
! ! |
65 |
||
1142 | 66 |
!JavaMonitor class methodsFor:'instance creation'! |
67 |
||
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
68 |
for: owningObject |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
69 |
^ self basicNew initializeFor: owningObject. |
1142 | 70 |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
71 |
"Created: / 30-11-2011 / 20:39:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1691 | 72 |
! |
73 |
||
74 |
for: owningObject thread: threadOrNil nestedLockCount: count |
|
75 |
^ self basicNew initializeFor: owningObject thread: threadOrNil nestedLockCount: count |
|
76 |
||
77 |
"Created: / 26-08-2012 / 17:01:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1142 | 78 |
! ! |
79 |
||
80 |
!JavaMonitor methodsFor:'accessing'! |
|
81 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
82 |
activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
83 |
^ Processor activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
84 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
85 |
|
1142 | 86 |
copyProcessesEntered |
87 |
^ processesEntered copy. |
|
88 |
||
89 |
"Created: / 20-11-2011 / 14:45:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
90 |
! |
|
91 |
||
1691 | 92 |
count |
93 |
^ count |
|
94 |
! |
|
95 |
||
1142 | 96 |
processesEntered |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
97 |
"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
|
98 |
^ processesEntered. |
1142 | 99 |
|
100 |
"Created: / 20-11-2011 / 13:22:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
101 |
! ! |
|
102 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
103 |
!JavaMonitor methodsFor:'atomic'! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
104 |
|
1172 | 105 |
addProcess: aProcess |
106 |
instVarAccess critical: [ processesEntered add: aProcess ]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
107 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
108 |
"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
|
109 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
110 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
111 |
clearOwningProcess |
1172 | 112 |
instVarAccess critical: [ owningProcess := nil ]. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
113 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
114 |
"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
|
115 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
116 |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
117 |
decrement |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
118 |
"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
|
119 |
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
|
120 |
|
1172 | 121 |
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
|
122 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
123 |
"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
|
124 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
125 |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
126 |
disableWait |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
127 |
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
|
128 |
instVarAccess critical: [ waitEnabled := false ]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
129 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
130 |
"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
|
131 |
"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
|
132 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
133 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
134 |
enableWait |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
135 |
instVarAccess critical: [waitEnabled := true]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
136 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
137 |
"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
|
138 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
139 |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
140 |
increment |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
141 |
"owning process entered monitor again (recursion ...), lets raise our counter so we know how many times |
1172 | 142 |
do we have to release it" |
143 |
||
144 |
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
|
145 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
146 |
"Created: / 22-11-2011 / 10:49:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1691 | 147 |
"Modified: / 27-08-2012 / 10:42:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
148 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
149 |
|
1172 | 150 |
owningProcess: aProcess |
151 |
instVarAccess critical: [ owningProcess := aProcess ]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
152 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
153 |
"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
|
154 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
155 |
|
1146 | 156 |
processesWaitingAdd: aProcess |
1172 | 157 |
instVarAccess |
158 |
critical: [ |
|
159 |
self assert: (processesWaiting includesKey: aProcess) not. |
|
160 |
processesWaiting at: aProcess put: count |
|
161 |
]. |
|
1146 | 162 |
|
163 |
"Created: / 22-11-2011 / 11:57:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
164 |
! |
|
165 |
||
166 |
processesWaitingRestore: aProcess |
|
1172 | 167 |
instVarAccess |
168 |
critical: [ |
|
169 |
self assert: (processesWaiting includesKey: aProcess). |
|
170 |
self reinitCounter: (processesWaiting at: aProcess). |
|
171 |
processesWaiting removeKey: aProcess |
|
172 |
]. |
|
1146 | 173 |
|
174 |
"Created: / 22-11-2011 / 12:59:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
175 |
! |
|
176 |
||
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
177 |
reinitCounter |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
178 |
"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
|
179 |
|
1172 | 180 |
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
|
181 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
182 |
"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
|
183 |
! |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
184 |
|
1146 | 185 |
reinitCounter: newCount |
1172 | 186 |
instVarAccess critical: [ count := newCount ]. |
1146 | 187 |
|
188 |
"Created: / 22-11-2011 / 13:00:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
189 |
! |
|
190 |
||
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
191 |
removeProcess: aProcess |
1172 | 192 |
instVarAccess |
1146 | 193 |
critical: [ |
194 |
self assert: processesEntered last == aProcess. |
|
195 |
processesEntered remove: aProcess |
|
196 |
]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
197 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
198 |
"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
|
199 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
200 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
201 |
waitEnabled |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
202 |
instVarAccess critical: [ ^ waitEnabled]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
203 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
204 |
"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
|
205 |
! ! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
206 |
|
1142 | 207 |
!JavaMonitor methodsFor:'initialization'! |
208 |
||
209 |
initialize |
|
210 |
owningProcess := nil. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
211 |
processesEntered := OrderedCollection new. |
1142 | 212 |
monitorSema := Semaphore new: 1. |
1146 | 213 |
processesWaiting := Dictionary new. |
214 |
waitingSema := Semaphore new: 0. |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
215 |
waitEnabled. |
1142 | 216 |
|
217 |
"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
|
218 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
219 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
220 |
initializeFor: owningObject |
1691 | 221 |
self initializeFor: owningObject thread: 0 nestedLockCount: 0. |
222 |
||
223 |
"Created: / 30-11-2011 / 20:39:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
224 |
"Modified: / 26-08-2012 / 17:25:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
225 |
! |
|
226 |
||
227 |
initializeFor:owningObject thread:threadId nestedLockCount:cnt |
|
228 |
||
229 |
"/ self assert: (owningObject isJavaObject or:[owningObject isJavaClass]). |
|
230 |
||
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
231 |
processesEntered := OrderedCollection new. |
1691 | 232 |
waitEnabled := true. |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
233 |
processesWaiting := Dictionary new. |
1691 | 234 |
waitingSema := Semaphore new:0. |
1690 | 235 |
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
|
236 |
|
1691 | 237 |
"/Not locked... |
238 |
threadId == 0 ifTrue:[ |
|
239 |
monitorSema := Semaphore new:1. |
|
240 |
count := 0. |
|
241 |
^self. |
|
242 |
] ifFalse: [ |
|
243 |
"threadId is not zero (zero is threadId of scheduler process, which will never try to acquire the monitor)" |
|
244 |
"so it means it is possible that the thin lock is already locked for other thread, we must be careful " |
|
245 |
||
246 |
owningProcess := Process findProcessWithId:threadId. |
|
247 |
self assert: owningProcess notNil. |
|
248 |
processesEntered add: owningProcess. |
|
249 |
cnt timesRepeat:[ |
|
250 |
"/ JavaVM enteredMonitorsOf: owningProcess add: owningObject. |
|
251 |
"/ JavaVM acquiredMonitorsOf: owningProcess add: owningObject. |
|
252 |
]. |
|
253 |
monitorSema := Semaphore new: 0. |
|
254 |
count := cnt. |
|
255 |
]. |
|
256 |
||
257 |
"Created: / 26-08-2012 / 17:02:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1142 | 258 |
! ! |
259 |
||
260 |
!JavaMonitor methodsFor:'public'! |
|
261 |
||
262 |
acquire |
|
263 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
264 |
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
|
265 |
(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
|
266 |
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
|
267 |
^ self |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
268 |
]. |
1142 | 269 |
monitorSema wait. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
270 |
self owningProcess: thisProcess. |
1691 | 271 |
count := 1. |
1142 | 272 |
|
273 |
"Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1691 | 274 |
"Modified: / 27-08-2012 / 11:45:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1142 | 275 |
! |
276 |
||
277 |
enter |
|
278 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
279 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
280 |
self addProcess: thisProcess. |
1142 | 281 |
self acquire. |
282 |
||
283 |
"Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
284 |
! |
|
285 |
||
286 |
exit |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
287 |
| thisProcess | |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
288 |
thisProcess := self activeProcess. |
1169 | 289 |
(self isOwnedBy: thisProcess) ifTrue: [ self release. ]. |
290 |
processesEntered remove: thisProcess ifAbsent: nil. |
|
1142 | 291 |
|
292 |
"Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1691 | 293 |
"Modified: / 26-08-2012 / 19:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1142 | 294 |
! |
295 |
||
1146 | 296 |
notify |
297 |
"wakeup one waiting process" |
|
298 |
||
299 |
| thisProcess | |
|
300 |
thisProcess := Processor activeProcess. |
|
1179 | 301 |
self assert: (self isOwnedBy: thisProcess). |
302 |
Logger |
|
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
303 |
log: ('%1: notifying %2 processes' bindWith: thisProcess printString |
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
304 |
with: processesWaiting size) |
1179 | 305 |
severity: #debug |
306 |
facility: #JVM. |
|
1146 | 307 |
waitingSema signal. |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
308 |
Processor yield. |
1146 | 309 |
|
310 |
"Created: / 22-11-2011 / 12:14:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
311 |
! |
|
312 |
||
313 |
notifyAll |
|
314 |
"wakeup one waiting process" |
|
315 |
||
316 |
| thisProcess | |
|
317 |
thisProcess := Processor activeProcess. |
|
318 |
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
|
319 |
Logger |
1199 | 320 |
log: ('%1: notifying all %2 processes' bindWith: thisProcess printString |
321 |
with: processesWaiting size) |
|
322 |
severity: #debug |
|
323 |
facility: #JVM. |
|
1146 | 324 |
waitingSema signalForAll. |
1199 | 325 |
Processor yield. |
1146 | 326 |
|
327 |
"Created: / 22-11-2011 / 12:14:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
328 |
! |
|
329 |
||
1142 | 330 |
release |
331 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
self clearOwningProcess. |
1691 | 336 |
count := 0. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
337 |
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
|
338 |
] ifFalse: [ |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
339 |
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
|
340 |
] |
1142 | 341 |
|
342 |
"Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1691 | 343 |
"Modified: / 27-08-2012 / 11:44:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1146 | 344 |
! |
345 |
||
346 |
releaseAll |
|
347 |
count timesRepeat: [self release]. |
|
348 |
||
349 |
"Created: / 22-11-2011 / 13:05:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
350 |
! |
|
351 |
||
352 |
wait |
|
353 |
"make owning process to go to wait" |
|
354 |
||
355 |
self waitForMilliseconds: nil. |
|
356 |
||
357 |
"Created: / 22-11-2011 / 11:57:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
358 |
! |
|
359 |
||
360 |
waitForMilliseconds: timeOut |
|
361 |
"make owning process to go to wait, but not longer than timeout" |
|
362 |
||
363 |
| thisProcess | |
|
364 |
thisProcess := Processor activeProcess. |
|
365 |
self assert: (self isOwnedBy: thisProcess). |
|
1195 | 366 |
self waitEnabled ifFalse: [ |
367 |
Logger |
|
368 |
log: ('%1 wanted to go to sleep, but it cant, this monitor is for %2 which is already dead' |
|
369 |
bindWith: thisProcess printString |
|
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
370 |
with: ownerPrintString) |
1195 | 371 |
severity: #debug |
372 |
facility: #JVM. |
|
373 |
^ self. |
|
374 |
]. |
|
1179 | 375 |
Logger |
1195 | 376 |
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
|
377 |
bindWith: thisProcess printString |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
378 |
with: timeOut |
1490
098c357e3c2f
- JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents:
1199
diff
changeset
|
379 |
with: ownerPrintString printString) |
1181
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
380 |
severity: #debug |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
381 |
facility: #JVM. |
1146 | 382 |
self processesWaitingAdd: thisProcess. |
383 |
self releaseAll. |
|
1169 | 384 |
"JV@2011-11-25: zero timeout means wait without timeout!!!!!!" |
385 |
timeOut == 0 ifTrue: [ waitingSema wait ] ifFalse: [ |
|
1159 | 386 |
waitingSema waitWithTimeoutMs: timeOut |
387 |
]. |
|
1179 | 388 |
Logger |
1198
2f3bec682673
discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents:
1195
diff
changeset
|
389 |
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
|
390 |
bindWith: thisProcess printString with: ownerPrintString printString with: owningProcess printString) |
1179 | 391 |
severity: #debug |
392 |
facility: #JVM. |
|
1146 | 393 |
self acquire. |
394 |
self processesWaitingRestore: thisProcess. |
|
395 |
||
396 |
"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
|
397 |
"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
|
398 |
"Modified: / 10-05-2012 / 00:24:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1142 | 399 |
! ! |
400 |
||
401 |
!JavaMonitor methodsFor:'queries'! |
|
402 |
||
403 |
isAcquired |
|
1172 | 404 |
^ instVarAccess critical: [ owningProcess notNil ]. |
1142 | 405 |
|
406 |
"Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
407 |
! |
|
408 |
||
409 |
isOwnedBy: aProcess |
|
1172 | 410 |
^ instVarAccess critical: [ owningProcess == aProcess ]. |
1142 | 411 |
|
412 |
"Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
413 |
! ! |
|
414 |
||
415 |
!JavaMonitor class methodsFor:'documentation'! |
|
416 |
||
1864 | 417 |
version_HG |
418 |
||
419 |
^ '$Changeset: <not expanded> $' |
|
420 |
! |
|
421 |
||
1142 | 422 |
version_SVN |
1864 | 423 |
^ '§Id§' |
1142 | 424 |
! ! |
1172 | 425 |
|
426 |
JavaMonitor initialize! |