Delay.st
author Claus Gittinger <cg@exept.de>
Tue, 23 Apr 1996 21:33:27 +0200
changeset 1273 f8449f53a6a3
parent 1035 8e673105f9ce
child 1282 3f5eda57c516
permissions -rw-r--r--
commentary
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     1
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 92
diff changeset
     3
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     4
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     5
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     6
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     8
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     9
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    10
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    11
"
9
b07612967dfa Initial revision
claus
parents:
diff changeset
    12
b07612967dfa Initial revision
claus
parents:
diff changeset
    13
Object subclass:#Delay
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    14
	instanceVariableNames:'millisecondDelta resumtionTime delaySemaphore'
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    15
	classVariableNames:''
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    16
	poolDictionaries:''
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    17
	category:'Kernel-Processes'
9
b07612967dfa Initial revision
claus
parents:
diff changeset
    18
!
b07612967dfa Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    20
!Delay class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 92
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    35
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    37
"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    38
    Instances of Delay are used to suspend the execution of a process 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    39
    (i.e. thread) for some time interval. 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    40
    Delays can be created either for some time-interval (seconds or milliseconds), 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
    or for delaying until a specific time has reached.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    Once created, a delay is waited upon with Delay>>wait.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    44
    Notice: due to delays (both within unix AND within Smalltalk itself,
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    45
    the resumtion time will ALWAYS be after the actual delay time.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    46
    (i.e. a Delay for n-millis will actually suspend for more than n milliseconds)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    48
    Warning: currently, the implementation does not support delays longer than
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    49
    a system specific maximum - future versions may remove this limitation.
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    50
    For now, do not use delays longer than the value returned by
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    51
        OperatingSystem maximumMillisecondTimeDelta
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    52
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    53
    Also notice: the clock resolution of the operatingSystem is usually limited
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    54
    (1/100, 1/60, 1/50, or even 1/20 of a second). Thus very small delays will
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    55
    delay for at least this minimum time interval. See examples.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    56
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    57
    [see also:]
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    58
        Semaphore Process ProcessorScheduler
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    59
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    60
"
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    61
!
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    62
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    63
examples 
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    64
"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    65
    Check your systems resolution with:
778
afbb3ebde874 commentary
Claus Gittinger <cg@exept.de>
parents: 777
diff changeset
    66
    (make certain, that no other timed processes are running in the background when doing this)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    67
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    68
        |d t1 t2 res|
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    69
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    70
        Processor activeProcess priority:24.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    71
        t1 := Time millisecondClockValue.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    72
        d := Delay forMilliseconds:1.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    73
        100 timesRepeat:[d wait].
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    74
        t2 := Time millisecondClockValue.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    75
        res := (OperatingSystem millisecondTimeDeltaBetween:t2 and:t1) // 100.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    76
        Transcript show:'minimum delta is about '; show:res; showCr:' milliseconds'.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    77
        Processor activeProcess priority:8.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    78
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    79
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    80
    examples:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    81
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    82
        delaying for some time-delta:
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    83
        (notice: you cannot use this without time-errors in a loop,
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    84
         since the errors will accumulate; after 5 runs through the loop,
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    85
         more than 5 seconds have passed)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    86
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    87
                |d|
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    88
                d := Delay forMilliseconds:500.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    89
                10 timesRepeat:[d wait]
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    90
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    91
        prove:
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    92
                |d t1 t2 deltaT|
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    93
                d := Delay forMilliseconds:500.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    94
                t1 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    95
                10 timesRepeat:[
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    96
                    d wait
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    97
                ].
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    98
                t2 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    99
                deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   100
                Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds'
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   101
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   102
        delaying until a specific time is reached:
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   103
        (this can be used to fix the above problem)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   104
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   105
                |now then t1 t2 deltaT|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   106
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   107
                t1 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   108
                now := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   109
                10 timesRepeat:[
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   110
                    then := OperatingSystem millisecondTimeAdd:now and:1000.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   111
                    (Delay untilMilliseconds:then) wait.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   112
                    now := then
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   113
                ].
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   114
                t2 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   115
                deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   116
                Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds'
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   117
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   118
        instead of recreating new delays, you can also reuse it:
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   119
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   120
                |d now then t1 t2 deltaT|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   121
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   122
                t1 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   123
                now := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   124
                d := Delay new.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   125
                10 timesRepeat:[
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   126
                    then := OperatingSystem millisecondTimeAdd:now and:1000.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   127
                    d resumtionTime:then.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   128
                    d wait.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   129
                    now := then
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   130
                ].
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   131
                t2 := Time millisecondClockValue.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   132
                deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   133
                Transcript show:'average delay: '; show:deltaT // 10; showCr:' milliseconds'
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   134
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   135
! !
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   136
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   137
!Delay class methodsFor:'instance creation'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   138
38
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   139
forMilliseconds:aNumber
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   140
    "return a new Delay object for delaying aNumber milliseconds"
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   141
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   142
    ^ self new delay:aNumber
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   143
!
b07612967dfa Initial revision
claus
parents:
diff changeset
   144
38
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   145
forSeconds:aNumber
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   146
    "return a new Delay object for delaying aNumber seconds"
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   147
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   148
    ^ self new delay:(aNumber * 1000) rounded
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   149
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   150
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   151
until:anAbsoluteTime
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   152
    "return a new Delay object, that will delay the active process
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   153
     until the system has reached the time represented by the argument.
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   154
     BUG:
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   155
	due to the limited range of the millisecondTimer, this can 
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   156
	(currently) not be used for long delays. The maximum supported
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   157
	delay is returned by OperatingSystem>>maximumMillisecondTimeDelta."
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   158
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   159
    |numberOfSeconds|
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   160
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   161
    numberOfSeconds := anAbsoluteTime getSeconds - AbsoluteTime now getSeconds.
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   162
    ^ self new delay:numberOfSeconds * 1000
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   163
!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   164
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   165
untilMilliseconds:aMillisecondTime
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   166
    "return a new Delay object, that will delay the active process
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   167
     until the systems millisecond time has reached aMillisecondTime.
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   168
    "
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   169
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   170
    ^ self new resumtionTime:aMillisecondTime
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   171
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   172
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   173
!Delay class methodsFor:'queries'!
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   174
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   175
millisecondClockValue
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   176
    "for ST-80 compatibility"
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   177
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   178
    ^ Time millisecondClockValue
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   179
! !
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   180
873
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   181
!Delay class methodsFor:'waiting'!
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   182
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   183
waitForMilliseconds:aNumber
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   184
    "wait for the given number of milliseconds.
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   185
     This is a combined instance creation & wait."
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   186
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   187
    ^ (self forMilliseconds:aNumber) wait
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   188
!
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   189
873
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   190
waitForSeconds:aNumber
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   191
    "wait for the given number of seconds.
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   192
     This is a combined instance creation & wait."
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   193
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   194
    ^ (self forSeconds:aNumber) wait
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   195
! !
b07612967dfa Initial revision
claus
parents:
diff changeset
   196
b07612967dfa Initial revision
claus
parents:
diff changeset
   197
!Delay methodsFor:'accessing'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   198
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   199
delay:aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   200
    "set the millisecond delta"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   201
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   202
    millisecondDelta := aNumber.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   203
    delaySemaphore := Semaphore new.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   204
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   205
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   206
delaySemaphore
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   207
    "return the semaphore used to resume the waiting process"
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   208
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   209
    ^ delaySemaphore
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   210
!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   211
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   212
resumtionTime:aMillisecondTime
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   213
    "set the resumtion time"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   214
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   215
    resumtionTime := aMillisecondTime.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   216
    delaySemaphore := Semaphore new.
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   217
! !
b07612967dfa Initial revision
claus
parents:
diff changeset
   218
b07612967dfa Initial revision
claus
parents:
diff changeset
   219
!Delay methodsFor:'delaying'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   220
b07612967dfa Initial revision
claus
parents:
diff changeset
   221
wait
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   222
    "suspend the current process until either the relative time delta
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   223
     has passed (if millisecondDelta is non-nil), or the absolute millisecondTime
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   224
     has been reached (if resumtionTime non-nil)."
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   225
25
e34a6267c79b *** empty log message ***
claus
parents: 14
diff changeset
   226
    Processor activeProcess state:#timeWait.
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   227
    [
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   228
        millisecondDelta notNil ifTrue:[
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   229
            Processor signal:delaySemaphore afterMilliseconds:millisecondDelta.
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   230
        ] ifFalse:[
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   231
            Processor signal:delaySemaphore atMilliseconds:resumtionTime.
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   232
        ].
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   233
        delaySemaphore wait.
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   234
    ] valueUninterruptably
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   235
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   236
    "
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   237
     '1' printNewline.
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   238
     (Delay forSeconds:10) wait.
b07612967dfa Initial revision
claus
parents:
diff changeset
   239
     '2' printNewline
b07612967dfa Initial revision
claus
parents:
diff changeset
   240
    "
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   241
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   242
    "Modified: 28.2.1996 / 21:39:26 / cg"
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   243
! !
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   244
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   245
!Delay methodsFor:'early signalling'!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   246
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   247
resume
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   248
    "resume the waiter, even if the delay-time has not yet passed."
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   249
1035
8e673105f9ce care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   250
    [
8e673105f9ce care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   251
        Processor disableSemaphore:delaySemaphore.
8e673105f9ce care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   252
        delaySemaphore signal.
8e673105f9ce care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   253
    ] valueUninterruptably
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   254
1035
8e673105f9ce care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1033
diff changeset
   255
    "Modified: 28.2.1996 / 21:40:27 / cg"
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   256
! !
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   257
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   258
!Delay class methodsFor:'documentation'!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   259
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   260
version
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
   261
    ^ '$Header: /cvs/stx/stx/libbasic/Delay.st,v 1.18 1996-04-23 19:33:08 cg Exp $'
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   262
! !