SemaphoreSet.st
author Stefan Vogel <sv@exept.de>
Mon, 22 Jun 2015 11:33:37 +0200
branchexpecco_2_7_5_branch
changeset 18499 b132ac7c9d6a
parent 16287 b989ab286181
child 18120 e3a375d5f6a8
child 20185 c32b6064d503
permissions -rw-r--r--
GLIBC 2.12 compatibility
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     1
"
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     2
 COPYRIGHT (c) 1995 by Stefan Vogel / Claus Gittinger
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     3
              All Rights Reserved
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     4
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     5
 This software is furnished under a license and may be used
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     6
 only in accordance with the terms of that license and with the
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
     9
 other person.  No title to or ownership of the software is
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    10
 hereby transferred.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    11
"
5570
e6e14f50d721 category change
Claus Gittinger <cg@exept.de>
parents: 2876
diff changeset
    12
"{ Package: 'stx:libbasic' }"
e6e14f50d721 category change
Claus Gittinger <cg@exept.de>
parents: 2876
diff changeset
    13
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    14
IdentitySet subclass:#SemaphoreSet
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:''
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    18
	category:'Kernel-Processes'
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
!
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
!SemaphoreSet class methodsFor:'documentation'!
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    22
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    23
copyright
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    24
"
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    25
 COPYRIGHT (c) 1995 by Stefan Vogel / Claus Gittinger
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    26
              All Rights Reserved
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    27
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    28
 This software is furnished under a license and may be used
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    29
 only in accordance with the terms of that license and with the
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    31
 be provided or otherwise made available to, or used by, any
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    32
 other person.  No title to or ownership of the software is
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    33
 hereby transferred.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    34
"
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    35
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    36
!
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    37
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    38
documentation
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    39
"
2876
fb3fed7470be oops - must unregister from individual semaphores
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
    40
    SemaphoreSets allow waiting until one of several semaphores becomes available.
fb3fed7470be oops - must unregister from individual semaphores
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
    41
    They provide a waiting protocol which is compatible to Semaphore, 
fb3fed7470be oops - must unregister from individual semaphores
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
    42
    i.e. #wait and #waitWithTimeOut.
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
    43
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
    44
    [see also:]
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
    45
        Semaphore
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1031
diff changeset
    46
        Process ProcessorScheduler
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    47
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    48
    [author:]
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
    49
        Stefan Vogel
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    50
"
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    51
!
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    52
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    53
examples
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    54
"
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    55
 the following example forks a process which waits on any
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    56
 of sema1, sema2 to be signalled. The main thread signals those.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    57
                                                                        [exBegin]
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    58
    |sema1 sema2 semaSet proc|
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    59
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    60
    sema1 := Semaphore new.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    61
    sema2 := Semaphore new.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    62
    semaSet := SemaphoreSet with:sema1 with:sema2.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    63
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    64
    proc := [
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    65
        [
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    66
            |ret name|
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    67
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    68
            ret := semaSet wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    69
            ret == sema1 ifTrue:[
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    70
                name := 'sema1'
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    71
            ] ifFalse:[ 
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    72
                ret == sema2 ifTrue:[
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    73
                    name := 'sema2'
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    74
                ]
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    75
            ].
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
    76
            Transcript showCR: name, ' raised'.
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    77
            ret == sema2 ifTrue:[
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    78
                proc terminate
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    79
            ]
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    80
        ] loop
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    81
    ] fork.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    82
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    83
    (Delay forSeconds:3) wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    84
    sema1 signal.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    85
    (Delay forSeconds:3) wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    86
    sema2 signal.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    87
                                                                        [exEnd]
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    88
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    89
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    90
 the following example forks a process which waits on any
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
    91
 of sema1, sema2 to be signalled, or a timeout to occur.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    92
                                                                        [exBegin]
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    93
    |sema1 sema2 semaSet proc|
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    94
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    95
    sema1 := Semaphore new.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    96
    sema2 := Semaphore new.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    97
    semaSet := SemaphoreSet with:sema1 with:sema2.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    98
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
    99
    proc := [
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   100
        [
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   101
            |ret name|
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   102
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   103
            ret := semaSet waitWithTimeout:5.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   104
            ret == sema1 ifTrue:[
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   105
                name := 'sema1'
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   106
            ] ifFalse:[ 
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   107
                ret == sema2 ifTrue:[
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   108
                    name := 'sema2'
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   109
                ] ifFalse:[
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   110
                    name := ret printString
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   111
                ]
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   112
            ].
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
   113
            Transcript showCR: name, ' raised'.
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   114
            ret isNil ifTrue:[
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   115
                proc terminate
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   116
            ]
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   117
        ] loop
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   118
    ] fork.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   119
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   120
    (Delay forSeconds:3) wait.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   121
    sema1 signal.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   122
    (Delay forSeconds:3) wait.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   123
    sema2 signal.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   124
                                                                        [exEnd]
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   125
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   126
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   127
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   128
 the following example forks a process which waits on input
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   129
 to arrive on any of 2 sharedQueues (with timeout)
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   130
 The main thread writes data into those queues.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   131
                                                                        [exBegin]
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   132
    |q1 q2 semaSet proc|
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   133
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   134
    q1 := SharedQueue new.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   135
    q2 := SharedQueue new.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   136
    semaSet := SemaphoreSet with:(q1 readSemaphore) with:(q2 readSemaphore).
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   137
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   138
    proc := [
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   139
        [
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   140
            |ret whatHappened|
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   141
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   142
            ret := semaSet waitWithTimeout:5.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   143
            ret == q1 readSemaphore ifTrue:[
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   144
                Transcript show:'q1 has data: '; show:q1 next; cr.
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   145
            ] ifFalse:[ 
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   146
                ret == q2 readSemaphore ifTrue:[
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   147
                    Transcript show:'q2 has data: '; show:q2 next; cr.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   148
                ] ifFalse:[
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
   149
                    Transcript showCR:'timeout'
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   150
                ]
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   151
            ].
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   152
        ] loop
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   153
    ] fork.
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   154
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   155
    (Delay forSeconds:3) wait.
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   156
    q1 nextPut:'one'.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   157
    (Delay forSeconds:2) wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   158
    q1 nextPut:'two'.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   159
    (Delay forSeconds:2) wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   160
    q1 nextPut:'three'.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   161
    (Delay forSeconds:6) wait.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   162
    proc terminate.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   163
                                                                        [exEnd]
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   164
"
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   165
! !
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   166
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   167
!SemaphoreSet methodsFor:'waiting'!
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   168
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   169
wait
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   170
    "wait for any of the semaphores in the set to be signalled.
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   171
     Return the (first) semaphore which is triggered."
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   172
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   173
    |currentProcess gotSema wasBlocked mustUnregisterAllSemas|
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   174
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   175
    currentProcess := Processor activeProcess.
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   176
    mustUnregisterAllSemas := false.
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   177
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   178
    wasBlocked := OperatingSystem blockInterrupts.
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   179
    [
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   180
        gotSema := self detect:[:eachSema|
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   181
            eachSema checkAndAddWaitingProcess:currentProcess
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   182
        ] ifNone:[].
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   183
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   184
        gotSema isNil ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   185
            mustUnregisterAllSemas := true.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   186
            [
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   187
                currentProcess suspendWithState:#wait.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   188
            ] ifCurtailed:[
11257
9689500b7608 care for interrupts when curtailed
ca
parents: 11252
diff changeset
   189
                OperatingSystem blockInterrupts.
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   190
                self do:[:eachSema |
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   191
                    eachSema removeWaitingProcess:currentProcess.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   192
                ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   193
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   194
            ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   195
        ].
16287
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   196
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   197
        gotSema isNil
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   198
    ] whileTrue.
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   199
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   200
    "
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   201
      we finally got at least one of our semaphores.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   202
      Now unregister from any semaphore, we are registered on.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   203
    "
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   204
    self do:[:eachSema|
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   205
        (eachSema == gotSema and:[mustUnregisterAllSemas not]) ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   206
            "done with registered semaphores"
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   207
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   208
            ^ gotSema
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   209
        ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   210
        eachSema removeWaitingProcess:currentProcess.
1031
cd715f8011f0 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   211
    ].
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   212
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   213
    ^ gotSema
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   214
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   215
    "Modified: 15.12.1995 / 23:10:07 / stefan"
2876
fb3fed7470be oops - must unregister from individual semaphores
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   216
    "Modified: 20.8.1997 / 18:33:09 / cg"
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   217
!
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   218
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   219
waitWithTimeout:seconds
12698
a4e7529547bc comment/format in: #waitWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 11282
diff changeset
   220
    "wait for any of the the semaphore, but abort the wait after some time (seconds).
775
7b6c00a4708a documentation / example methods merged into one (easier to browse for category "examples")
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   221
     Return the (first) triggered semaphore if any, nil if we return due to a timeout."
770
402958905760 protocol of waitWithTImeOut: changed
Claus Gittinger <cg@exept.de>
parents: 769
diff changeset
   222
6787
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   223
    |millis|
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   224
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   225
    seconds notNil ifTrue:[
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   226
        millis := seconds * 1000 
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   227
    ].
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   228
    ^ self waitWithTimeoutMs:millis.
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   229
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   230
    "Modified: 15.12.1995 / 23:10:54 / stefan"
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   231
    "Modified: 20.8.1997 / 18:33:23 / cg"
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   232
!
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   233
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   234
waitWithTimeoutMs:milliSeconds
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   235
    "wait for any of the the semaphore, but abort the wait after some time.
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   236
     Return the (first) triggered semaphore if any, nil if we return due to a timeout."
a1703f7cd4fd waitWithTimeout: protocol as in Semaphore
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   237
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   238
    |currentProcess gotSema wasBlocked timeoutBlock timeoutOccured mustUnregisterAllSemas|
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   239
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   240
    currentProcess := Processor activeProcess.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   241
    timeoutOccured := false.
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   242
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   243
    wasBlocked := OperatingSystem blockInterrupts.
1031
cd715f8011f0 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   244
    [
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   245
        gotSema := self detect:[:eachSema|
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   246
            eachSema checkAndAddWaitingProcess:currentProcess
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   247
        ] ifNone:[].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   248
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   249
        gotSema isNil ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   250
            mustUnregisterAllSemas := true.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   251
            (milliSeconds notNil and:[timeoutBlock isNil]) ifTrue:[ 
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   252
                |now endTime|
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   253
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   254
                milliSeconds == 0 ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   255
                    "with zero-timeout, this is a poll"
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   256
                    self do:[:eachSema |
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   257
                        eachSema removeWaitingProcess:currentProcess.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   258
                    ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   259
                    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   260
                    ^ nil
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   261
                ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   262
                "calculate the end-time"
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   263
                now := OperatingSystem getMillisecondTime.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   264
                endTime := OperatingSystem millisecondTimeAdd:now and:milliSeconds.
1031
cd715f8011f0 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   265
14769
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   266
                timeoutBlock := [
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   267
                        timeoutOccured := true. 
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   268
                        timeoutBlock := nil. 
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   269
                        Processor resume:currentProcess.
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   270
                    ].
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   271
                Processor addTimedBlock:timeoutBlock for:currentProcess atMilliseconds:endTime.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   272
            ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   273
            [
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   274
                currentProcess suspendWithState:#wait.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   275
            ] ifCurtailed:[
11282
5e04b4bd310a changed #waitWithTimeoutMs: - comments
Stefan Vogel <sv@exept.de>
parents: 11257
diff changeset
   276
                "interrupts are not blocked when entered through Processor>>#interruptActive"
11257
9689500b7608 care for interrupts when curtailed
ca
parents: 11252
diff changeset
   277
                OperatingSystem blockInterrupts.
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   278
                timeoutBlock notNil ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   279
                    Processor removeTimedBlock:timeoutBlock.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   280
                    timeoutBlock := nil.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   281
                ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   282
                self do:[:eachSema |
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   283
                    eachSema removeWaitingProcess:currentProcess.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   284
                ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   285
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   286
            ].
1031
cd715f8011f0 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   287
        ].
16287
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   288
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   289
        gotSema isNil and:[timeoutOccured not]
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   290
    ] whileTrue.
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   291
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   292
    timeoutBlock notNil ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   293
        Processor removeTimedBlock:timeoutBlock.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   294
        timeoutBlock := nil.
1031
cd715f8011f0 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   295
    ].
8569
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   296
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   297
    "we finally got a timeout or at least one of our semaphores.
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   298
     Unregister from any semaphore, we are registered with"
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   299
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   300
    self do:[:eachSema|
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   301
        (eachSema == gotSema and:[mustUnregisterAllSemas not]) ifTrue:[
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   302
            "done with registered semaphores"
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   303
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   304
            ^ gotSema
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   305
        ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   306
    ].
657853ae04cd Change waitXXX
Stefan Vogel <sv@exept.de>
parents: 6787
diff changeset
   307
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
769
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   308
    ^ gotSema
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   309
84cc1b36f27e Fix cleanup after process resume in SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents: 757
diff changeset
   310
    "Modified: 15.12.1995 / 23:10:54 / stefan"
2876
fb3fed7470be oops - must unregister from individual semaphores
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   311
    "Modified: 20.8.1997 / 18:33:23 / cg"
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   312
! !
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   313
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   314
!SemaphoreSet class methodsFor:'documentation'!
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   315
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   316
version
16287
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   317
    ^ '$Header: /cvs/stx/stx/libbasic/SemaphoreSet.st,v 1.21 2014-03-28 13:39:55 stefan Exp $'
12698
a4e7529547bc comment/format in: #waitWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 11282
diff changeset
   318
!
a4e7529547bc comment/format in: #waitWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 11282
diff changeset
   319
a4e7529547bc comment/format in: #waitWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 11282
diff changeset
   320
version_CVS
16287
b989ab286181 class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 14769
diff changeset
   321
    ^ '$Header: /cvs/stx/stx/libbasic/SemaphoreSet.st,v 1.21 2014-03-28 13:39:55 stefan Exp $'
757
93d5f6b86e98 Add SemaphoreSet.
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   322
! !
14769
898e4754340b class: SemaphoreSet
Stefan Vogel <sv@exept.de>
parents: 12698
diff changeset
   323