github.com/googgoog/go-ethereum@v1.9.7/log/handler_go13.go (about) 1 // +build !go1.4 2 3 package log 4 5 import ( 6 "sync/atomic" 7 "unsafe" 8 ) 9 10 // swapHandler wraps another handler that may be swapped out 11 // dynamically at runtime in a thread-safe fashion. 12 type swapHandler struct { 13 handler unsafe.Pointer 14 } 15 16 func (h *swapHandler) Log(r *Record) error { 17 return h.Get().Log(r) 18 } 19 20 func (h *swapHandler) Get() Handler { 21 return *(*Handler)(atomic.LoadPointer(&h.handler)) 22 } 23 24 func (h *swapHandler) Swap(newHandler Handler) { 25 atomic.StorePointer(&h.handler, unsafe.Pointer(&newHandler)) 26 }