github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/libpod/network/lock.go (about)

     1  package network
     2  
     3  import (
     4  	"github.com/containers/storage"
     5  )
     6  
     7  // acquireCNILock gets a lock that should be used in create and
     8  // delete cases to avoid unwanted collisions in network names.
     9  // TODO this uses a file lock and should be converted to shared memory
    10  // when we have a more general shared memory lock in libpod
    11  func acquireCNILock(lockPath string) (*CNILock, error) {
    12  	l, err := storage.GetLockfile(lockPath)
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  	l.Lock()
    17  	cnilock := CNILock{
    18  		Locker: l,
    19  	}
    20  	return &cnilock, nil
    21  }
    22  
    23  // ReleaseCNILock unlocks the previously held lock
    24  func (l *CNILock) releaseCNILock() {
    25  	l.Unlock()
    26  }