time.mx raw

   1  package runtime
   2  
   3  //go:linkname time_runtimeNano time.runtimeNano
   4  func time_runtimeNano() int64 {
   5  	// Note: we're ignoring sync groups here (package testing/synctest).
   6  	// See: https://github.com/golang/go/issues/67434
   7  	return nanotime()
   8  }
   9  
  10  //go:linkname time_runtimeNow time.runtimeNow
  11  func time_runtimeNow() (sec int64, nsec int32, mono int64) {
  12  	// Also ignoring the sync group here, like time_runtimeNano above.
  13  	return now()
  14  }
  15  
  16  // timerNode is an element in a linked list of timers.
  17  type timerNode struct {
  18  	next     *timerNode
  19  	timer    *timer
  20  	callback func(node *timerNode, delta int64)
  21  }
  22  
  23  // whenTicks returns the (absolute) time when this timer should trigger next.
  24  func (t *timerNode) whenTicks() timeUnit {
  25  	return nanosecondsToTicks(t.timer.when)
  26  }
  27  
  28  // timerCallback is called when a timer expires. It makes sure to call the
  29  // callback in the time package and to re-add the timer to the queue if this is
  30  // a ticker (repeating timer).
  31  // This is intentionally used as a callback and not a direct call (even though a
  32  // direct call would be trivial), because otherwise a circular dependency
  33  // between scheduler, addTimer and timerQueue would form. Such a circular
  34  // dependency causes timerQueue not to get optimized away.
  35  // If timerQueue doesn't get optimized away, small programs (that don't call
  36  // time.NewTimer etc) would still pay the cost of these timers.
  37  func timerCallback(tn *timerNode, delta int64) {
  38  	// Run timer function (implemented in the time package).
  39  	// The seq parameter to the f function is not used in the time
  40  	// package so is left zero.
  41  	tn.timer.callCallback(delta)
  42  
  43  	// If this is a periodic timer (a ticker), re-add it to the queue.
  44  	if tn.timer.period != 0 {
  45  		tn.timer.when += tn.timer.period
  46  		addTimer(tn)
  47  	}
  48  }
  49  
  50  //go:linkname time_runtimeIsBubbled time.runtimeIsBubbled
  51  func time_runtimeIsBubbled() bool {
  52  	// We don't currently support bubbles.
  53  	return false
  54  }
  55