github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/log/handler_go13.go (about)

     1  //go:build !go1.4
     2  // +build !go1.4
     3  
     4  package log
     5  
     6  import (
     7  	"sync/atomic"
     8  	"unsafe"
     9  )
    10  
    11  type swapHandler struct {
    12  	handler unsafe.Pointer
    13  }
    14  
    15  func (h *swapHandler) Log(r *Record) error {
    16  	return h.Get().Log(r)
    17  }
    18  
    19  func (h *swapHandler) Get() Handler {
    20  	return *(*Handler)(atomic.LoadPointer(&h.handler))
    21  }
    22  
    23  func (h *swapHandler) Swap(newHandler Handler) {
    24  	atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler))
    25  }