github.com/carter-ya/go-ethereum@v0.0.0-20230628080049-d2309be3983b/log/handler_go14.go (about)

     1  //go:build go1.4
     2  // +build go1.4
     3  
     4  package log
     5  
     6  import "sync/atomic"
     7  
     8  // swapHandler wraps another handler that may be swapped out
     9  // dynamically at runtime in a thread-safe fashion.
    10  type swapHandler struct {
    11  	handler atomic.Value
    12  }
    13  
    14  func (h *swapHandler) Log(r *Record) error {
    15  	return (*h.handler.Load().(*Handler)).Log(r)
    16  }
    17  
    18  func (h *swapHandler) Swap(newHandler Handler) {
    19  	h.handler.Store(&newHandler)
    20  }
    21  
    22  func (h *swapHandler) Get() Handler {
    23  	return *h.handler.Load().(*Handler)
    24  }