go-now.c 672 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <sys/time.h>
  7. #include "runtime.h"
  8. // Return current time. This is the implementation of runtime.walltime().
  9. struct walltime_ret
  10. {
  11. int64_t sec;
  12. int32_t nsec;
  13. };
  14. struct walltime_ret now(void) __asm__ (GOSYM_PREFIX "runtime.walltime")
  15. __attribute__ ((no_split_stack));
  16. struct walltime_ret
  17. now(void)
  18. {
  19. struct timespec ts;
  20. struct walltime_ret ret;
  21. clock_gettime (CLOCK_REALTIME, &ts);
  22. ret.sec = ts.tv_sec;
  23. ret.nsec = ts.tv_nsec;
  24. return ret;
  25. }