fix: thread-safe in getWriter of logx (#2319)

This commit is contained in:
Kevin Wan
2022-08-29 08:32:17 +08:00
committed by GitHub
parent 8c72136631
commit dfeef5e497
2 changed files with 13 additions and 12 deletions

View File

@@ -67,6 +67,17 @@ func (w *atomicWriter) Store(v Writer) {
w.writer = v
}
func (w *atomicWriter) StoreIfNil(v Writer) Writer {
w.lock.Lock()
defer w.lock.Unlock()
if w.writer == nil {
w.writer = v
}
return w.writer
}
func (w *atomicWriter) Swap(v Writer) Writer {
w.lock.Lock()
defer w.lock.Unlock()