Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions util/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

//go:build !linux
// +build !linux

package util
Expand Down
10 changes: 0 additions & 10 deletions util/sleep_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@
package util

import (
"syscall"
"time"
)

// NanoSleep sleeps for the given d duration.
func NanoSleep(d time.Duration) {
timeSpec := &syscall.Timespec{
Nsec: d.Nanoseconds() % time.Second.Nanoseconds(),
Sec: d.Nanoseconds() / time.Second.Nanoseconds(),
}
syscall.Nanosleep(timeSpec, nil) // nolint:errcheck
}

// NanoAfter waits for the duration to elapse and then sends the current time on the returned channel.
func NanoAfter(d time.Duration) <-chan time.Time {
// The following is a workaround for the go 1.16 bug, where timers are rounded up to the next millisecond resolution.
Expand Down
35 changes: 35 additions & 0 deletions util/sleep_linux_32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

//go:build linux && (arm || 386)
// +build linux
// +build arm 386

package util

import (
"syscall"
"time"
)

// NanoSleep sleeps for the given d duration.
func NanoSleep(d time.Duration) {
timeSpec := &syscall.Timespec{
Nsec: int32(d.Nanoseconds() % time.Second.Nanoseconds()),
Sec: int32(d.Nanoseconds() / time.Second.Nanoseconds()),
}
syscall.Nanosleep(timeSpec, nil) // nolint:errcheck
}
34 changes: 34 additions & 0 deletions util/sleep_linux_64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2019-2022 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

//go:build linux && !(arm || 386)
// +build linux,!arm,!386

package util

import (
"syscall"
"time"
)

// NanoSleep sleeps for the given d duration.
func NanoSleep(d time.Duration) {
timeSpec := &syscall.Timespec{
Nsec: d.Nanoseconds() % time.Second.Nanoseconds(),
Sec: d.Nanoseconds() / time.Second.Nanoseconds(),
}
syscall.Nanosleep(timeSpec, nil) // nolint:errcheck
}