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