1 // Copyright 2022 The gVisor Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 15 // Package locking implements lock primitives with the correctness validator.
16 //
17 // All mutexes are divided on classes and the validator check following conditions:
18 // - Mutexes of the same class are not taken more than once except cases when
19 // that is expected.
20 // - Mutexes are never locked in a reverse order. Lock dependencies are tracked
21 // on the class level.
22 //
23 // The validator is implemented in a very straightforward way. For each mutex
24 // class, we maintain the ancestors list of all classes that have ever been
25 // taken before the target one. For each goroutine, we have the list of
26 // currently locked mutexes. And finally, all lock methods check that
27 // ancestors of currently locked mutexes don't contain the target one.
28 package locking
29