github.com/mailru/activerecord@v1.12.2/pkg/iproto/util/time/monotonic_linux.go (about)

     1  package time
     2  
     3  import "fmt"
     4  
     5  /*
     6  #cgo LDFLAGS: -lrt
     7  #include <time.h>
     8  */
     9  import "C"
    10  
    11  func Monotonic() (ret MonotonicTimestamp, err error) {
    12  	var ts C.struct_timespec
    13  
    14  	code := C.clock_gettime(C.CLOCK_MONOTONIC, &ts)
    15  	if code != 0 {
    16  		err = fmt.Errorf("clock_gettime error: %d", code)
    17  		return
    18  	}
    19  
    20  	ret.sec = int64(ts.tv_sec)
    21  	ret.nsec = int32(ts.tv_nsec)
    22  
    23  	return
    24  }