update my personal library versions (#220)

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
kim 2021-09-13 09:33:01 +01:00 committed by GitHub
parent f6492d12d9
commit 635281f133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 84 deletions

6
go.mod
View file

@ -3,7 +3,7 @@ module github.com/superseriousbusiness/gotosocial
go 1.17
require (
git.iim.gay/grufwub/go-store v0.4.1
git.iim.gay/grufwub/go-store v0.4.2
github.com/ReneKroon/ttlcache v1.7.0
github.com/buckket/go-blurhash v1.1.0
github.com/coreos/go-oidc/v3 v3.0.0
@ -47,8 +47,8 @@ require (
git.iim.gay/grufwub/go-bytes v0.7.0 // indirect
git.iim.gay/grufwub/go-errors v0.2.3 // indirect
git.iim.gay/grufwub/go-hashenc v0.3.0 // indirect
git.iim.gay/grufwub/go-mutexes v0.5.0 // indirect
git.iim.gay/grufwub/go-nowish v0.3.4 // indirect
git.iim.gay/grufwub/go-mutexes v0.5.1 // indirect
git.iim.gay/grufwub/go-nowish v0.3.5 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect

12
go.sum
View file

@ -42,12 +42,12 @@ git.iim.gay/grufwub/go-errors v0.2.3/go.mod h1:rfKZpjI7A67zJfzpt5zfwAUMA7gec0EHX
git.iim.gay/grufwub/go-fixedmap v0.1.3/go.mod h1:KB4nV2+NeBMVFvFwpdgsP74AsMiDeX68oD20wiC2S3I=
git.iim.gay/grufwub/go-hashenc v0.3.0 h1:2etpzwoUTPTLvlWZ9u9a+FUCGBcVU37x5zM5XZ0kahQ=
git.iim.gay/grufwub/go-hashenc v0.3.0/go.mod h1:wjztiGUzaZsEw5kKE6gz/UOFN2cbcDnGiUSUjOLXi4o=
git.iim.gay/grufwub/go-mutexes v0.5.0 h1:HojjhBWI1ry1TTvijczhm2oQ5CxLbxzihawqYk2Umto=
git.iim.gay/grufwub/go-mutexes v0.5.0/go.mod h1:xMhjpEP5UsCuFQD4qCIcq4pJLf7vMXZ56TD/u+wWJ4Y=
git.iim.gay/grufwub/go-nowish v0.3.4 h1:VgUzSEO7xJsJFN2HPbPYHT79s3pUkd5Z8hQOPecZzFU=
git.iim.gay/grufwub/go-nowish v0.3.4/go.mod h1:oII7zlMQMFclFzgmI1qRd7DdQXKNHWcJYnwHFgdgiRI=
git.iim.gay/grufwub/go-store v0.4.1 h1:orSqupN2iTm8P0sUpGWlCl6qckM2phkFnsB3TFTo6aQ=
git.iim.gay/grufwub/go-store v0.4.1/go.mod h1:NaSfOLKNzjj9lUQ0MA/gLGEeRiXhwOx26zR+l/SC9VM=
git.iim.gay/grufwub/go-mutexes v0.5.1 h1:HjMUvTCsEWfX8lW7VaYwwkdOA2Bjg8qZjHJAT+cbMBA=
git.iim.gay/grufwub/go-mutexes v0.5.1/go.mod h1:oCWMmmM+puqoq8y3b2ZEvmazx9XLbcvUIugtMPJswhE=
git.iim.gay/grufwub/go-nowish v0.3.5 h1:RBBSPAIZcsqd0QfscMZ55ogNwM+uERoBKKLlNMgFhxs=
git.iim.gay/grufwub/go-nowish v0.3.5/go.mod h1:oII7zlMQMFclFzgmI1qRd7DdQXKNHWcJYnwHFgdgiRI=
git.iim.gay/grufwub/go-store v0.4.2 h1:VjcuyFDW64Pu0fvO9Nww33eLBewrQbtjAKT99YQSJsw=
git.iim.gay/grufwub/go-store v0.4.2/go.mod h1:qXeDj6+LlMJsZul3RwP2LLBSOK57Rl/vdWtQdGIbL9g=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=

View file

@ -8,15 +8,7 @@
// by key. You do not need to worry about managing the contents of the map,
// only requesting RLock/Lock for keys, and ensuring to call the returned
// unlock functions.
type MutexMap interface {
// Lock acquires a mutex lock for supplied key, returning an Unlock function
Lock(key string) (unlock func())
// RLock acquires a mutex read lock for supplied key, returning an RUnlock function
RLock(key string) (runlock func())
}
type mutexMap struct {
type MutexMap struct {
// NOTE:
// Individual keyed mutexes should ONLY ever
// be locked within the protection of the outer
@ -35,7 +27,7 @@ func NewMap(newFn func() RWMutex) MutexMap {
if newFn == nil {
newFn = NewRW
}
return &mutexMap{
return MutexMap{
mus: make(map[string]RWMutex),
mapMu: sync.Mutex{},
pool: sync.Pool{
@ -46,7 +38,7 @@ func NewMap(newFn func() RWMutex) MutexMap {
}
}
func (mm *mutexMap) evict(key string, mu RWMutex) {
func (mm *MutexMap) evict(key string, mu RWMutex) {
// Acquire map lock
mm.mapMu.Lock()
@ -63,21 +55,21 @@ func (mm *mutexMap) evict(key string, mu RWMutex) {
mm.pool.Put(mu)
}
// GetRLock acquires a mutex read lock for supplied key, returning an RUnlock function
func (mm *mutexMap) RLock(key string) func() {
// RLock acquires a mutex read lock for supplied key, returning an RUnlock function
func (mm *MutexMap) RLock(key string) func() {
return mm.getLock(key, func(mu RWMutex) func() {
return mu.RLock()
})
}
// GetLock acquires a mutex lock for supplied key, returning an Unlock function
func (mm *mutexMap) Lock(key string) func() {
// Lock acquires a mutex lock for supplied key, returning an Unlock function
func (mm *MutexMap) Lock(key string) func() {
return mm.getLock(key, func(mu RWMutex) func() {
return mu.Lock()
})
}
func (mm *mutexMap) getLock(key string, doLock func(RWMutex) func()) func() {
func (mm *MutexMap) getLock(key string, doLock func(RWMutex) func()) func() {
// Get map lock
mm.mapMu.Lock()

View file

@ -43,7 +43,7 @@ type timeoutMutex struct {
}
func (mu *timeoutMutex) Lock() func() {
return mu.LockFunc(func() { panic("timed out") })
return mu.LockFunc(func() { panic("lock timed out") })
}
func (mu *timeoutMutex) LockFunc(fn func()) func() {
@ -58,7 +58,7 @@ type timeoutRWMutex struct {
}
func (mu *timeoutRWMutex) Lock() func() {
return mu.LockFunc(func() { panic("timed out") })
return mu.LockFunc(func() { panic("lock timed out") })
}
func (mu *timeoutRWMutex) LockFunc(fn func()) func() {
@ -66,7 +66,7 @@ func (mu *timeoutRWMutex) LockFunc(fn func()) func() {
}
func (mu *timeoutRWMutex) RLock() func() {
return mu.RLockFunc(func() { panic("timed out") })
return mu.RLockFunc(func() { panic("rlock timed out") })
}
func (mu *timeoutRWMutex) RLockFunc(fn func()) func() {
@ -76,7 +76,8 @@ func (mu *timeoutRWMutex) RLockFunc(fn func()) func() {
// timeoutPool provides nowish.Timeout objects for timeout mutexes
var timeoutPool = sync.Pool{
New: func() interface{} {
return nowish.NewTimeout()
t := nowish.NewTimeout()
return &t
},
}
@ -88,7 +89,7 @@ func mutexTimeout(d time.Duration, unlock func(), fn func()) func() {
}
// Acquire timeout obj
t := timeoutPool.Get().(nowish.Timeout)
t := timeoutPool.Get().(*nowish.Timeout)
// Start the timeout with hook
t.Start(d, fn)

View file

@ -1,57 +1,12 @@
package nowish
import (
"errors"
"sync/atomic"
"time"
)
// ErrTimeoutStarted is returned if a Timeout interface is attempted to be reused while still in operation
var ErrTimeoutStarted = errors.New("nowish: timeout already started")
// timeoutState provides a thread-safe timeout state mechanism
type timeoutState uint32
// start attempts to start the state, must be already reset, returns success
func (t *timeoutState) start() bool {
return atomic.CompareAndSwapUint32((*uint32)(t), 0, 1)
}
// stop attempts to stop the state, must already be started, returns success
func (t *timeoutState) stop() bool {
return atomic.CompareAndSwapUint32((*uint32)(t), 1, 2)
}
// reset is fairly self explanatory
func (t *timeoutState) reset() {
atomic.StoreUint32((*uint32)(t), 0)
}
// Timeout provides a reusable structure for enforcing timeouts with a cancel
type Timeout interface {
// Start starts the timer with supplied timeout. If timeout is reached before
// cancel then supplied timeout hook will be called. Error may be called if
// Timeout is already running when this function is called
Start(time.Duration, func()) error
// Cancel cancels the currently running timer. If a cancel is achieved, then
// this function will return after the timeout goroutine is finished
Cancel()
}
// NewTimeout returns a new Timeout instance
func NewTimeout() Timeout {
t := &timeout{
tk: time.NewTicker(time.Minute),
ch: make(chan struct{}),
}
t.tk.Stop() // don't keep it running
return t
}
// timeout is the Timeout implementation that we force
// initialization on via NewTimeout by unexporting it
type timeout struct {
type Timeout struct {
noCopy noCopy //nolint noCopy because a copy will mess with atomics
tk *time.Ticker // tk is the underlying timeout-timer
@ -59,10 +14,23 @@ type timeout struct {
st timeoutState // st stores the current timeout state (and protects concurrent use)
}
func (t *timeout) Start(d time.Duration, hook func()) error {
// NewTimeout returns a new Timeout instance
func NewTimeout() Timeout {
tk := time.NewTicker(time.Minute)
tk.Stop() // don't keep it running
return Timeout{
tk: tk,
ch: make(chan struct{}),
}
}
// Start starts the timer with supplied timeout. If timeout is reached before
// cancel then supplied timeout hook will be called. Error may be called if
// Timeout is already running when this function is called
func (t *Timeout) Start(d time.Duration, hook func()) {
// Attempt to acquire start
if !t.st.start() {
return ErrTimeoutStarted
panic("nowish: timeout already started")
}
// Start the ticker
@ -96,11 +64,11 @@ func (t *timeout) Start(d time.Duration, hook func()) error {
// Finally, reset state
t.st.reset()
}()
return nil
}
func (t *timeout) Cancel() {
// Cancel cancels the currently running timer. If a cancel is achieved, then
// this function will return after the timeout goroutine is finished
func (t *Timeout) Cancel() {
// Attempt to acquire stop
if !t.st.stop() {
return
@ -109,3 +77,21 @@ func (t *timeout) Cancel() {
// Send a cancel signal
t.ch <- struct{}{}
}
// timeoutState provides a thread-safe timeout state mechanism
type timeoutState uint32
// start attempts to start the state, must be already reset, returns success
func (t *timeoutState) start() bool {
return atomic.CompareAndSwapUint32((*uint32)(t), 0, 1)
}
// stop attempts to stop the state, must already be started, returns success
func (t *timeoutState) stop() bool {
return atomic.CompareAndSwapUint32((*uint32)(t), 1, 2)
}
// reset is fairly self explanatory
func (t *timeoutState) reset() {
atomic.StoreUint32((*uint32)(t), 0)
}

6
vendor/modules.txt vendored
View file

@ -13,13 +13,13 @@ git.iim.gay/grufwub/go-errors
# git.iim.gay/grufwub/go-hashenc v0.3.0
## explicit; go 1.16
git.iim.gay/grufwub/go-hashenc
# git.iim.gay/grufwub/go-mutexes v0.5.0
# git.iim.gay/grufwub/go-mutexes v0.5.1
## explicit; go 1.16
git.iim.gay/grufwub/go-mutexes
# git.iim.gay/grufwub/go-nowish v0.3.4
# git.iim.gay/grufwub/go-nowish v0.3.5
## explicit; go 1.16
git.iim.gay/grufwub/go-nowish
# git.iim.gay/grufwub/go-store v0.4.1
# git.iim.gay/grufwub/go-store v0.4.2
## explicit; go 1.16
git.iim.gay/grufwub/go-store/kv
git.iim.gay/grufwub/go-store/storage