diff options
author | 2022-11-08 09:35:01 +0000 | |
---|---|---|
committer | 2022-11-08 10:35:01 +0100 | |
commit | 7c0bbd3f6a3ed9a8e5b879a00dbd4dad88e375c3 (patch) | |
tree | 0409dfee4ff5685f66cbd61d8504b119b1db093c /vendor/codeberg.org/gruf/go-mutexes/map_pool.go | |
parent | [docs] refer to the latest release version (#992) (diff) | |
download | gotosocial-7c0bbd3f6a3ed9a8e5b879a00dbd4dad88e375c3.tar.xz |
[chore] update gruf libraries (#996)
* update go-store to v2.0.6: closer callbacks are now only ever called at most once
Signed-off-by: kim <grufwub@gmail.com>
* bump go-store => v2.0.7, go-mutexes => v1.1.4
Signed-off-by: kim <grufwub@gmail.com>
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-mutexes/map_pool.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-mutexes/map_pool.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-mutexes/map_pool.go b/vendor/codeberg.org/gruf/go-mutexes/map_pool.go new file mode 100644 index 000000000..450e0bc06 --- /dev/null +++ b/vendor/codeberg.org/gruf/go-mutexes/map_pool.go @@ -0,0 +1,39 @@ +package mutexes + +// pool is a very simply memory pool. +type pool struct { + current []*rwmutex + victim []*rwmutex +} + +// Acquire will returns a rwmutex from pool (or alloc new). +func (p *pool) Acquire() *rwmutex { + // First try the current queue + if l := len(p.current) - 1; l >= 0 { + mu := p.current[l] + p.current = p.current[:l] + return mu + } + + // Next try the victim queue. + if l := len(p.victim) - 1; l >= 0 { + mu := p.victim[l] + p.victim = p.victim[:l] + return mu + } + + // Lastly, alloc new. + return &rwmutex{} +} + +// Release places a sync.RWMutex back in the pool. +func (p *pool) Release(mu *rwmutex) { + p.current = append(p.current, mu) +} + +// GC will clear out unused entries from the pool. +func (p *pool) GC() { + current := p.current + p.current = nil + p.victim = current +} |