github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/checklocks/test/test.go (about)

     1  // Copyright 2020 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 test is a test package.
    16  //
    17  // Tests are all compilation tests in separate files.
    18  package test
    19  
    20  import (
    21  	"sync"
    22  )
    23  
    24  // oneGuardStruct has one guarded field.
    25  type oneGuardStruct struct {
    26  	mu sync.Mutex
    27  	// +checklocks:mu
    28  	guardedField   int
    29  	unguardedField int
    30  }
    31  
    32  // twoGuardStruct has two guarded fields.
    33  type twoGuardStruct struct {
    34  	mu sync.Mutex
    35  	// +checklocks:mu
    36  	guardedField1 int
    37  	// +checklocks:mu
    38  	guardedField2 int
    39  }
    40  
    41  // twoLocksStruct has two locks and two fields.
    42  type twoLocksStruct struct {
    43  	mu       sync.Mutex
    44  	secondMu sync.Mutex
    45  	// +checklocks:mu
    46  	guardedField1 int
    47  	// +checklocks:secondMu
    48  	guardedField2 int
    49  }
    50  
    51  // twoLocksDoubleGuardStruct has two locks and a single field with two guards.
    52  type twoLocksDoubleGuardStruct struct {
    53  	mu       sync.Mutex
    54  	secondMu sync.Mutex
    55  	// +checklocks:mu
    56  	// +checklocks:secondMu
    57  	doubleGuardedField int
    58  }
    59  
    60  // nestedGuardStruct nests oneGuardStruct fields.
    61  type nestedGuardStruct struct {
    62  	val oneGuardStruct
    63  	ptr *oneGuardStruct
    64  }