author | hlopkmar |
Wed, 30 Nov 2011 19:52:16 +0000 | |
branch | jk_new_structure |
changeset 1194 | 9f910257b6e8 |
parent 1181 | 36396857af53 |
child 1195 | 378d34a28bd4 |
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 |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
25 |
processesWaiting waitEnabled owner' |
1172 | 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 |
|
60 |
instVarAccess := RecursionLock forMutualExclusion. |
|
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 |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
116 |
instVarAccess critical: [ waitEnabled := false ]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
117 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
118 |
"Created: / 30-11-2011 / 20:34:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
119 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
120 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
121 |
enableWait |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
122 |
instVarAccess critical: [waitEnabled := true]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
123 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
124 |
"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
|
125 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
126 |
|
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
127 |
increment |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
128 |
"owning process entered monitor again (recursion ...), lets raise our counter so we know how many times |
1172 | 129 |
do we have to release it" |
130 |
||
131 |
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
|
132 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
133 |
"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
|
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 |
|
1172 | 136 |
owningProcess: aProcess |
137 |
instVarAccess critical: [ owningProcess := aProcess ]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
138 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
139 |
"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
|
140 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
141 |
|
1146 | 142 |
processesWaitingAdd: aProcess |
1172 | 143 |
instVarAccess |
144 |
critical: [ |
|
145 |
self assert: (processesWaiting includesKey: aProcess) not. |
|
146 |
processesWaiting at: aProcess put: count |
|
147 |
]. |
|
1146 | 148 |
|
149 |
"Created: / 22-11-2011 / 11:57:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
150 |
! |
|
151 |
||
152 |
processesWaitingRestore: aProcess |
|
1172 | 153 |
instVarAccess |
154 |
critical: [ |
|
155 |
self assert: (processesWaiting includesKey: aProcess). |
|
156 |
self reinitCounter: (processesWaiting at: aProcess). |
|
157 |
processesWaiting removeKey: aProcess |
|
158 |
]. |
|
1146 | 159 |
|
160 |
"Created: / 22-11-2011 / 12:59:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
161 |
! |
|
162 |
||
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
163 |
reinitCounter |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
164 |
"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
|
165 |
|
1172 | 166 |
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
|
167 |
|
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
168 |
"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
|
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 |
|
1146 | 171 |
reinitCounter: newCount |
1172 | 172 |
instVarAccess critical: [ count := newCount ]. |
1146 | 173 |
|
174 |
"Created: / 22-11-2011 / 13:00:51 / 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 |
removeProcess: aProcess |
1172 | 178 |
instVarAccess |
1146 | 179 |
critical: [ |
180 |
self assert: processesEntered last == aProcess. |
|
181 |
processesEntered remove: aProcess |
|
182 |
]. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
183 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
184 |
"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
|
185 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
186 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
187 |
waitEnabled |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
188 |
instVarAccess critical: [ ^ waitEnabled]. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
189 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
190 |
"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
|
191 |
! ! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
192 |
|
1142 | 193 |
!JavaMonitor methodsFor:'initialization'! |
194 |
||
195 |
initialize |
|
196 |
owningProcess := nil. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
197 |
processesEntered := OrderedCollection new. |
1142 | 198 |
monitorSema := Semaphore new: 1. |
1146 | 199 |
processesWaiting := Dictionary new. |
200 |
waitingSema := Semaphore new: 0. |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
201 |
waitEnabled. |
1142 | 202 |
|
203 |
"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
|
204 |
! |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
205 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
206 |
initializeFor: owningObject |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
207 |
owningProcess := nil. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
208 |
processesEntered := OrderedCollection new. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
209 |
monitorSema := Semaphore new: 1. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
210 |
processesWaiting := Dictionary new. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
211 |
waitingSema := Semaphore new: 0. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
212 |
waitEnabled := true. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
213 |
owner := owningObject. |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
214 |
|
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
215 |
"Created: / 30-11-2011 / 20:39:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1142 | 216 |
! ! |
217 |
||
218 |
!JavaMonitor methodsFor:'public'! |
|
219 |
||
220 |
acquire |
|
221 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
222 |
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
|
223 |
(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
|
224 |
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
|
225 |
^ self |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
226 |
]. |
1142 | 227 |
monitorSema wait. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
228 |
self owningProcess: thisProcess. |
1145
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
229 |
self reinitCounter. |
1142 | 230 |
|
231 |
"Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
232 |
! |
|
233 |
||
234 |
enter |
|
235 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
236 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
237 |
self addProcess: thisProcess. |
1142 | 238 |
self acquire. |
239 |
||
240 |
"Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
241 |
! |
|
242 |
||
243 |
exit |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
244 |
| thisProcess | |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
245 |
thisProcess := self activeProcess. |
1169 | 246 |
(self isOwnedBy: thisProcess) ifTrue: [ self release. ]. |
247 |
processesEntered remove: thisProcess ifAbsent: nil. |
|
1142 | 248 |
|
249 |
"Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
250 |
! |
|
251 |
||
1146 | 252 |
notify |
253 |
"wakeup one waiting process" |
|
254 |
||
255 |
| thisProcess | |
|
256 |
thisProcess := Processor activeProcess. |
|
1179 | 257 |
self assert: (self isOwnedBy: thisProcess). |
258 |
Logger |
|
259 |
log: ('%1: notifying %2 processes' bindWith: thisProcess printString with:processesWaiting size) |
|
260 |
severity: #debug |
|
261 |
facility: #JVM. |
|
1146 | 262 |
waitingSema signal. |
263 |
||
264 |
"Created: / 22-11-2011 / 12:14:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
265 |
! |
|
266 |
||
267 |
notifyAll |
|
268 |
"wakeup one waiting process" |
|
269 |
||
270 |
| thisProcess | |
|
271 |
thisProcess := Processor activeProcess. |
|
272 |
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
|
273 |
Logger |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
274 |
log: ('%1: notifying all %2 processes' bindWith: thisProcess printString |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
275 |
with: processesWaiting size) |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
276 |
severity: #debug |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
277 |
facility: #JVM. |
1146 | 278 |
waitingSema signalForAll. |
279 |
||
280 |
"Created: / 22-11-2011 / 12:14:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
281 |
! |
|
282 |
||
1142 | 283 |
release |
284 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
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
|
290 |
] ifFalse: [ |
8728f5373a48
end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents:
1144
diff
changeset
|
291 |
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
|
292 |
] |
1142 | 293 |
|
294 |
"Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1146 | 295 |
! |
296 |
||
297 |
releaseAll |
|
298 |
count timesRepeat: [self release]. |
|
299 |
||
300 |
"Created: / 22-11-2011 / 13:05:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
301 |
! |
|
302 |
||
303 |
wait |
|
304 |
"make owning process to go to wait" |
|
305 |
||
306 |
self waitForMilliseconds: nil. |
|
307 |
||
308 |
"Created: / 22-11-2011 / 11:57:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
309 |
! |
|
310 |
||
311 |
waitForMilliseconds: timeOut |
|
312 |
"make owning process to go to wait, but not longer than timeout" |
|
313 |
||
314 |
| thisProcess | |
|
315 |
thisProcess := Processor activeProcess. |
|
316 |
self assert: (self isOwnedBy: thisProcess). |
|
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
317 |
self waitEnabled ifFalse: [Logger log:( '%1 wanted to go to sleep, but it cant, this monitor is for %2 which is already dead' bindWith: thisProcess printString with: owner printString) severity: #debug facility:#JVM. ^self.]. |
1179 | 318 |
Logger |
1194
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
319 |
log: ('%1 is going to wait for timeout: %2' |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
320 |
bindWith: thisProcess printString |
9f910257b6e8
from now on joining thread does not block after threads death
hlopkmar
parents:
1181
diff
changeset
|
321 |
with: timeOut) |
1181
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
322 |
severity: #debug |
36396857af53
more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents:
1179
diff
changeset
|
323 |
facility: #JVM. |
1146 | 324 |
self processesWaitingAdd: thisProcess. |
325 |
self releaseAll. |
|
1169 | 326 |
"JV@2011-11-25: zero timeout means wait without timeout!!!!!!" |
327 |
timeOut == 0 ifTrue: [ waitingSema wait ] ifFalse: [ |
|
1159 | 328 |
waitingSema waitWithTimeoutMs: timeOut |
329 |
]. |
|
1179 | 330 |
Logger |
331 |
log: ('%1 has been notified and continues' |
|
332 |
bindWith: thisProcess printString) |
|
333 |
severity: #debug |
|
334 |
facility: #JVM. |
|
1146 | 335 |
self acquire. |
336 |
self processesWaitingRestore: thisProcess. |
|
337 |
||
338 |
"Created: / 22-11-2011 / 12:52:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1159 | 339 |
"Modified (comment): / 25-11-2011 / 18:30:59 / 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
|
340 |
"Modified: / 30-11-2011 / 20:38:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1142 | 341 |
! ! |
342 |
||
343 |
!JavaMonitor methodsFor:'queries'! |
|
344 |
||
345 |
isAcquired |
|
1172 | 346 |
^ instVarAccess critical: [ owningProcess notNil ]. |
1142 | 347 |
|
348 |
"Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
349 |
! |
|
350 |
||
351 |
isOwnedBy: aProcess |
|
1172 | 352 |
^ instVarAccess critical: [ owningProcess == aProcess ]. |
1142 | 353 |
|
354 |
"Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
355 |
! ! |
|
356 |
||
357 |
!JavaMonitor class methodsFor:'documentation'! |
|
358 |
||
359 |
version_SVN |
|
360 |
^ '$Id$' |
|
361 |
! ! |
|
1172 | 362 |
|
363 |
JavaMonitor initialize! |