mirror of
https://github.com/hanzozt/dilithium.git
synced 2026-10-30 20:38:17 +00:00
32 lines
430 B
Go
32 lines
430 B
Go
package loop
|
|
|
|
import "sync/atomic"
|
|
|
|
type buffer struct {
|
|
data []byte
|
|
uz int64
|
|
sz int64
|
|
pool *Pool
|
|
refs int32
|
|
}
|
|
|
|
func newBuffer(pool *Pool) *buffer {
|
|
return &buffer{
|
|
data: make([]byte, pool.sz),
|
|
sz: pool.sz,
|
|
pool: pool,
|
|
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)
|
|
}
|
|
}
|