Live video on the AT Protocol
at eli/bump-xcode 47 lines 916 B view raw
1package atproto 2 3import "sync" 4 5// handleLocks provides per-handle synchronization 6var handleLocks = struct { 7 sync.Mutex 8 locks map[string]*sync.Mutex 9}{ 10 locks: make(map[string]*sync.Mutex), 11} 12 13// getHandleLock returns a mutex for the given handle 14func getHandleLock(handle string) *sync.Mutex { 15 handleLocks.Lock() 16 defer handleLocks.Unlock() 17 18 if lock, exists := handleLocks.locks[handle]; exists { 19 return lock 20 } 21 22 lock := &sync.Mutex{} 23 handleLocks.locks[handle] = lock 24 return lock 25} 26 27// pdsLocks provides per-pds synchronization 28var pdsLocks = struct { 29 sync.Mutex 30 locks map[string]*sync.Mutex 31}{ 32 locks: make(map[string]*sync.Mutex), 33} 34 35// getpdsLock returns a mutex for the given pds 36func getPDSLock(pds string) *sync.Mutex { 37 pdsLocks.Lock() 38 defer pdsLocks.Unlock() 39 40 if lock, exists := pdsLocks.locks[pds]; exists { 41 return lock 42 } 43 44 lock := &sync.Mutex{} 45 pdsLocks.locks[pds] = lock 46 return lock 47}