Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/debuglog_on.go

Documentation: runtime

     1  // Copyright 2019 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  
     5  //go:build debuglog
     6  // +build debuglog
     7  
     8  package runtime
     9  
    10  const dlogEnabled = true
    11  
    12  // dlogPerM is the per-M debug log data. This is embedded in the m
    13  // struct.
    14  type dlogPerM struct {
    15  	dlogCache *dlogger
    16  }
    17  
    18  // getCachedDlogger returns a cached dlogger if it can do so
    19  // efficiently, or nil otherwise. The returned dlogger will be owned.
    20  func getCachedDlogger() *dlogger {
    21  	mp := acquirem()
    22  	// We don't return a cached dlogger if we're running on the
    23  	// signal stack in case the signal arrived while in
    24  	// get/putCachedDlogger. (Too bad we don't have non-atomic
    25  	// exchange!)
    26  	var l *dlogger
    27  	if getg() != mp.gsignal {
    28  		l = mp.dlogCache
    29  		mp.dlogCache = nil
    30  	}
    31  	releasem(mp)
    32  	return l
    33  }
    34  
    35  // putCachedDlogger attempts to return l to the local cache. It
    36  // returns false if this fails.
    37  func putCachedDlogger(l *dlogger) bool {
    38  	mp := acquirem()
    39  	if getg() != mp.gsignal && mp.dlogCache == nil {
    40  		mp.dlogCache = l
    41  		releasem(mp)
    42  		return true
    43  	}
    44  	releasem(mp)
    45  	return false
    46  }
    47  

View as plain text