mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Implement jiffies.
This commit is contained in:
parent
7ae9a9ea69
commit
dddecd8610
2 changed files with 15 additions and 1 deletions
|
@ -22,6 +22,13 @@ func Microseconds() uint64 {
|
||||||
return Now(1000000)
|
return Now(1000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JiffiesPerSec is the LCM of 48000, 96000 and 65536
|
||||||
|
const JiffiesPerSec = 24576000
|
||||||
|
|
||||||
|
func Jiffies() uint64 {
|
||||||
|
return Now(JiffiesPerSec)
|
||||||
|
}
|
||||||
|
|
||||||
var ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
|
var ntpEpoch = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
func NTPToTime(ntp uint64) time.Time {
|
func NTPToTime(ntp uint64) time.Time {
|
||||||
|
|
|
@ -24,7 +24,7 @@ func differs(a, b, delta uint64) bool {
|
||||||
return a - b >= delta
|
return a - b >= delta
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMono(t *testing.T) {
|
func TestTime(t *testing.T) {
|
||||||
a := Now(48000)
|
a := Now(48000)
|
||||||
time.Sleep(4 * time.Millisecond)
|
time.Sleep(4 * time.Millisecond)
|
||||||
b := Now(48000) - a
|
b := Now(48000) - a
|
||||||
|
@ -38,6 +38,13 @@ func TestMono(t *testing.T) {
|
||||||
if differs(d, 4000, 1000) {
|
if differs(d, 4000, 1000) {
|
||||||
t.Errorf("Expected %v, got %v", 4000, d)
|
t.Errorf("Expected %v, got %v", 4000, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c = Jiffies()
|
||||||
|
time.Sleep(time.Second * 100000 / JiffiesPerSec)
|
||||||
|
d = Jiffies() - c
|
||||||
|
if differs(d, 100000, 10000) {
|
||||||
|
t.Errorf("Expected %v, got %v", 4000, d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNTP(t *testing.T) {
|
func TestNTP(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue