shm

package
v3.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
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(C.bitmap_size_c)
)

Functions

This section is empty.

Types

type SHMLocks

type SHMLocks struct {
	// contains filtered or unexported fields
}

SHMLocks is a struct enabling POSIX semaphore locking in a shared memory segment.

func CreateSHMLock

func CreateSHMLock(path string, numLocks uint32) (*SHMLocks, error)

CreateSHMLock sets up a shared-memory segment holding a given number of POSIX semaphores, and returns a struct that can be used to operate on those locks. numLocks must not be 0, and may be rounded up to a multiple of the bitmap size used by the underlying implementation.

func OpenSHMLock

func OpenSHMLock(path string, numLocks uint32) (*SHMLocks, error)

OpenSHMLock opens an existing shared-memory segment holding a given number of POSIX semaphores. numLocks must match the number of locks the shared memory segment was created with.

func (*SHMLocks) AllocateGivenSemaphore

func (locks *SHMLocks) AllocateGivenSemaphore(sem uint32) error

AllocateGivenSemaphore allocates the given semaphore from the shared-memory segment for use by a container or pod. If the semaphore is already in use or the index is invalid an error will be returned.

func (*SHMLocks) AllocateSemaphore

func (locks *SHMLocks) AllocateSemaphore() (uint32, error)

AllocateSemaphore allocates a semaphore from a shared-memory segment for use by a container or pod. Returns the index of the semaphore that was allocated. Allocations past the maximum number of locks given when the SHM segment was created will result in an error, and no semaphore will be allocated.

func (*SHMLocks) Close

func (locks *SHMLocks) Close() error

Close closes an existing shared-memory segment. The segment will be rendered unusable after closing. WARNING: If you Close() while there are still locks locked, these locks may fail to release, causing a program freeze. Close() is only intended to be used while testing the locks.

func (*SHMLocks) DeallocateAllSemaphores

func (locks *SHMLocks) DeallocateAllSemaphores() error

DeallocateAllSemaphores frees all semaphores so they can be reallocated to other containers and pods.

func (*SHMLocks) DeallocateSemaphore

func (locks *SHMLocks) DeallocateSemaphore(sem uint32) error

DeallocateSemaphore frees a semaphore in a shared-memory segment so it can be reallocated to another container or pod. The given semaphore must be already allocated, or an error will be returned.

func (*SHMLocks) GetMaxLocks

func (locks *SHMLocks) GetMaxLocks() uint32

GetMaxLocks returns the maximum number of locks in the SHM

func (*SHMLocks) LockSemaphore

func (locks *SHMLocks) LockSemaphore(sem uint32) error

LockSemaphore locks the given semaphore. If the semaphore is already locked, LockSemaphore will block until the lock can be acquired. There is no requirement that the given semaphore be allocated. This ensures that attempts to lock a container after it has been deleted, but before the caller has queried the database to determine this, will succeed.

func (*SHMLocks) UnlockSemaphore

func (locks *SHMLocks) UnlockSemaphore(sem uint32) error

UnlockSemaphore unlocks the given semaphore. Unlocking a semaphore that is already unlocked with return EBUSY. There is no requirement that the given semaphore be allocated. This ensures that attempts to lock a container after it has been deleted, but before the caller has queried the database to determine this, will succeed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL