mirror of
https://github.com/hanzozt/dilithium.git
synced 2026-10-30 20:38:17 +00:00
33 lines
455 B
Go
33 lines
455 B
Go
package westworld3
|
|
|
|
import "sync/atomic"
|
|
|
|
type buffer struct {
|
|
data []byte
|
|
refs int32
|
|
sz uint32
|
|
uz uint32
|
|
pool *pool
|
|
}
|
|
|
|
func newBuffer(pool *pool) *buffer {
|
|
return &buffer{
|
|
data: make([]byte, pool.bufSz),
|
|
pool: pool,
|
|
sz: pool.bufSz,
|
|
uz: 0,
|
|
refs: 0,
|
|
}
|
|
}
|
|
|
|
func (self *buffer) ref() {
|
|
atomic.AddInt32(&self.refs, 1)
|
|
}
|
|
|
|
func (self *buffer) unref() {
|
|
if atomic.AddInt32(&self.refs, -1) < 1 {
|
|
self.uz = 0
|
|
self.pool.put(self)
|
|
}
|
|
}
|