Source File
lock.go
Belonging Package
github.com/mlange-42/ark/ecs
package ecsimport ()// Manages locks by mask bits.//// The number of simultaneous locks at a given time is limited to 64.type lock struct {bitPool bitPool // The bit pool for getting and recycling bits.locks bitMask64 // The actual locks.mu sync.Mutex}func newLock() lock {return lock{bitPool: newBitPool(),}}// Lock the world and get the Lock bit for later unlocking.// This is not concurrency-safe.func ( *lock) () uint8 {:= .bitPool.Get().locks.Set()return}// Unlock unlocks the given lock bit.// This is not concurrency-safe.func ( *lock) ( uint8) {if !.locks.Get() {panic("unbalanced unlock. Did you close a query that was already iterated?")}.locks.Clear().bitPool.Recycle()}// LockSafe locks the world and get the Lock bit for later unlocking.// This is concurrency-safe.func ( *lock) () uint8 {.mu.Lock():= .bitPool.Get().locks.Set().mu.Unlock()return}// UnlockSafe unlocks the given lock bit.// This is concurrency-safe.func ( *lock) ( uint8) {.mu.Lock()if !.locks.Get() {.mu.Unlock()panic("unbalanced unlock. Did you close a query that was already iterated?")}.locks.Clear().bitPool.Recycle().mu.Unlock()}// IsLocked returns whether the world is locked by any queries.func ( *lock) () bool {return !.locks.IsZero()}// Reset the locks and the pool.func ( *lock) () {.locks = bitMask64{}.bitPool.Reset()}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |