优化日志库-新增Buff数量,减少多协程并发写锁等待

This commit is contained in:
boyce
2021-07-01 18:24:25 +08:00
parent a0594cb945
commit 17601f1831
3 changed files with 221 additions and 184 deletions

View File

@@ -1,17 +1,29 @@
package log // import "go.uber.org/zap/buffer"
import "strconv"
import (
"strconv"
"sync"
)
const _size = 9216
type Buffer struct {
bs []byte
mu sync.Mutex // ensures atomic writes; protects the following fields
}
func (buff *Buffer) Init(){
buff.bs = make([]byte,_size)
}
func (buff *Buffer) Locker() {
buff.mu.Lock()
}
func (buff *Buffer) UnLocker() {
buff.mu.Unlock()
}
// AppendByte writes a single byte to the Buffer.
func (b *Buffer) AppendByte(v byte) {
b.bs = append(b.bs, v)