author | hlopkmar |
Sun, 20 Nov 2011 20:05:29 +0000 | |
branch | jk_new_structure |
changeset 1144 | c1c59b13340e |
parent 1143 | 5e1de8c6b43e |
child 1145 | 8728f5373a48 |
permissions | -rw-r--r-- |
1142 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
4 |
SWING Research Group, Czech Technical University in Prague |
|
5 |
||
6 |
Parts of the code written by Claus Gittinger are under following |
|
7 |
license: |
|
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 |
||
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
17 |
||
18 |
Permission is hereby granted, free of charge, to any person |
|
19 |
obtaining a copy of this software and associated documentation |
|
20 |
files (the 'Software'), to deal in the Software without |
|
21 |
restriction, including without limitation the rights to use, |
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
23 |
copies of the Software, and to permit persons to whom the |
|
24 |
Software is furnished to do so, subject to the following |
|
25 |
conditions: |
|
26 |
||
27 |
The above copyright notice and this permission notice shall be |
|
28 |
included in all copies or substantial portions of the Software. |
|
29 |
||
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
37 |
OTHER DEALINGS IN THE SOFTWARE. |
|
38 |
||
39 |
[1] Code written at SWING Research Group contain a signature |
|
40 |
of one of the above copright owners. |
|
41 |
" |
|
42 |
"{ Package: 'stx:libjava' }" |
|
43 |
||
44 |
Object subclass:#JavaMonitor |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
45 |
instanceVariableNames:'owningProcess processesEntered monitorSema processesEnteredAccess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
46 |
owningProcessAccess' |
1142 | 47 |
classVariableNames:'' |
48 |
poolDictionaries:'' |
|
49 |
category:'Languages-Java-Support' |
|
50 |
! |
|
51 |
||
52 |
!JavaMonitor class methodsFor:'documentation'! |
|
53 |
||
54 |
copyright |
|
55 |
" |
|
56 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
57 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
58 |
SWING Research Group, Czech Technical University in Prague |
|
59 |
||
60 |
Parts of the code written by Claus Gittinger are under following |
|
61 |
license: |
|
62 |
||
63 |
This software is furnished under a license and may be used |
|
64 |
only in accordance with the terms of that license and with the |
|
65 |
inclusion of the above copyright notice. This software may not |
|
66 |
be provided or otherwise made available to, or used by, any |
|
67 |
other person. No title to or ownership of the software is |
|
68 |
hereby transferred. |
|
69 |
||
70 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed: |
|
71 |
||
72 |
Permission is hereby granted, free of charge, to any person |
|
73 |
obtaining a copy of this software and associated documentation |
|
74 |
files (the 'Software'), to deal in the Software without |
|
75 |
restriction, including without limitation the rights to use, |
|
76 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
77 |
copies of the Software, and to permit persons to whom the |
|
78 |
Software is furnished to do so, subject to the following |
|
79 |
conditions: |
|
80 |
||
81 |
The above copyright notice and this permission notice shall be |
|
82 |
included in all copies or substantial portions of the Software. |
|
83 |
||
84 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
85 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
86 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
87 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
88 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
89 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
90 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
91 |
OTHER DEALINGS IN THE SOFTWARE. |
|
92 |
||
93 |
[1] Code written at SWING Research Group contain a signature |
|
94 |
of one of the above copright owners. |
|
95 |
||
96 |
" |
|
97 |
! ! |
|
98 |
||
99 |
!JavaMonitor class methodsFor:'instance creation'! |
|
100 |
||
101 |
new |
|
102 |
^self basicNew initialize. |
|
103 |
||
104 |
"Created: / 20-11-2011 / 14:30:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
105 |
! ! |
|
106 |
||
107 |
!JavaMonitor methodsFor:'accessing'! |
|
108 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
109 |
activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
110 |
^ Processor activeProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
111 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
112 |
|
1142 | 113 |
copyProcessesEntered |
114 |
^ processesEntered copy. |
|
115 |
||
116 |
"Created: / 20-11-2011 / 14:45:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
117 |
! |
|
118 |
||
119 |
processesEntered |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
120 |
"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
|
121 |
^ processesEntered. |
1142 | 122 |
|
123 |
"Created: / 20-11-2011 / 13:22:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
124 |
! ! |
|
125 |
||
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
126 |
!JavaMonitor methodsFor:'atomic'! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
127 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
128 |
addProcess: aProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
129 |
processesEnteredAccess critical: [processesEntered add: aProcess]. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
130 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
131 |
"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
|
132 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
133 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
134 |
clearOwningProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
135 |
owningProcessAccess critical: [ owningProcess := nil ]. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
136 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
137 |
"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
|
138 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
139 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
140 |
owningProcess: aProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
141 |
owningProcessAccess critical: [owningProcess := aProcess]. |
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 |
"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
|
144 |
! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
145 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
146 |
removeProcess: aProcess |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
147 |
processesEnteredAccess critical: [processesEntered remove: aProcess]. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
148 |
|
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
149 |
"Created: / 20-11-2011 / 20:28:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
150 |
! ! |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
151 |
|
1142 | 152 |
!JavaMonitor methodsFor:'initialization'! |
153 |
||
154 |
initialize |
|
155 |
owningProcess := nil. |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
156 |
owningProcessAccess := Semaphore forMutualExclusion. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
157 |
processesEntered := OrderedCollection new. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
158 |
processesEnteredAccess := Semaphore forMutualExclusion. |
1142 | 159 |
monitorSema := Semaphore new: 1. |
160 |
||
161 |
"Created: / 20-11-2011 / 13:28:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
162 |
! ! |
|
163 |
||
164 |
!JavaMonitor methodsFor:'public'! |
|
165 |
||
166 |
acquire |
|
167 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
168 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
169 |
(self isOwnedBy: thisProcess) ifTrue: [ ^ self ]. |
1142 | 170 |
monitorSema wait. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
171 |
self owningProcess: thisProcess. |
1142 | 172 |
|
173 |
"Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
174 |
! |
|
175 |
||
176 |
enter |
|
177 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
178 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
179 |
self addProcess: thisProcess. |
1142 | 180 |
self acquire. |
181 |
||
182 |
"Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
183 |
! |
|
184 |
||
185 |
exit |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
186 |
| thisProcess | |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
187 |
thisProcess := self activeProcess. |
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
188 |
(self isOwnedBy: thisProcess) ifTrue: [ self release. ]. |
1142 | 189 |
processesEntered remove: thisProcess. |
190 |
||
191 |
"Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
192 |
! |
|
193 |
||
194 |
release |
|
195 |
| thisProcess | |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
196 |
thisProcess := self activeProcess. |
1142 | 197 |
self assert: thisProcess == owningProcess. |
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
198 |
self clearOwningProcess. |
1142 | 199 |
monitorSema signal. |
200 |
||
201 |
"Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
202 |
! ! |
|
203 |
||
204 |
!JavaMonitor methodsFor:'queries'! |
|
205 |
||
206 |
isAcquired |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
207 |
^ owningProcessAccess critical: [owningProcess notNil]. |
1142 | 208 |
|
209 |
"Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
210 |
! |
|
211 |
||
212 |
isOwnedBy: aProcess |
|
1143
5e1de8c6b43e
JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents:
1142
diff
changeset
|
213 |
^ owningProcessAccess critical: [ owningProcess == aProcess ]. |
1142 | 214 |
|
215 |
"Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
216 |
! ! |
|
217 |
||
218 |
!JavaMonitor class methodsFor:'documentation'! |
|
219 |
||
220 |
version_SVN |
|
221 |
^ '$Id$' |
|
222 |
! ! |