7 type LevelMutex struct {
9 // Protected by the very last mutex.
13 func (lm *LevelMutex) Init(levels int) {
15 panic("level mutex already initialized")
17 lm.mus = make([]sync.Mutex, levels)
20 func (lm *LevelMutex) Lock() {
24 func (lm *LevelMutex) Unlock() {
25 stopLevel := lm.lastLevel
26 for i := len(lm.mus) - 1; i >= stopLevel; i-- {
31 func (lm *LevelMutex) LevelLock(level int) {
32 if level >= len(lm.mus) {
33 panic("lock level exceeds configured level count")
35 for l := level; l < len(lm.mus); l++ {