Delay.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24198 fc537a78d136
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
     1
"{ Encoding: utf8 }"
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
     2
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     3
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 92
diff changeset
     5
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     6
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     7
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     8
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    10
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    11
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    12
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    13
"
6423
e43f6e61bfaa #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
    14
"{ Package: 'stx:libbasic' }"
e43f6e61bfaa #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
    15
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
    16
"{ NameSpace: Smalltalk }"
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
    17
9
b07612967dfa Initial revision
claus
parents:
diff changeset
    18
Object subclass:#Delay
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
    19
	instanceVariableNames:'millisecondDelta resumptionTime delaySemaphore isInterrupted'
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    20
	classVariableNames:''
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    21
	poolDictionaries:''
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    22
	category:'Kernel-Processes'
9
b07612967dfa Initial revision
claus
parents:
diff changeset
    23
!
b07612967dfa Initial revision
claus
parents:
diff changeset
    24
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    25
!Delay class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    29
 COPYRIGHT (c) 1993 by Claus Gittinger
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 92
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    40
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
    42
"
20197
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
    43
    Instances of Delay are used to suspend the execution of a process
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
    44
    (i.e. thread) for some time interval.
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
    45
    Delays can be created either for some time-interval (seconds or milliseconds),
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    46
    or for delaying until a specific time has reached.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
    Once created, a delay is waited upon with Delay>>wait.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    48
15552
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
    49
    Notice: due to delays (both within Unix AND within Smalltalk itself,
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
    50
    the resumption time will ALWAYS be after the actual delay time.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    51
    (i.e. a Delay for n-millis will actually suspend for more than n milliseconds)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
20197
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
    53
    Warning:
15552
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
    54
        currently, the implementation does not support delays longer than
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
    55
        a system specific maximum - future versions may remove this limitation.
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
    56
        For now, do not use delays longer than the value returned by
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    57
        OperatingSystem maximumMillisecondTimeDelta
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    58
15552
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
    59
    Also notice: the clock resolution of the operating system is usually limited
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    60
    (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
    61
    delay for at least this minimum time interval. See examples.
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    62
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    63
    [see also:]
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    64
        Semaphore Process ProcessorScheduler
8254
73b6109ab982 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 7590
diff changeset
    65
        Time Timestamp OperatingSystem
1348
Claus Gittinger <cg@exept.de>
parents: 1316
diff changeset
    66
        (Using delay in ``Working with time, delays and interrupts'': programming/timing.html#DELAY)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    67
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    68
    [author:]
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1282
diff changeset
    69
        Claus Gittinger
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    70
"
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    71
!
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    72
20197
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
    73
examples
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    74
"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    75
    Check your systems resolution with:
778
afbb3ebde874 commentary
Claus Gittinger <cg@exept.de>
parents: 777
diff changeset
    76
    (make certain, that no other timed processes are running in the background when doing this)
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    77
                                                                        [exBegin]
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    78
        |d t1 t2 res|
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
    79
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    80
        Processor activeProcess priority:24.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    81
        t1 := Time millisecondClockValue.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    82
        d := Delay forMilliseconds:1.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    83
        100 timesRepeat:[d wait].
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    84
        t2 := Time millisecondClockValue.
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    85
        res := (OperatingSystem millisecondTimeDeltaBetween:t2 and:t1) // 100.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
    86
        Transcript show:'minimum delta is about '; show:res; showCR:' milliseconds'.
777
452133016f54 commentary
Claus Gittinger <cg@exept.de>
parents: 695
diff changeset
    87
        Processor activeProcess priority:8.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    88
                                                                        [exEnd]
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    89
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    90
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    91
    examples:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    92
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    93
    delaying for some time-delta:
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    94
    (notice: you cannot use this without time-errors in a loop,
2179
3f633442dc34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2178
diff changeset
    95
     since the errors will accumulate; after 10 runs through the loop,
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    96
     more than 5 seconds have passed)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    97
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    98
            |d|
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
    99
            d := Delay forMilliseconds:500.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   100
            10 timesRepeat:[d wait]
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   101
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   102
    prove:
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   103
                                                                    [exBegin]
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   104
            |d t1 t2 deltaT|
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   105
            d := Delay forMilliseconds:500.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   106
            t1 := Time millisecondClockValue.
2178
e255c5cd6dc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   107
            20 timesRepeat:[
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   108
                d wait
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   109
            ].
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   110
            t2 := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   111
            deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
2178
e255c5cd6dc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   112
            Transcript show:'average delay: '; show:deltaT // 20; showCR:' milliseconds'
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   113
                                                                    [exEnd]
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   114
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   115
    delaying until a specific time is reached:
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   116
    (this can be used to fix the above problem)
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   117
                                                                    [exBegin]
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   118
            |now then t1 t2 deltaT|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   119
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   120
            t1 := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   121
            now := Time millisecondClockValue.
2178
e255c5cd6dc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   122
            20 timesRepeat:[
e255c5cd6dc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   123
                then := OperatingSystem millisecondTimeAdd:now and:500.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   124
                (Delay untilMilliseconds:then) wait.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   125
                now := then
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   126
            ].
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   127
            t2 := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   128
            deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
2178
e255c5cd6dc7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   129
            Transcript show:'average delay: '; show:deltaT // 20; showCR:' milliseconds'
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   130
                                                                    [exEnd]
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   131
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   132
    instead of recreating new delays all over, 
2422
a319ee1bf54b open coded valueUninterruptably
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   133
    you can also reuse it (but that does not make a big difference ;-):
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   134
                                                                    [exBegin]
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   135
            |d now then t1 t2 deltaT|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   136
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   137
            t1 := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   138
            now := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   139
            d := Delay new.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   140
            10 timesRepeat:[
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   141
                then := OperatingSystem millisecondTimeAdd:now and:1000.
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   142
                d resumptionTime:then.
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   143
                d wait.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   144
                now := then
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   145
            ].
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   146
            t2 := Time millisecondClockValue.
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   147
            deltaT := OperatingSystem millisecondTimeDeltaBetween:t2 and:t1.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1348
diff changeset
   148
            Transcript show:'average delay: '; show:deltaT // 10; showCR:' milliseconds'
1316
248a8cb2ae3b examples
Claus Gittinger <cg@exept.de>
parents: 1294
diff changeset
   149
                                                                    [exEnd]
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   150
"
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   151
! !
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   152
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   153
!Delay class methodsFor:'instance creation'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   154
16404
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   155
for:aTimeDuration
20197
091727fab41e #OTHER by mawalch
mawalch
parents: 18996
diff changeset
   156
    "return a new Delay object for delaying aTimeDuration"
16404
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   157
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   158
    ^ self new delay:aTimeDuration asTimeDuration asTruncatedMilliseconds
16404
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   159
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   160
    "
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   161
      Delay for:10 seconds
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   162
      Delay for:2.5
16404
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   163
    "
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   164
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   165
    "Modified: / 21-02-2017 / 15:06:45 / stefan"
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   166
    "Modified: / 27-05-2019 / 21:29:07 / Stefan Vogel"
16404
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   167
!
ebb89de51a93 class: Delay
Stefan Vogel <sv@exept.de>
parents: 16351
diff changeset
   168
38
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   169
forMilliseconds:aNumber
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   170
    "return a new Delay object for delaying aNumber milliseconds"
454b1b94a48e *** empty log message ***
claus
parents: 25
diff changeset
   171
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   172
    ^ self new delay:aNumber
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   173
!
b07612967dfa Initial revision
claus
parents:
diff changeset
   174
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   175
forSeconds:secondsOrTimeDuration
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   176
    "return a new Delay object for delaying secondsOrTimeDuration seconds"
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   177
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   178
    secondsOrTimeDuration isNumber ifTrue:[
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   179
        ^ self new delay:(secondsOrTimeDuration * 1000) asInteger
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   180
    ].
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   181
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   182
    "a TimeDuration"
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   183
    ^ self new delay:secondsOrTimeDuration asTruncatedMilliseconds.
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   184
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   185
    "Modified: / 21-02-2017 / 14:54:53 / stefan"
24198
fc537a78d136 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22178
diff changeset
   186
    "Modified: / 27-05-2019 / 21:32:22 / Stefan Vogel"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   187
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   188
8254
73b6109ab982 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 7590
diff changeset
   189
until:aTimeStamp
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   190
    "return a new Delay object, that will delay the active process
15630
9e0f47e44106 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15553
diff changeset
   191
     until the system has reached the time represented by the argument."
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   192
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   193
    ^ self new delay:(aTimeStamp - Timestamp now) getMilliseconds.
275
a76029ddaa98 *** empty log message ***
claus
parents: 202
diff changeset
   194
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   195
    "
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   196
        (self until:(Timestamp now + 1 seconds)) wait
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   197
        (self until:(Timestamp now - 30 seconds)) wait
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   198
        (self until:Date tomorrow asTimestamp) wait
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   199
    "
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   200
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   201
    "Modified (comment): / 21-02-2017 / 15:17:49 / stefan"
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   202
!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   203
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   204
untilMilliseconds:aMillisecondTime
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   205
    "return a new Delay object, that will delay the active process
15630
9e0f47e44106 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15553
diff changeset
   206
     until the systems millisecond time has reached aMillisecondTime."
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   207
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   208
    ^ self new resumptionTime:aMillisecondTime
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   209
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   210
    "Modified: 18.4.1997 / 11:57:53 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   211
! !
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   212
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   213
!Delay class methodsFor:'queries'!
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   214
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   215
millisecondClockValue
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   216
    "for ST-80 compatibility"
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   217
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   218
    ^ Time millisecondClockValue
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   219
! !
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   220
873
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   221
!Delay class methodsFor:'waiting'!
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   222
11601
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   223
waitFor:aTimeDuration
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   224
    "wait for the given timeDuration.
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   225
     This is a combined instance creation & wait."
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   226
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   227
    ^ (self for:aTimeDuration) wait
11601
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   228
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   229
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   230
    "
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   231
     Delay waitFor:(TimeDuration seconds:5).
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   232
     Delay waitFor:2.5.
11601
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   233
    "
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   234
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   235
    "Modified: / 21-02-2017 / 15:06:01 / stefan"
11601
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   236
!
597295c0c3ab +waitFor:
Claus Gittinger <cg@exept.de>
parents: 10790
diff changeset
   237
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   238
waitForMilliseconds:aNumber
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   239
    "wait for the given number of milliseconds.
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   240
     This is a combined instance creation & wait."
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
    ^ (self forMilliseconds:aNumber) wait
8585
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   243
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   244
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   245
    "
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   246
        |start end|
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   247
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   248
        start := OperatingSystem getMicrosecondTime.
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   249
        Delay waitForMilliseconds:1.
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   250
        end := OperatingSystem getMicrosecondTime.
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   251
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   252
        end - start
47c2cef4692d comment
Stefan Vogel <sv@exept.de>
parents: 8566
diff changeset
   253
    "
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   254
!
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   255
873
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   256
waitForSeconds:aNumber
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   257
    "wait for the given number of seconds.
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   258
     This is a combined instance creation & wait."
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   259
b899dd803470 added combined create & wait
Claus Gittinger <cg@exept.de>
parents: 778
diff changeset
   260
    ^ (self forSeconds:aNumber) wait
12982
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   261
!
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   262
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   263
waitUntil:aTimestamp
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   264
    "wait until a given time is reached.
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   265
     This is a combined instance creation & wait."
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   266
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   267
    ^ (self until:aTimestamp) wait
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   268
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   269
    "Created: / 29-07-2010 / 13:51:41 / cg"
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   270
! !
b07612967dfa Initial revision
claus
parents:
diff changeset
   271
b07612967dfa Initial revision
claus
parents:
diff changeset
   272
!Delay methodsFor:'accessing'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   273
6934
7f47cfcbe755 oops - until: was wrong (setting seconds instead of millis)
Claus Gittinger <cg@exept.de>
parents: 6423
diff changeset
   274
delay:numberOfMillis
10725
cdf2971ca4a4 comment
Claus Gittinger <cg@exept.de>
parents: 10582
diff changeset
   275
    "set the millisecond delta and create a new semaphore internally to wait upon"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   276
10790
1d0fe0adf6be validate non-nil delayTime args
sr
parents: 10725
diff changeset
   277
    self assert:(numberOfMillis notNil).
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   278
    numberOfMillis < 0 ifTrue:[
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   279
        millisecondDelta := 0.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   280
    ] ifFalse:[
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   281
        millisecondDelta := numberOfMillis.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   282
    ].
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   283
22178
74a9bb3957b2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22154
diff changeset
   284
    delaySemaphore := Semaphore name:'delaySema'.
10582
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   285
22178
74a9bb3957b2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22154
diff changeset
   286
    "Modified: / 09-08-2017 / 11:52:47 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   287
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   288
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   289
delaySemaphore
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   290
    "return the semaphore used to resume the waiting process"
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   291
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   292
    ^ delaySemaphore
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   293
!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   294
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   295
resumptionTime:aMillisecondTime
11898
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   296
    "set the resumption time and create a new semaphore internally to wait upon"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   297
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   298
    resumptionTime := aMillisecondTime.
22178
74a9bb3957b2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22154
diff changeset
   299
    delaySemaphore := Semaphore name:'delaySema'.
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   300
22178
74a9bb3957b2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22154
diff changeset
   301
    "Created: / 18-04-1997 / 11:56:14 / stefan"
74a9bb3957b2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22154
diff changeset
   302
    "Modified: / 09-08-2017 / 11:52:53 / cg"
10582
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   303
!
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   304
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   305
setDelayDuration:numberOfMillis
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   306
    "set the millisecond delta"
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   307
10790
1d0fe0adf6be validate non-nil delayTime args
sr
parents: 10725
diff changeset
   308
    self assert:(numberOfMillis notNil).
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   309
    numberOfMillis < 0 ifTrue:[
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   310
        millisecondDelta := 0.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   311
    ] ifFalse:[
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   312
        millisecondDelta := numberOfMillis.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   313
    ].
11898
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   314
    resumptionTime := nil.
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   315
!
10582
00d5691a2b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8585
diff changeset
   316
11898
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   317
setResumptionTime:aMillisecondTime
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   318
    "set the resumption time"
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   319
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   320
    resumptionTime := aMillisecondTime.
2236f1cd95e1 comments
Claus Gittinger <cg@exept.de>
parents: 11601
diff changeset
   321
    millisecondDelta := nil.
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   322
! !
b07612967dfa Initial revision
claus
parents:
diff changeset
   323
b07612967dfa Initial revision
claus
parents:
diff changeset
   324
!Delay methodsFor:'delaying'!
b07612967dfa Initial revision
claus
parents:
diff changeset
   325
b07612967dfa Initial revision
claus
parents:
diff changeset
   326
wait
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   327
    "suspend the current process until either the relative time delta
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   328
     has passed (if millisecondDelta is non-nil), or the absolute millisecondTime
2556
4e58fce26d69 Fix spelling (resumtion --> resumption).
Stefan Vogel <sv@exept.de>
parents: 2422
diff changeset
   329
     has been reached (if resumptionTime non-nil)."
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   330
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   331
    |wasBlocked currentDelta dueTime then maxMilliseconds|
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   332
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   333
    isInterrupted := false.
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   334
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   335
    millisecondDelta notNil ifTrue:[
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   336
        maxMilliseconds := SmallInteger maxVal // 4.
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   337
        currentDelta := millisecondDelta rounded.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   338
        currentDelta <= 0 ifTrue:[
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   339
            ^ self.
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   340
        ].
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   341
        currentDelta > maxMilliseconds ifTrue:[
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   342
            "NOTE: the microsecondTime is increasing monotonically,
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   343
                   while millisecondTime is wrapping at 16r1fffffff.
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   344
                   So use the microsecondTime to check when we are finished"
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   345
            dueTime := OperatingSystem getMicrosecondTime + (currentDelta * 1000).
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   346
            currentDelta := maxMilliseconds.
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   347
        ].
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   348
        then := OperatingSystem 
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   349
                    millisecondTimeAdd:OperatingSystem getMillisecondTime 
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   350
                    and:currentDelta .
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   351
    ] ifFalse:[
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   352
        then := resumptionTime.
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   353
    ].
2422
a319ee1bf54b open coded valueUninterruptably
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   354
a319ee1bf54b open coded valueUninterruptably
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   355
    wasBlocked := OperatingSystem blockInterrupts.
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   356
    [
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   357
        [
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   358
            Processor signal:delaySemaphore atMilliseconds:then.
15553
8e0b933a9d68 class: Delay
Claus Gittinger <cg@exept.de>
parents: 15552
diff changeset
   359
            Processor activeProcess setStateTo:#timeWait if:#active.
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   360
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   361
            delaySemaphore wait.
16288
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   362
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   363
            dueTime notNil
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   364
              and:[isInterrupted not
16288
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   365
              and:[(currentDelta := dueTime - OperatingSystem getMicrosecondTime) > 0
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   366
              and:[
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   367
                currentDelta := (currentDelta // 1000) min:maxMilliseconds.
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   368
                then := OperatingSystem millisecondTimeAdd:OperatingSystem getMillisecondTime and:currentDelta.
16288
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   369
                true.]]]
c599c7f52198 class: Delay
Stefan Vogel <sv@exept.de>
parents: 15630
diff changeset
   370
        ] whileTrue.
6423
e43f6e61bfaa #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   371
    ] ensure:[
2422
a319ee1bf54b open coded valueUninterruptably
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   372
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
a319ee1bf54b open coded valueUninterruptably
Claus Gittinger <cg@exept.de>
parents: 2262
diff changeset
   373
    ]
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   374
88
81dacba7a63a *** empty log message ***
claus
parents: 38
diff changeset
   375
    "
8566
a8101fa70c6c comment
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
   376
     Transcript showCR:'1'.
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   377
     (Delay forSeconds:10) wait.
8566
a8101fa70c6c comment
Stefan Vogel <sv@exept.de>
parents: 8254
diff changeset
   378
     Transcript showCR:'2'.
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   379
    "
1033
244530001e84 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
   380
21503
d8d05099c9e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 20197
diff changeset
   381
    "Modified: / 26-02-1997 / 15:21:35 / cg"
22154
57770b556bdd #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 21503
diff changeset
   382
    "Modified: / 02-08-2017 / 14:17:54 / stefan"
9
b07612967dfa Initial revision
claus
parents:
diff changeset
   383
! !
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   384
7425
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   385
!Delay methodsFor:'early signalling'!
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   386
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   387
resume
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   388
    "resume the waiter, even if the delay-time has not yet passed."
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   389
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   390
    [
13802
ae3635b4508e class definition
Stefan Vogel <sv@exept.de>
parents: 13185
diff changeset
   391
        isInterrupted := true.
7425
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   392
        self disable.
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   393
        delaySemaphore signalOnce.
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   394
    ] valueUninterruptably
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   395
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   396
    "Modified: / 9.11.1998 / 20:56:43 / cg"
de40123f867c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7424
diff changeset
   397
! !
7424
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   398
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   399
!Delay methodsFor:'private'!
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   400
7424
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   401
disable
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   402
    "tell the ProcessorScheduler to forget about signaling my semaphore."
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   403
d68d1ccc2135 refactored for compatibility
Claus Gittinger <cg@exept.de>
parents: 6934
diff changeset
   404
    Processor disableSemaphore:delaySemaphore
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   405
! !
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   406
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   407
!Delay class methodsFor:'documentation'!
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   408
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   409
version
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   410
    ^ '$Header$'
12982
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   411
!
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   412
ec2cd6e2d39b added: #waitUntil:
Claus Gittinger <cg@exept.de>
parents: 11898
diff changeset
   413
version_CVS
18996
d27c313ccf06 #BUGFIX
Stefan Vogel <sv@exept.de>
parents: 16404
diff changeset
   414
    ^ '$Header$'
695
20ec350f92ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   415
! !
15552
9a800a2e1e81 class: Delay
Claus Gittinger <cg@exept.de>
parents: 13802
diff changeset
   416