mirror of
https://github.com/golang/go
synced 2024-11-26 08:38:01 -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
|
//go:build faketime && !windows
|
||||||
// +build faketime,!windows
|
// +build faketime,!windows
|
||||||
|
|
||||||
// Faketime isn't currently supported on Windows. This would require:
|
// Faketime isn't currently supported on Windows. This would require
|
||||||
//
|
// modifying syscall.Write to call syscall.faketimeWrite,
|
||||||
// 1. Shadowing time_now, which is implemented in assembly on Windows.
|
// translating the Stdout and Stderr handles into FDs 1 and 2.
|
||||||
// Since that's exported directly to the time package from runtime
|
// (See CL 192739 PS 3.)
|
||||||
// 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.)
|
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
@ -48,6 +41,12 @@ func walltime() (sec int64, nsec int32) {
|
|||||||
return faketime / 1000000000, int32(faketime % 1000000000)
|
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 {
|
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
|
||||||
if !(fd == 1 || fd == 2) {
|
if !(fd == 1 || fd == 2) {
|
||||||
// Do an ordinary write.
|
// Do an ordinary write.
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !faketime
|
||||||
|
// +build !faketime
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
#include "time_windows.h"
|
#include "time_windows.h"
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !faketime
|
||||||
|
// +build !faketime
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
#include "time_windows.h"
|
#include "time_windows.h"
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !faketime
|
||||||
|
// +build !faketime
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
#include "time_windows.h"
|
#include "time_windows.h"
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !faketime
|
||||||
|
// +build !faketime
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
#include "time_windows.h"
|
#include "time_windows.h"
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
// Declarations for operating systems implementing time.now directly in assembly.
|
// Declarations for operating systems implementing time.now directly in assembly.
|
||||||
|
|
||||||
//go:build windows
|
//go:build !faketime && windows
|
||||||
// +build windows
|
// +build !faketime,windows
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
// Declarations for operating systems implementing time.now
|
// Declarations for operating systems implementing time.now
|
||||||
// indirectly, in terms of walltime and nanotime assembly.
|
// indirectly, in terms of walltime and nanotime assembly.
|
||||||
|
|
||||||
//go:build !windows
|
//go:build !faketime && !windows
|
||||||
// +build !windows
|
// +build !faketime,!windows
|
||||||
|
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user