gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/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 // 19 // +checkalignedignore 20 package test 21 22 import ( 23 "sync" 24 ) 25 26 // oneGuardStruct has one guarded field. 27 type oneGuardStruct struct { 28 mu sync.Mutex 29 // +checklocks:mu 30 guardedField int 31 unguardedField int 32 } 33 34 // twoGuardStruct has two guarded fields. 35 type twoGuardStruct struct { 36 mu sync.Mutex 37 // +checklocks:mu 38 guardedField1 int 39 // +checklocks:mu 40 guardedField2 int 41 } 42 43 // twoLocksStruct has two locks and two fields. 44 type twoLocksStruct struct { 45 mu sync.Mutex 46 secondMu sync.Mutex 47 // +checklocks:mu 48 guardedField1 int 49 // +checklocks:secondMu 50 guardedField2 int 51 } 52 53 // twoLocksDoubleGuardStruct has two locks and a single field with two guards. 54 type twoLocksDoubleGuardStruct struct { 55 mu sync.Mutex 56 secondMu sync.Mutex // +checklocksignore: mu is inferred as requisite. 57 // +checklocks:mu 58 // +checklocks:secondMu 59 doubleGuardedField int 60 } 61 62 // nestedGuardStruct nests oneGuardStruct fields. 63 type nestedGuardStruct struct { 64 val oneGuardStruct 65 ptr *oneGuardStruct 66 }