RecursionLock.st
author Claus Gittinger <cg@exept.de>
Wed, 22 Nov 2000 11:56:15 +0100
changeset 5724 96c2a5cf4217
parent 5104 99233ab3f6f5
child 5735 3c1f1f115640
permissions -rw-r--r--
category: and package: now send change notifications.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
330
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
341
claus
parents: 330
diff changeset
     3
	      All Rights Reserved
330
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
claus
parents:
diff changeset
    12
claus
parents:
diff changeset
    13
claus
parents:
diff changeset
    14
Object subclass:#RecursionLock
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    15
	instanceVariableNames:'process sema'
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    16
	classVariableNames:''
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    17
	poolDictionaries:''
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    18
	category:'Kernel-Processes'
330
claus
parents:
diff changeset
    19
!
claus
parents:
diff changeset
    20
claus
parents:
diff changeset
    21
!RecursionLock class methodsFor:'documentation'!
claus
parents:
diff changeset
    22
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    23
copyright
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    24
"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    26
	      All Rights Reserved
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    27
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    28
 This software is furnished under a license and may be used
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    29
 only in accordance with the terms of that license and with the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    31
 be provided or otherwise made available to, or used by, any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    32
 other person.  No title to or ownership of the software is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    33
 hereby transferred.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    34
"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    35
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    36
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    37
330
claus
parents:
diff changeset
    38
documentation
claus
parents:
diff changeset
    39
"
claus
parents:
diff changeset
    40
    like a Semaphore for mutual exclusion, but avoids the deadlock
claus
parents:
diff changeset
    41
    if a critical region is reentered by the same process again.
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    42
    I.e. allows reentering the critical region IFF the current process 
341
claus
parents: 330
diff changeset
    43
    is the one which did the original locking.
330
claus
parents:
diff changeset
    44
3524
b5fe623f0e4d warning in documentation
Claus Gittinger <cg@exept.de>
parents: 3326
diff changeset
    45
    WARNING:
b5fe623f0e4d warning in documentation
Claus Gittinger <cg@exept.de>
parents: 3326
diff changeset
    46
        for now, recursionLocks are not unlocked when an image is
b5fe623f0e4d warning in documentation
Claus Gittinger <cg@exept.de>
parents: 3326
diff changeset
    47
        restarted. You may have to recreate them to avoid a deadLock.
b5fe623f0e4d warning in documentation
Claus Gittinger <cg@exept.de>
parents: 3326
diff changeset
    48
        (this may change in the future, but recreating a recursionLock in
b5fe623f0e4d warning in documentation
Claus Gittinger <cg@exept.de>
parents: 3326
diff changeset
    49
         the #earlyRestart handling does not hurt)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    50
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    51
    [author:]
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    52
        Claus Gittinger
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    53
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    54
    [see also:]
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    55
        Semaphore
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    56
        Process ProcessorScheduler
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    57
"
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    58
!
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    59
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    60
examples
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1216
diff changeset
    61
"
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    62
  example (good):
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    63
                                                                        [exBegin]
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    64
    |lock|
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    65
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    66
    lock := RecursionLock new.
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    67
    lock critical:[
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    68
        Transcript showCR:'in lock ...'.
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    69
        lock critical:[
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    70
            Transcript showCR:'again ...'
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    71
        ]
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    72
    ]
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    73
                                                                        [exEnd]
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    74
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    75
  in contrast to (wrong example - deadlocks):
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    76
                                                                        [exBegin]
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    77
    |lock|
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    78
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    79
    lock := Semaphore forMutualExclusion.
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    80
    lock critical:[
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    81
        Transcript showCR:'in lock ...'.
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    82
        lock critical:[
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    83
            '*** never reached - deadlock because sema is already locked ***'.
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    84
            '    (press CTRL-c and abort in the debugger)'.
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    85
            Transcript showCR:'again ...'
776
f3c0c579c0d2 commentary
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    86
        ]
2143
09af9c997961 commentary
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
    87
    ]
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    88
                                                                        [exEnd]
330
claus
parents:
diff changeset
    89
"
claus
parents:
diff changeset
    90
! !
claus
parents:
diff changeset
    91
claus
parents:
diff changeset
    92
!RecursionLock class methodsFor:'instance creation'!
claus
parents:
diff changeset
    93
claus
parents:
diff changeset
    94
new
claus
parents:
diff changeset
    95
    ^ self basicNew initialize
claus
parents:
diff changeset
    96
claus
parents:
diff changeset
    97
! !
claus
parents:
diff changeset
    98
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
    99
!RecursionLock methodsFor:'printing & storing'!
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   100
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   101
displayString
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   102
    "return a string to display the receiver - include the
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   103
     count and user-friendly name for your convenience"
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   104
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   105
    ^ self class name , '(' , sema count printString , ' name: ' , (self name ? 'unnamed') , ')'
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   106
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   107
    "Created: / 28.6.1997 / 16:20:33 / cg"
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   108
    "Modified: / 14.12.1999 / 21:04:08 / cg"
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   109
!
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   110
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   111
name
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   112
    "return the semaphores userFriendly name"
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   113
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   114
    ^ sema name
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   115
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   116
    "Created: / 28.6.1997 / 16:19:40 / cg"
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   117
    "Modified: / 14.12.1999 / 21:03:46 / cg"
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   118
!
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   119
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   120
name:aString
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   121
    "set the semaphores userFriendly name"
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   122
4938
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   123
    sema name:aString
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   124
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   125
    "Created: / 28.6.1997 / 16:19:47 / cg"
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   126
    "Modified: / 14.12.1999 / 21:03:52 / cg"
2722
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   127
! !
f6c7146fced2 added naming protocol
Claus Gittinger <cg@exept.de>
parents: 2266
diff changeset
   128
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   129
!RecursionLock methodsFor:'private initialization'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   130
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   131
initialize
2266
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2263
diff changeset
   132
    sema := Semaphore forMutualExclusion name:'recursionLock'
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2263
diff changeset
   133
a94af740c68a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2263
diff changeset
   134
    "Modified: 25.1.1997 / 00:19:15 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   135
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   136
1215
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   137
!RecursionLock methodsFor:'queries'!
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   138
4938
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   139
numberOfWaitingProcesses
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   140
    "return the number of waiting processes"
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   141
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   142
    ^ sema numberOfWaitingProcesses
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   143
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   144
    "Created: 18.4.1996 / 17:18:08 / cg"
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   145
!
d5640f1c8894 Add #numberOfWaitingProcesse
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   146
1215
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   147
wouldBlock
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   148
    "return true, if the receiver would block the activeProcess
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   149
     if a wait was performed. False otherwise."
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   150
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   151
    process == Processor activeProcess ifTrue:[^ false].
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   152
    ^ sema wouldBlock
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   153
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   154
    "Created: 18.4.1996 / 17:18:08 / cg"
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   155
! !
43e8e17fd9f5 added #wouldBlock
Claus Gittinger <cg@exept.de>
parents: 1186
diff changeset
   156
330
claus
parents:
diff changeset
   157
!RecursionLock methodsFor:'wait & signal'!
claus
parents:
diff changeset
   158
claus
parents:
diff changeset
   159
critical:aBlock
claus
parents:
diff changeset
   160
    "evaluate aBlock as a critical region, but do not block,
claus
parents:
diff changeset
   161
     if this lock is already held by the current process."
claus
parents:
diff changeset
   162
3326
ffcf961d203a #critical: did not return the value of the executed block.
Stefan Vogel <sv@exept.de>
parents: 2722
diff changeset
   163
    |active retVal wasBlocked|
330
claus
parents:
diff changeset
   164
claus
parents:
diff changeset
   165
    active := Processor activeProcess.
claus
parents:
diff changeset
   166
    process == active ifTrue:[
3670
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   167
        "/ I already have the lock
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   168
        ^ aBlock value
330
claus
parents:
diff changeset
   169
    ].
3670
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   170
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   171
    "/
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   172
    "/ sema wait & process := active
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   173
    "/ and:
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   174
    "/ proces := nil & sema signal
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   175
    "/ must both be done atomic
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   176
    "/ Scenario:
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   177
    "/   ... recLock critical
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   178
    "/         got lock
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   179
    "/         evaluated
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   180
    "/         set process to nil
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   181
    "/         -> timer interrupt
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   182
    "/              recLock critical in timeOut action
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   183
    "/              process isNil
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   184
    "/                 sema wait !!!!!! DEADLOCK
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   185
    "/
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   186
    wasBlocked := OperatingSystem blockInterrupts.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   187
    sema critical:[
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   188
        [
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   189
            process := active.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   190
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   191
            retVal := aBlock value.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   192
            OperatingSystem blockInterrupts.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   193
        ] valueOnUnwindDo:[
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   194
            process := nil.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   195
        ]
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   196
    ].
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   197
    process := nil.
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   198
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   199
3326
ffcf961d203a #critical: did not return the value of the executed block.
Stefan Vogel <sv@exept.de>
parents: 2722
diff changeset
   200
    ^ retVal
1186
cf4c57ecabb8 Fix in critical: don't clear process when we didn't get the semaphore when unwinding.
Stefan Vogel <sv@exept.de>
parents: 776
diff changeset
   201
3326
ffcf961d203a #critical: did not return the value of the executed block.
Stefan Vogel <sv@exept.de>
parents: 2722
diff changeset
   202
    "Modified: / 5.3.1998 / 10:22:50 / stefan"
3670
91b4524a74b3 avoid an assignment if I already have the sema (in #critical)
Claus Gittinger <cg@exept.de>
parents: 3524
diff changeset
   203
    "Modified: / 21.7.1998 / 17:44:06 / cg"
330
claus
parents:
diff changeset
   204
! !
claus
parents:
diff changeset
   205
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   206
!RecursionLock class methodsFor:'documentation'!
330
claus
parents:
diff changeset
   207
1216
d7cbc6eb8dd4 critical was critical (deadlock with timeouts)
Claus Gittinger <cg@exept.de>
parents: 1215
diff changeset
   208
version
5104
99233ab3f6f5 comments
Claus Gittinger <cg@exept.de>
parents: 4938
diff changeset
   209
    ^ '$Header: /cvs/stx/stx/libbasic/RecursionLock.st,v 1.23 1999-12-14 20:09:38 cg Exp $'
330
claus
parents:
diff changeset
   210
! !