Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
1e66428d
Commit
1e66428d
authored
Feb 04, 2010
by
Christopher Wedgwood
Committed by
Russ Cox
Feb 04, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time: Sleep through interruptions
R=rsc CC=golang-dev
https://golang.org/cl/202043
parent
b655fa8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
src/pkg/time/sleep.go
src/pkg/time/sleep.go
+13
-2
src/pkg/time/sleep_test.go
src/pkg/time/sleep_test.go
+26
-0
No files found.
src/pkg/time/sleep.go
View file @
1e66428d
...
...
@@ -11,5 +11,16 @@ import (
// Sleep pauses the current goroutine for at least ns nanoseconds. Higher resolution
// sleeping may be provided by syscall.Nanosleep on some operating systems.
// Sleep returns os.EINTR if interrupted.
func
Sleep
(
ns
int64
)
os
.
Error
{
return
os
.
NewSyscallError
(
"sleep"
,
syscall
.
Sleep
(
ns
))
}
func
Sleep
(
ns
int64
)
os
.
Error
{
// TODO(cw): use monotonic-time once it's available
t
:=
Nanoseconds
()
end
:=
t
+
ns
for
t
<
end
{
errno
:=
syscall
.
Sleep
(
end
-
t
)
if
errno
!=
0
&&
errno
!=
syscall
.
EINTR
{
return
os
.
NewSyscallError
(
"sleep"
,
errno
)
}
t
=
Nanoseconds
()
}
return
nil
}
src/pkg/time/sleep_test.go
0 → 100644
View file @
1e66428d
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
time_test
import
(
"os"
"syscall"
"testing"
.
"time"
)
func
TestSleep
(
t
*
testing
.
T
)
{
const
delay
=
int64
(
100e6
)
go
func
()
{
Sleep
(
delay
/
2
)
syscall
.
Kill
(
os
.
Getpid
(),
syscall
.
SIGCHLD
)
}()
start
:=
Nanoseconds
()
Sleep
(
delay
)
duration
:=
Nanoseconds
()
-
start
if
duration
<
delay
{
t
.
Fatalf
(
"Sleep(%d) slept for only %d ns"
,
delay
,
duration
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment