author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 30 Aug 2017 12:38:37 +0100 | |
branch | jv |
changeset 23084 | 0ffb59b273ff |
parent 23083 | c8dcd89b9cf6 |
child 23085 | 9effc2bcf8a6 |
permissions | -rw-r--r-- |
330 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
341 | 3 |
All Rights Reserved |
330 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
5735 | 13 |
|
18748 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
16 |
AbstractLock subclass:#RecursionLock |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
17 |
instanceVariableNames:'' |
776 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Kernel-Processes' |
|
330 | 21 |
! |
22 |
||
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
23 |
!RecursionLock primitiveDefinitions! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
24 |
%{ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
25 |
#define THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
26 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
27 |
# include <thinlocks.h> |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
28 |
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
|
29 |
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
|
30 |
} |
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 |
#endif |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
33 |
%} |
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 |
|
330 | 36 |
!RecursionLock class methodsFor:'documentation'! |
37 |
||
699 | 38 |
copyright |
39 |
" |
|
40 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
41 |
All Rights Reserved |
|
42 |
||
43 |
This software is furnished under a license and may be used |
|
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
49 |
" |
|
50 |
||
51 |
! |
|
52 |
||
330 | 53 |
documentation |
54 |
" |
|
55 |
like a Semaphore for mutual exclusion, but avoids the deadlock |
|
56 |
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
|
57 |
I.e. allows reentering the critical region IFF the current process |
341 | 58 |
is the one which did the original locking. |
330 | 59 |
|
3524 | 60 |
WARNING: |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
61 |
for now, recursionLocks are not unlocked when an image is |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
62 |
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
|
63 |
(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
|
64 |
the #earlyRestart handling does not hurt) |
1294 | 65 |
|
66 |
[author:] |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
67 |
Claus Gittinger |
1294 | 68 |
|
1273 | 69 |
[see also:] |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
70 |
Semaphore |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
71 |
Process ProcessorScheduler |
1273 | 72 |
" |
73 |
! |
|
74 |
||
75 |
examples |
|
76 |
" |
|
2143 | 77 |
example (good): |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
78 |
[exBegin] |
2143 | 79 |
|lock| |
776 | 80 |
|
2143 | 81 |
lock := RecursionLock new. |
82 |
lock critical:[ |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
83 |
Transcript showCR:'in lock ...'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
84 |
lock critical:[ |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
85 |
Transcript showCR:'again ...' |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
86 |
] |
2143 | 87 |
] |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
88 |
[exEnd] |
776 | 89 |
|
2143 | 90 |
in contrast to (wrong example - deadlocks): |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
91 |
[exBegin] |
2143 | 92 |
|lock| |
776 | 93 |
|
2143 | 94 |
lock := Semaphore forMutualExclusion. |
95 |
lock critical:[ |
|
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
96 |
Transcript showCR:'in lock ...'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
97 |
lock critical:[ |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
98 |
'*** never reached - deadlock because sema is already locked ***'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
99 |
' (press CTRL-c and abort in the debugger)'. |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
100 |
Transcript showCR:'again ...' |
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
101 |
] |
2143 | 102 |
] |
6552
5ebab8a33da9
Moved from libbasic2 to libbasic
Stefan Vogel <sv@exept.de>
parents:
5735
diff
changeset
|
103 |
[exEnd] |
330 | 104 |
" |
105 |
! ! |
|
106 |
||
107 |
!RecursionLock class methodsFor:'instance creation'! |
|
108 |
||
5735 | 109 |
forMutualExclusion |
18748 | 110 |
"same as new, for easy exchangability with regular mutual-exclusion Semaphores." |
5735 | 111 |
|
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
112 |
^ self new |
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
113 |
! ! |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
114 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
115 |
!RecursionLock methodsFor:'accessing'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
116 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
117 |
count |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
118 |
^ 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
|
119 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
120 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
121 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
122 |
owner |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
123 |
^ 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
|
124 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
125 |
! ! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
126 |
|
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
127 |
!RecursionLock methodsFor:'acquire & release'! |
5735 | 128 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
129 |
acquireWithTimeoutMs: timeout |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
130 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
131 |
Acquire the lock: |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
132 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
133 |
* 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
|
134 |
* 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
|
135 |
* 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
|
136 |
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
|
137 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
138 |
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
|
139 |
timed out) |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
140 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
141 |
%{ /* NOCONTEXT */ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
142 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
143 |
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
|
144 |
return (true); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
145 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
146 |
#endif |
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 |
"/ 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
|
149 |
"/ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
150 |
"/ 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
|
151 |
"/ 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
|
152 |
"/ 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
|
153 |
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
|
154 |
^ super acquireWithTimeoutMs: timeout |
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 |
|
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
157 |
release |
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
158 |
" |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
" |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
162 |
%{ /* NOCONTEXT */ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
163 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
164 |
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
|
165 |
return (true); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
166 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
167 |
#endif |
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 |
"/ 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
|
170 |
"/ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
171 |
"/ 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
|
172 |
"/ 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
|
173 |
"/ 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
|
174 |
"/ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
175 |
"/ 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
|
176 |
"/ 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
|
177 |
"/ 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
|
178 |
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
|
179 |
super release ifFalse:[ |
23083
c8dcd89b9cf6
Issue #94 [5/x]: introduce an `AbstractLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23082
diff
changeset
|
180 |
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
|
181 |
]. |
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
182 |
! ! |
330 | 183 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
184 |
!RecursionLock methodsFor:'initialization'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
185 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
186 |
initialize |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
187 |
super initialize. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
188 |
process := 0. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
189 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
190 |
"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
|
191 |
"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
|
192 |
! ! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
193 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
194 |
!RecursionLock methodsFor:'private'! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
195 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
196 |
inflate |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
197 |
"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
|
198 |
#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
|
199 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
200 |
Called by: |
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 |
* #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
|
203 |
is exceeded (unlikely) |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
204 |
* #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
|
205 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
206 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
207 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
208 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
209 |
| processAndCount wasBlocked | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
210 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
211 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
212 |
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
|
213 |
wasBlocked := OperatingSystem blockInterrupts. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
214 |
"/ 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
|
215 |
"/ 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
|
216 |
"/ 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
|
217 |
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
|
218 |
self processAndCountInto: processAndCount. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
219 |
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
|
220 |
count := processAndCount at: 2. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
221 |
sema setCount: 0. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
222 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
223 |
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
|
224 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
225 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
226 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
227 |
processAndCount |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
228 |
| processAndCount | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
229 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
230 |
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
|
231 |
self processAndCountInto: processAndCount. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
232 |
^ processAndCount |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
233 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
234 |
! |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
235 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
236 |
processAndCountInto: anArray |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
237 |
"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
|
238 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
239 |
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
|
240 |
be already obsolete. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
241 |
" |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
242 |
| pid cnt proc | |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
243 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
244 |
"/ 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
|
245 |
"/ 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
|
246 |
"/ 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
|
247 |
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
|
248 |
%{ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
249 |
#ifdef THINLOCKING |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
|
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
253 |
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
|
254 |
pid = nil; |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
255 |
cnt = __MKINT(0); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
256 |
} else { |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
257 |
pid = __MKINT(_pid); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
258 |
cnt = __MKINT(_cnt); |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
259 |
} |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
260 |
#endif |
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 |
pid notNil ifTrue:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
263 |
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
|
264 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
265 |
] ifFalse:[ |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
266 |
proc := process. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
267 |
cnt := count. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
268 |
]. |
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
269 |
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
|
270 |
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
|
271 |
|
330 | 272 |
! ! |
273 |
||
2722 | 274 |
!RecursionLock methodsFor:'printing & storing'! |
275 |
||
13356
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
276 |
displayOn:aGCOrStream |
2722 | 277 |
"return a string to display the receiver - include the |
13356
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
278 |
count for your convenience" |
2722 | 279 |
|
13356
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
280 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
281 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
282 |
(aGCOrStream isStream) ifFalse:[ |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
283 |
^ super displayOn:aGCOrStream |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
284 |
]. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
285 |
aGCOrStream |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
286 |
nextPutAll:self class name; |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
287 |
nextPut:$(. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
288 |
sema count printOn:aGCOrStream. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
289 |
aGCOrStream nextPutAll:' name: '. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
290 |
(self name ? 'unnamed') printOn:aGCOrStream. |
42b4aec86a14
added: #displayOn: (instead of displayString)
Stefan Vogel <sv@exept.de>
parents:
12681
diff
changeset
|
291 |
aGCOrStream nextPut:$). |
699 | 292 |
! ! |
293 |
||
1215 | 294 |
!RecursionLock methodsFor:'queries'! |
295 |
||
4938 | 296 |
numberOfWaitingProcesses |
297 |
"return the number of waiting processes" |
|
298 |
||
299 |
^ sema numberOfWaitingProcesses |
|
300 |
||
301 |
"Created: 18.4.1996 / 17:18:08 / cg" |
|
302 |
! |
|
303 |
||
7428 | 304 |
wouldBlock |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
305 |
"Check if the resource represented by the receiver is |
15550 | 306 |
already in use by another process. |
307 |
Attention: if asked without some global lock (blockedInterrupts), |
|
308 |
the returned value may be outdated right away." |
|
1215 | 309 |
|
20734 | 310 |
|p| |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
311 |
|
23084
0ffb59b273ff
Issue #94 [6/x]: refactor `RecursionLock` to use thinlocks.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
23083
diff
changeset
|
312 |
^ (p := self owner) notNil and:[Processor activeProcess ~~ p and:[p isDead not]] |
1215 | 313 |
! ! |
314 |
||
16904 | 315 |
!RecursionLock methodsFor:'signaling'! |
316 |
||
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
317 |
signal |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
318 |
self breakPoint: #jv. |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
319 |
self release ifFalse:[ |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
320 |
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
|
321 |
] |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
322 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
323 |
"Modified: / 25-08-2017 / 08:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16904 | 324 |
! ! |
325 |
||
8568 | 326 |
!RecursionLock methodsFor:'waiting'! |
330 | 327 |
|
16904 | 328 |
wait |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
329 |
self breakPoint: #jv. |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
330 |
self acquire. |
16904 | 331 |
|
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
332 |
"Modified: / 25-08-2017 / 08:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
330 | 333 |
! ! |
334 |
||
699 | 335 |
!RecursionLock class methodsFor:'documentation'! |
330 | 336 |
|
1216
d7cbc6eb8dd4
critical was critical (deadlock with timeouts)
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
337 |
version |
18748 | 338 |
^ '$Header$' |
12681 | 339 |
! |
340 |
||
341 |
version_CVS |
|
18748 | 342 |
^ '$Header$' |
23082
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
343 |
! |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
344 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
345 |
version_HG |
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
346 |
|
b75aec4476a4
Issue #94 [4/x]: revamp of `RecursionLock`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
21249
diff
changeset
|
347 |
^ '$Changeset: <not expanded> $' |
330 | 348 |
! ! |
14697 | 349 |