mirror of
https://github.com/containers/podman.git
synced 2025-10-25 10:16:43 +08:00
Add lock manager to libpod runtime
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
committed by
Matthew Heon
parent
e73484c176
commit
a364b656ea
@ -41,11 +41,14 @@ type Locker interface {
|
||||
// Lock locks the lock.
|
||||
// This call MUST block until it successfully acquires the lock or
|
||||
// encounters a fatal error.
|
||||
Lock() error
|
||||
// All errors must be handled internally, as they are not returned. For
|
||||
// the most part, panicking should be appropriate.
|
||||
Lock()
|
||||
// Unlock unlocks the lock.
|
||||
// A call to Unlock() on a lock that is already unlocked lock MUST
|
||||
// error.
|
||||
Unlock() error
|
||||
// All errors must be handled internally, as they are not returned. For
|
||||
// the most part, panicking should be appropriate.
|
||||
// This includes unlocking locks which are already unlocked.
|
||||
Unlock()
|
||||
// Free deallocates the underlying lock, allowing its reuse by other
|
||||
// pods and containers.
|
||||
// The lock MUST still be usable after a Free() - some libpod instances
|
||||
|
||||
@ -12,9 +12,13 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
var (
|
||||
// BitmapSize is the size of the bitmap used when managing SHM locks.
|
||||
// an SHM lock manager's max locks will be rounded up to a multiple of
|
||||
// this number.
|
||||
BitmapSize uint32 = uint32(C.bitmap_size_c)
|
||||
)
|
||||
|
||||
@ -51,6 +55,8 @@ func CreateSHMLock(path string, numLocks uint32) (*SHMLocks, error) {
|
||||
locks.maxLocks = uint32(lockStruct.num_locks)
|
||||
locks.valid = true
|
||||
|
||||
logrus.Debugf("Initialized SHM lock manager at path %s", path)
|
||||
|
||||
return locks, nil
|
||||
}
|
||||
|
||||
|
||||
@ -73,13 +73,17 @@ func (l *SHMLock) ID() uint32 {
|
||||
}
|
||||
|
||||
// Lock acquires the lock.
|
||||
func (l *SHMLock) Lock() error {
|
||||
return l.manager.locks.LockSemaphore(l.lockID)
|
||||
func (l *SHMLock) Lock() {
|
||||
if err := l.manager.locks.LockSemaphore(l.lockID); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock releases the lock.
|
||||
func (l *SHMLock) Unlock() error {
|
||||
return l.manager.locks.UnlockSemaphore(l.lockID)
|
||||
func (l *SHMLock) Unlock() {
|
||||
if err := l.manager.locks.UnlockSemaphore(l.lockID); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Free releases the lock, allowing it to be reused.
|
||||
|
||||
Reference in New Issue
Block a user