scheduler.mx raw

   1  package runtime
   2  
   3  import "internal/task"
   4  
   5  const schedulerDebug = false
   6  
   7  var timerQueue *timerNode
   8  
   9  // Simple logging, for debugging.
  10  func scheduleLog(msg string) {
  11  	if schedulerDebug {
  12  		println("---", msg)
  13  	}
  14  }
  15  
  16  // Simple logging with a task pointer, for debugging.
  17  func scheduleLogTask(msg string, t *task.Task) {
  18  	if schedulerDebug {
  19  		println("---", msg, t)
  20  	}
  21  }
  22  
  23  // Simple logging with a channel and task pointer.
  24  func scheduleLogChan(msg string, ch *channel, t *task.Task) {
  25  	if schedulerDebug {
  26  		println("---", msg, ch, t)
  27  	}
  28  }
  29  
  30  func timerQueueAdd(tn *timerNode) {
  31  	q := &timerQueue
  32  	for ; *q != nil; q = &(*q).next {
  33  		if tn.whenTicks() < (*q).whenTicks() {
  34  			// this will finish earlier than the next - insert here
  35  			break
  36  		}
  37  	}
  38  	tn.next = *q
  39  	*q = tn
  40  }
  41  
  42  func timerQueueRemove(t *timer) *timerNode {
  43  	for q := &timerQueue; *q != nil; q = &(*q).next {
  44  		if (*q).timer == t {
  45  			scheduleLog("removed timer")
  46  			n := *q
  47  			*q = (*q).next
  48  			return n
  49  		}
  50  	}
  51  	scheduleLog("did not remove timer")
  52  	return nil
  53  }
  54  
  55  // Goexit terminates the currently running goroutine. No other goroutines are affected.
  56  func Goexit() {
  57  	panicOrGoexit(nil, panicGoexit)
  58  }
  59  
  60  //go:linkname fips_getIndicator crypto/internal/fips140.getIndicator
  61  func fips_getIndicator() uint8 {
  62  	return task.Current().FipsIndicator
  63  }
  64  
  65  //go:linkname fips_setIndicator crypto/internal/fips140.setIndicator
  66  func fips_setIndicator(indicator uint8) {
  67  	// This indicator is stored per goroutine.
  68  	task.Current().FipsIndicator = indicator
  69  }
  70