29
var _ PriorityMutex = (*PriorityMutexImpl)(nil)
30
32
>
lock := &sync.Mutex{}
33
>
syncCV := NewConditionVariable(lock)
34
>
asyncCV := NewConditionVariable(lock)
35
>
return &PriorityMutexImpl{
36
>
locker: lock,
37
>
highCV: syncCV,
38
>
lowCV: asyncCV,
39
>
highWait: 0,
40
>
lowWait: 0,
41
>
42
>
lockState: PriorityMutexStateUnlocked,
43
>
}
44
>
}
45
46
// LockHigh try to lock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
47
func (c *PriorityMutexImpl) LockHigh(
48
ctx context.Context,
50
>
c.locker.Lock()
51
>
defer c.locker.Unlock()
52
>
53
>
c.highWait += 1
54
>
defer func() { c.highWait -= 1 }()
55
58
>
}
59
61
return ctx.Err()
62
}
63
65
>
return nil
66
}
67