mirror of
https://github.com/golang/go
synced 2024-11-26 08:07:57 -07:00
runtime: use a single definition of time_now for faketime
Build other definitions with the !faketime build tag. This makes it easy for us to add new assembly implementations of time.now. Change-Id: I4e48e41a4a04ab001030e6d1cdd9cebfa0161b0d Reviewed-on: https://go-review.googlesource.com/c/go/+/314274 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
parent
b36596b14f
commit
c96fec9036
@ -5,17 +5,10 @@
|
||||
//go:build faketime && !windows
|
||||
// +build faketime,!windows
|
||||
|
||||
// Faketime isn't currently supported on Windows. This would require:
|
||||
//
|
||||
// 1. Shadowing time_now, which is implemented in assembly on Windows.
|
||||
// Since that's exported directly to the time package from runtime
|
||||
// assembly, this would involve moving it from sys_windows_*.s into
|
||||
// its own assembly files build-tagged with !faketime and using the
|
||||
// implementation of time_now from timestub.go in faketime mode.
|
||||
//
|
||||
// 2. Modifying syscall.Write to call syscall.faketimeWrite,
|
||||
// translating the Stdout and Stderr handles into FDs 1 and 2.
|
||||
// (See CL 192739 PS 3.)
|
||||
// Faketime isn't currently supported on Windows. This would require
|
||||
// modifying syscall.Write to call syscall.faketimeWrite,
|
||||
// translating the Stdout and Stderr handles into FDs 1 and 2.
|
||||
// (See CL 192739 PS 3.)
|
||||
|
||||
package runtime
|
||||
|
||||
@ -48,6 +41,12 @@ func walltime() (sec int64, nsec int32) {
|
||||
return faketime / 1000000000, int32(faketime % 1000000000)
|
||||
}
|
||||
|
||||
//go:linkname time_now time.now
|
||||
func time_now() (sec int64, nsec int32, mono int64) {
|
||||
sec, nsec = walltime()
|
||||
return sec, nsec, nanotime()
|
||||
}
|
||||
|
||||
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
|
||||
if !(fd == 1 || fd == 2) {
|
||||
// Do an ordinary write.
|
||||
|
@ -2,6 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !faketime
|
||||
// +build !faketime
|
||||
|
||||
#include "go_asm.h"
|
||||
#include "textflag.h"
|
||||
#include "time_windows.h"
|
||||
|
@ -2,6 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !faketime
|
||||
// +build !faketime
|
||||
|
||||
#include "go_asm.h"
|
||||
#include "textflag.h"
|
||||
#include "time_windows.h"
|
||||
|
@ -2,6 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !faketime
|
||||
// +build !faketime
|
||||
|
||||
#include "go_asm.h"
|
||||
#include "textflag.h"
|
||||
#include "time_windows.h"
|
||||
|
@ -2,6 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !faketime
|
||||
// +build !faketime
|
||||
|
||||
#include "go_asm.h"
|
||||
#include "textflag.h"
|
||||
#include "time_windows.h"
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
// Declarations for operating systems implementing time.now directly in assembly.
|
||||
|
||||
//go:build windows
|
||||
// +build windows
|
||||
//go:build !faketime && windows
|
||||
// +build !faketime,windows
|
||||
|
||||
package runtime
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
// Declarations for operating systems implementing time.now
|
||||
// indirectly, in terms of walltime and nanotime assembly.
|
||||
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
//go:build !faketime && !windows
|
||||
// +build !faketime,!windows
|
||||
|
||||
package runtime
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user