github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/sentry/kernel/futex/futex_mutex.go (about)

     1  package futex
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/ttpreport/gvisor-ligolo/pkg/sync"
     7  	"github.com/ttpreport/gvisor-ligolo/pkg/sync/locking"
     8  )
     9  
    10  // Mutex is sync.Mutex with the correctness validator.
    11  type futexBucketMutex struct {
    12  	mu sync.Mutex
    13  }
    14  
    15  var futexBucketprefixIndex *locking.MutexClass
    16  
    17  // lockNames is a list of user-friendly lock names.
    18  // Populated in init.
    19  var futexBucketlockNames []string
    20  
    21  // lockNameIndex is used as an index passed to NestedLock and NestedUnlock,
    22  // refering to an index within lockNames.
    23  // Values are specified using the "consts" field of go_template_instance.
    24  type futexBucketlockNameIndex int
    25  
    26  // DO NOT REMOVE: The following function automatically replaced with lock index constants.
    27  const (
    28  	futexBucketLockB = futexBucketlockNameIndex(0)
    29  )
    30  const ()
    31  
    32  // Lock locks m.
    33  // +checklocksignore
    34  func (m *futexBucketMutex) Lock() {
    35  	locking.AddGLock(futexBucketprefixIndex, -1)
    36  	m.mu.Lock()
    37  }
    38  
    39  // NestedLock locks m knowing that another lock of the same type is held.
    40  // +checklocksignore
    41  func (m *futexBucketMutex) NestedLock(i futexBucketlockNameIndex) {
    42  	locking.AddGLock(futexBucketprefixIndex, int(i))
    43  	m.mu.Lock()
    44  }
    45  
    46  // Unlock unlocks m.
    47  // +checklocksignore
    48  func (m *futexBucketMutex) Unlock() {
    49  	locking.DelGLock(futexBucketprefixIndex, -1)
    50  	m.mu.Unlock()
    51  }
    52  
    53  // NestedUnlock unlocks m knowing that another lock of the same type is held.
    54  // +checklocksignore
    55  func (m *futexBucketMutex) NestedUnlock(i futexBucketlockNameIndex) {
    56  	locking.DelGLock(futexBucketprefixIndex, int(i))
    57  	m.mu.Unlock()
    58  }
    59  
    60  // DO NOT REMOVE: The following function is automatically replaced.
    61  func futexBucketinitLockNames() { futexBucketlockNames = []string{"b"} }
    62  
    63  func init() {
    64  	futexBucketinitLockNames()
    65  	futexBucketprefixIndex = locking.NewMutexClass(reflect.TypeOf(futexBucketMutex{}), futexBucketlockNames)
    66  }