// NewHashed returns a new instance of KeyMutex which hashes arbitrary keys to // a fixed set of locks. `n` specifies number of locks, if n <= 0, we use // number of cpus. // Note that because it uses fixed set of locks, different keys may share same // lock, so it's possible to wait on same lock. func NewHashed(n int) KeyMutex { … } type hashedKeyMutex … // Acquires a lock associated with the specified ID. func (km *hashedKeyMutex) LockKey(id string) { … } // Releases the lock associated with the specified ID. func (km *hashedKeyMutex) UnlockKey(id string) error { … } func (km *hashedKeyMutex) hash(id string) uint32 { … }