gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 635281f1339e2cbe0be4e801545d126090d57f6d
parent f6492d12d948507021bbe934de94e87e20464c01
Author: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
Date:   Mon, 13 Sep 2021 09:33:01 +0100

update my personal library versions (#220)

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat:
Mgo.mod | 6+++---
Mgo.sum | 12++++++------
Mvendor/git.iim.gay/grufwub/go-mutexes/map.go | 24++++++++----------------
Mvendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go | 11++++++-----
Mvendor/git.iim.gay/grufwub/go-nowish/timeout.go | 86+++++++++++++++++++++++++++++++++----------------------------------------------
Mvendor/modules.txt | 6+++---
6 files changed, 62 insertions(+), 83 deletions(-)

diff --git a/go.mod b/go.mod @@ -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 diff --git a/go.sum b/go.sum @@ -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= diff --git a/vendor/git.iim.gay/grufwub/go-mutexes/map.go b/vendor/git.iim.gay/grufwub/go-mutexes/map.go @@ -8,15 +8,7 @@ import ( // 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() diff --git a/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go b/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go @@ -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) diff --git a/vendor/git.iim.gay/grufwub/go-nowish/timeout.go b/vendor/git.iim.gay/grufwub/go-nowish/timeout.go @@ -1,68 +1,36 @@ 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() +type Timeout struct { + noCopy noCopy //nolint noCopy because a copy will mess with atomics + + tk *time.Ticker // tk is the underlying timeout-timer + ch chan struct{} // ch is the cancel propagation channel + st timeoutState // st stores the current timeout state (and protects concurrent use) } // NewTimeout returns a new Timeout instance func NewTimeout() Timeout { - t := &timeout{ - tk: time.NewTicker(time.Minute), + tk := time.NewTicker(time.Minute) + tk.Stop() // don't keep it running + return Timeout{ + tk: tk, 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 { - noCopy noCopy //nolint noCopy because a copy will mess with atomics - - tk *time.Ticker // tk is the underlying timeout-timer - ch chan struct{} // ch is the cancel propagation channel - st timeoutState // st stores the current timeout state (and protects concurrent use) } -func (t *timeout) Start(d time.Duration, hook func()) error { +// 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) +} diff --git a/vendor/modules.txt b/vendor/modules.txt @@ -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