author | Jan Vrany <jan.vrany@labware.com> |
Wed, 02 Aug 2023 13:04:52 +0100 | |
branch | jv |
changeset 25462 | 548cb62b20c7 |
parent 25415 | 4ea1fe7c363f |
permissions | -rw-r--r-- |
330 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
23107 | 3 |
COPYRIGHT (c) 2017 Jan Vrany |
341 | 4 |
All Rights Reserved |
330 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
5735 | 14 |
|
18748 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
17 |
AbstractLock subclass:#RecursionLock |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
18 |
instanceVariableNames:'' |
776 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Kernel-Processes' |
|
330 | 22 |
! |
23 |
||
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
24 |
!RecursionLock primitiveDefinitions! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
25 |
%{ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
26 |
#define THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
27 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
28 |
# include <thinlocks.h> |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
29 |
static inline unsigned INT* stxGetLockwordPtr(OBJ o) { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
30 |
return (unsigned INT*)(&__OINST(o, process)); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
31 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
32 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
33 |
#endif |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
34 |
%} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
35 |
! ! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
36 |
|
330 | 37 |
!RecursionLock class methodsFor:'documentation'! |
38 |
||
699 | 39 |
copyright |
40 |
" |
|
41 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
23107 | 42 |
COPYRIGHT (c) 2017 Jan Vrany |
699 | 43 |
All Rights Reserved |
44 |
||
45 |
This software is furnished under a license and may be used |
|
46 |
only in accordance with the terms of that license and with the |
|
47 |
inclusion of the above copyright notice. This software may not |
|
48 |
be provided or otherwise made available to, or used by, any |
|
49 |
other person. No title to or ownership of the software is |
|
50 |
hereby transferred. |
|
51 |
" |
|
52 |
||
53 |
! |
|
54 |
||
330 | 55 |
documentation |
56 |
" |
|
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
57 |
Like a Semaphore for mutual exclusion, but avoids the deadlock |
330 | 58 |
if a critical region is reentered by the same process again. |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
59 |
I.e. allows reentering the critical region IFF the current process |
341 | 60 |
is the one which did the original locking. |
330 | 61 |
|
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
62 |
NOTE: |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
63 |
The recursion lock is not only reentrant (same process may enter the |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
64 |
critical section multiple times) but also much faster than using |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
65 |
semaphore (`lock := Semaphore forMutualExclusion. lock critical:[...]`) |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
66 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
67 |
Therefore you're encouraged to use `RecursonLock` rather than |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
68 |
`Semaphore forMutualExclusion` whenever possible. |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
69 |
|
3524 | 70 |
WARNING: |
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
71 |
For now, recursionLocks are not unlocked when an image is |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
72 |
restarted. You may have to recreate them to avoid a deadLock. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
73 |
(this may change in the future, but recreating a recursionLock in |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
74 |
the #earlyRestart handling does not hurt) |
1294 | 75 |
|
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
76 |
Thinlocks |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
77 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
78 |
RecursionLocks uses `thinlocks`[1] to optimize locking in the common |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
79 |
case - this makes it much faster. |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
80 |
The `lockword` is stored in `process` instvar - when a `process` instvar |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
81 |
contains a small integer, recursion lock is `thin`, value of `count` instvas |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
82 |
is invalid (out of sync). |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
83 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
84 |
[1]: David F. Bacon, Ravi Konuru, Chet Murthy, Mauricio Serrano: |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
85 |
Thin locks: featherweight synchronization for Java, ACM SIGPLAN 1998 |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
86 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
87 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
88 |
|
1294 | 89 |
[author:] |
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
90 |
Claus Gittinger |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
91 |
Jan Vrany (thinlock suppot) |
1294 | 92 |
|
1273 | 93 |
[see also:] |
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
94 |
Semaphore |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
95 |
Process ProcessorScheduler |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
96 |
AbstractLock |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
97 |
thinlocks.h |
1273 | 98 |
" |
99 |
! |
|
100 |
||
101 |
examples |
|
102 |
" |
|
2143 | 103 |
example (good): |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
104 |
[exBegin] |
2143 | 105 |
|lock| |
776 | 106 |
|
2143 | 107 |
lock := RecursionLock new. |
108 |
lock critical:[ |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
109 |
Transcript showCR:'in lock ...'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
110 |
lock critical:[ |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
111 |
Transcript showCR:'again ...' |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
112 |
] |
2143 | 113 |
] |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
114 |
[exEnd] |
776 | 115 |
|
2143 | 116 |
in contrast to (wrong example - deadlocks): |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
117 |
[exBegin] |
2143 | 118 |
|lock| |
776 | 119 |
|
2143 | 120 |
lock := Semaphore forMutualExclusion. |
121 |
lock critical:[ |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
122 |
Transcript showCR:'in lock ...'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
123 |
lock critical:[ |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
124 |
'*** never reached - deadlock because sema is already locked ***'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
125 |
' (press CTRL-c and abort in the debugger)'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
126 |
Transcript showCR:'again ...' |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
127 |
] |
2143 | 128 |
] |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
129 |
[exEnd] |
330 | 130 |
" |
131 |
! ! |
|
132 |
||
133 |
!RecursionLock class methodsFor:'instance creation'! |
|
134 |
||
5735 | 135 |
forMutualExclusion |
18748 | 136 |
"same as new, for easy exchangability with regular mutual-exclusion Semaphores." |
5735 | 137 |
|
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
138 |
^ self new |
25415
4ea1fe7c363f
Cherry-picked changes from eXept, part 1
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
139 |
|
4ea1fe7c363f
Cherry-picked changes from eXept, part 1
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
140 |
! |
4ea1fe7c363f
Cherry-picked changes from eXept, part 1
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
141 |
|
4ea1fe7c363f
Cherry-picked changes from eXept, part 1
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
142 |
name:aString |
4ea1fe7c363f
Cherry-picked changes from eXept, part 1
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
143 |
^ self new name:aString |
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
144 |
! ! |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
145 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
146 |
!RecursionLock methodsFor:'accessing'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
147 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
148 |
count |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
149 |
^ self processAndCount at: 2. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
150 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
151 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
152 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
153 |
owner |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
154 |
^ self processAndCount at: 1. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
155 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
156 |
! ! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
157 |
|
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
158 |
!RecursionLock methodsFor:'acquire & release'! |
5735 | 159 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
160 |
acquireWithTimeoutMs: timeout |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
161 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
162 |
Acquire the lock: |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
163 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
164 |
* If the lock is not owned by any process, lock it and return immediately. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
165 |
* If the lock is already owned by the calling process, return immediately. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
166 |
* Otherwise, wait until owning process release it (by means of #release) |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
167 |
at most `timeout` milliseconds. If `timeout` is nil, wait forever. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
168 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
169 |
Return `true` if the lock has been acquired or `false` if bot (e.g. wait |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
170 |
timed out) |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
171 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
172 |
%{ /* NOCONTEXT */ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
173 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
174 |
if ( stxThinLock( stxGetLockwordPtr(self) ) == StxThinlockSuccess ) { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
175 |
return (true); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
176 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
177 |
#endif |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
178 |
%}. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
179 |
"/ Inflate the lock if it's not yet inflated. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
180 |
"/ |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
181 |
"/ Note that #inflate method checks again if it's inflated or not, |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
182 |
"/ it may haopen some other thread inflated the lock in between the check |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
183 |
"/ here and code in #inflate. |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
184 |
"/ |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
185 |
"/ Note that `someobject class == SmallInteger` is handled as a special |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
186 |
"/ case in stc and compiled as `__isSmallInteger(someobject)` and thus |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
187 |
"/ very fast - just bitwise and + non-zero test. Don't change. |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
188 |
process class == SmallInteger ifTrue:[ self inflate ]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
189 |
^ super acquireWithTimeoutMs: timeout |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
190 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
191 |
|
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
192 |
release |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
193 |
" |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
194 |
Release the lock. Return true of lock has been released, `false` if |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
195 |
not (because calling process does not own it). |
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
196 |
" |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
197 |
%{ /* NOCONTEXT */ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
198 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
199 |
if ( stxThinUnlock( stxGetLockwordPtr(self) ) == StxThinlockSuccess ) { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
200 |
return (true); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
201 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
202 |
#endif |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
203 |
%}. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
204 |
"/ Inflate the lock if it's not yet inflated. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
205 |
"/ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
206 |
"/ Note that #inflate method checks again if it's inflated or not, |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
207 |
"/ it may haopen some other thread inflated the lock in between the check |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
208 |
"/ here and code in #inflate |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
209 |
"/ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
210 |
"/ Note that `someobject class == SmallInteger` is handled as a special |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
211 |
"/ case in stc and compiled as `__isSmallInteger(someobject)` and thus |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
212 |
"/ very fast - just bitwise and + non-zero test. Don't change. |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
213 |
process class == SmallInteger ifTrue:[ self inflate ]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
214 |
super release ifFalse:[ |
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
215 |
self error: ('Calling process does not own the lock (caller: %1, owner: %2)' bindWith: Processor activeProcess id with: (process isNil ifTrue:['<no owner>'] ifFalse:[process id])). |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
216 |
]. |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
217 |
! ! |
330 | 218 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
219 |
!RecursionLock methodsFor:'initialization'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
220 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
221 |
initialize |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
222 |
super initialize. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
223 |
process := 0. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
224 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
225 |
"Modified: / 25-01-1997 / 00:19:15 / cg" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
226 |
"Modified: / 29-08-2017 / 09:53:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
227 |
! ! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
228 |
|
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
229 |
!RecursionLock methodsFor:'printing & storing'! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
230 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
231 |
displayOn:aGCOrStream |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
232 |
"return a string to display the receiver - include the |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
233 |
count for your convenience" |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
234 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
235 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
236 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
237 |
(aGCOrStream isStream) ifFalse:[ |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
238 |
^ super displayOn:aGCOrStream |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
239 |
]. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
240 |
aGCOrStream |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
241 |
nextPutAll:self class name; |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
242 |
nextPut:$(. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
243 |
sema count printOn:aGCOrStream. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
244 |
aGCOrStream nextPutAll:' name: '. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
245 |
(self name ? 'unnamed') printOn:aGCOrStream. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
246 |
aGCOrStream nextPut:$). |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
247 |
! ! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
248 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
249 |
!RecursionLock methodsFor:'private'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
250 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
251 |
inflate |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
252 |
"Inflates (thin) lock (into fat lock). If the lock is already a fat lock, |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
253 |
#inflate is no-op. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
254 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
255 |
Called by: |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
256 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
257 |
* #acquire* in case of contention or if maximum nesting count |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
258 |
is exceeded (unlikely) |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
259 |
* #release in case of contention |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
260 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
261 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
262 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
263 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
264 |
| processAndCount wasBlocked | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
265 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
266 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
267 |
processAndCount := Array new: 2. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
268 |
wasBlocked := OperatingSystem blockInterrupts. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
269 |
"/ Note that `someobject class == SmallInteger` is handled as a special |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
270 |
"/ case in stc and compiled as `__isSmallInteger(someobject)` and thus |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
271 |
"/ very fast - just bitwise and + non-zero test. Don't change |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
272 |
process class == SmallInteger ifTrue:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
273 |
self processAndCountInto: processAndCount. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
274 |
process := processAndCount at: 1. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
275 |
count := processAndCount at: 2. |
23096
36e1c7a471ab
Issue 94: make #inflate safe w.r.t inflating an unlocked lock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23094
diff
changeset
|
276 |
process notNil ifTrue:[ |
36e1c7a471ab
Issue 94: make #inflate safe w.r.t inflating an unlocked lock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23094
diff
changeset
|
277 |
sema setCount: 0. |
36e1c7a471ab
Issue 94: make #inflate safe w.r.t inflating an unlocked lock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23094
diff
changeset
|
278 |
]. |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
279 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
280 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
281 |
|
23096
36e1c7a471ab
Issue 94: make #inflate safe w.r.t inflating an unlocked lock
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23094
diff
changeset
|
282 |
"Modified: / 11-12-2017 / 21:40:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
283 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
284 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
285 |
processAndCount |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
286 |
| processAndCount | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
287 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
288 |
processAndCount := Array new: 2. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
289 |
self processAndCountInto: processAndCount. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
290 |
^ processAndCount |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
291 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
292 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
293 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
294 |
processAndCountInto: anArray |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
295 |
"Fills in `anArray` with owning process and nesting count. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
296 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
297 |
Note that by the time this method returns, the data in given array may |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
298 |
be already obsolete. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
299 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
300 |
| pid cnt proc | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
301 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
302 |
"/ Note that `someobject class == SmallInteger` is handled as a special |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
303 |
"/ case in stc and compiled as `__isSmallInteger(someobject)` and thus |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
304 |
"/ very fast - just bitwise and + non-zero test. Don't change! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
305 |
process class == SmallInteger ifTrue:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
306 |
%{ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
307 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
308 |
unsigned INT _pid = stxLockwordGetPid( *stxGetLockwordPtr(self) ); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
309 |
unsigned INT _cnt = stxLockwordGetCnt( *stxGetLockwordPtr(self) ); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
310 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
311 |
if (_pid == INV_PROCESS_ID) { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
312 |
pid = nil; |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
313 |
cnt = __MKINT(0); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
314 |
} else { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
315 |
pid = __MKINT(_pid); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
316 |
cnt = __MKINT(_cnt); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
317 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
318 |
#endif |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
319 |
%}. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
320 |
pid notNil ifTrue:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
321 |
proc := ObjectMemory processesKnownInVM detect:[:p|p id == pid] ifNone:[nil]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
322 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
323 |
] ifFalse:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
324 |
proc := process. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
325 |
cnt := count. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
326 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
327 |
anArray at: 1 put: proc. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
328 |
anArray at: 2 put: cnt. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
329 |
|
330 | 330 |
! ! |
331 |
||
1215 | 332 |
!RecursionLock methodsFor:'queries'! |
333 |
||
4938 | 334 |
numberOfWaitingProcesses |
335 |
"return the number of waiting processes" |
|
336 |
||
337 |
^ sema numberOfWaitingProcesses |
|
338 |
||
339 |
"Created: 18.4.1996 / 17:18:08 / cg" |
|
340 |
! |
|
341 |
||
7428 | 342 |
wouldBlock |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
343 |
"Check if the resource represented by the receiver is |
15550 | 344 |
already in use by another process. |
345 |
Attention: if asked without some global lock (blockedInterrupts), |
|
346 |
the returned value may be outdated right away." |
|
1215 | 347 |
|
20734 | 348 |
|p| |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
349 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
350 |
^ (p := self owner) notNil and:[Processor activeProcess ~~ p and:[p isDead not]] |
1215 | 351 |
! ! |
352 |
||
16904 | 353 |
!RecursionLock methodsFor:'signaling'! |
354 |
||
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
355 |
signal |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
356 |
self breakPoint: #jv. |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
357 |
self release ifFalse:[ |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
358 |
self error: 'Attempt to release a (recursion) lock by process the does not own it!!' |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
359 |
] |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
360 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
361 |
"Modified: / 25-08-2017 / 08:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16904 | 362 |
! ! |
363 |
||
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
364 |
!RecursionLock methodsFor:'synchronized evaluation'! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
365 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
366 |
critical:aBlock |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
367 |
"Evaluate aBlock as a critical region. Same process may |
23086
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
368 |
enter critical region again, i.e., nesting allowed. |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
369 |
|
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
370 |
Returns the (return) value of `aBlock` |
d3f84ef999e6
Issue #94 [8/x]: improved documentation on locking
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23085
diff
changeset
|
371 |
" |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
372 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
373 |
<exception: #unwind> |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
374 |
|
23090
58f7ca7bb385
Issue #94: simplified `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23088
diff
changeset
|
375 |
| retval | |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
376 |
|
23090
58f7ca7bb385
Issue #94: simplified `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23088
diff
changeset
|
377 |
self acquireWithTimeoutMs: nil. |
58f7ca7bb385
Issue #94: simplified `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23088
diff
changeset
|
378 |
retval := aBlock value. |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
379 |
thisContext unmarkForUnwind. |
23090
58f7ca7bb385
Issue #94: simplified `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23088
diff
changeset
|
380 |
self release. |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
381 |
^ retval |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
382 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
383 |
"Created: / 31-08-2017 / 10:12:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
384 |
! ! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
385 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
386 |
!RecursionLock methodsFor:'unwinding'! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
387 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
388 |
unwindHandlerInContext:aContext |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
389 |
aContext selector == #critical: ifTrue:[ |
23094
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
390 |
^ [ |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
391 |
"/ When unwiding a #critical: frame, there are two (only two?) |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
392 |
"/ cases: |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
393 |
"/ |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
394 |
"/ 1. the critical section is executing aand being unwound |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
395 |
"/ 2. the process calling #critical: is waiting inside #acquire... |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
396 |
"/ for some other process to release it. |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
397 |
"/ |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
398 |
"/ In the first case we have to call #release, in the second |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
399 |
"/ we MUST NOT since other process owns the lock. |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
400 |
"/ To distinguish, we check whether we own the lock or not |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
401 |
"/ by `self owner == Processor activeProcess`. |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
402 |
self owner == Processor activeProcess ifTrue:[ self release ]. |
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
403 |
] |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
404 |
]. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
405 |
self shouldNeverBeReached. |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
406 |
|
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
407 |
"Created: / 31-08-2017 / 10:11:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
23094
664a6370e264
Issue 94: fixed a bad bug in #critical: unwind mechanism.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23090
diff
changeset
|
408 |
"Modified (format): / 11-12-2017 / 11:33:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
23085
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
409 |
! ! |
9effc2bcf8a6
Issue #94 [7/x]: Optimize `RecursionLock >> #critical:`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23084
diff
changeset
|
410 |
|
8568 | 411 |
!RecursionLock methodsFor:'waiting'! |
330 | 412 |
|
16904 | 413 |
wait |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
414 |
self breakPoint: #jv. |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
415 |
self acquire. |
16904 | 416 |
|
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
417 |
"Modified: / 25-08-2017 / 08:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
330 | 418 |
! ! |
419 |
||
699 | 420 |
!RecursionLock class methodsFor:'documentation'! |
330 | 421 |
|
1216
d7cbc6eb8dd4
critical was critical (deadlock with timeouts)
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
422 |
version |
18748 | 423 |
^ '$Header$' |
12681 | 424 |
! |
425 |
||
426 |
version_CVS |
|
18748 | 427 |
^ '$Header$' |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
428 |
! |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
429 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
430 |
version_HG |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
431 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
432 |
^ '$Changeset: <not expanded> $' |
330 | 433 |
! ! |
14697 | 434 |