Documentation ¶
Overview ¶
Package semaphore implements System V semaphores.
Index ¶
- type Registry
- func (r *Registry) FindByID(id ipc.ID) *Set
- func (r *Registry) FindByIndex(index int32) *Set
- func (r *Registry) FindOrCreate(ctx context.Context, key ipc.Key, nsems int32, mode linux.FileMode, ...) (*Set, error)
- func (r *Registry) HighestIndex() int32
- func (r *Registry) IPCInfo() *linux.SemInfo
- func (r *Registry) Remove(id ipc.ID, creds *auth.Credentials) error
- func (r *Registry) SemInfo() *linux.SemInfo
- func (r *Registry) StateFields() []string
- func (r *Registry) StateLoad(stateSourceObject state.Source)
- func (r *Registry) StateSave(stateSinkObject state.Sink)
- func (r *Registry) StateTypeName() string
- type Set
- func (s *Set) AbortWait(num int32, ch chan struct{})
- func (s *Set) CountNegativeWaiters(num int32, creds *auth.Credentials) (uint16, error)
- func (s *Set) CountZeroWaiters(num int32, creds *auth.Credentials) (uint16, error)
- func (s *Set) Destroy()
- func (s *Set) ExecuteOps(ctx context.Context, ops []linux.Sembuf, creds *auth.Credentials, pid int32) (chan struct{}, int32, error)
- func (s *Set) GetPID(num int32, creds *auth.Credentials) (int32, error)
- func (s *Set) GetStat(creds *auth.Credentials) (*linux.SemidDS, error)
- func (s *Set) GetStatAny(creds *auth.Credentials) (*linux.SemidDS, error)
- func (s *Set) GetVal(num int32, creds *auth.Credentials) (int16, error)
- func (s *Set) GetValAll(creds *auth.Credentials) ([]uint16, error)
- func (s *Set) ID() ipc.ID
- func (s *Set) Lock()
- func (s *Set) Object() *ipc.Object
- func (s *Set) Set(ctx context.Context, ds *linux.SemidDS) error
- func (s *Set) SetVal(ctx context.Context, num int32, val int16, creds *auth.Credentials, pid int32) error
- func (s *Set) SetValAll(ctx context.Context, vals []uint16, creds *auth.Credentials, pid int32) error
- func (s *Set) Size() int
- func (s *Set) StateFields() []string
- func (s *Set) StateLoad(stateSourceObject state.Source)
- func (s *Set) StateSave(stateSinkObject state.Sink)
- func (s *Set) StateTypeName() string
- func (s *Set) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maintains a set of semaphores that can be found by key or ID.
+stateify savable
func NewRegistry ¶
func NewRegistry(userNS *auth.UserNamespace) *Registry
NewRegistry creates a new semaphore set registry.
func (*Registry) FindByIndex ¶
FindByIndex looks up a set given an index.
func (*Registry) FindOrCreate ¶
func (r *Registry) FindOrCreate(ctx context.Context, key ipc.Key, nsems int32, mode linux.FileMode, private, create, exclusive bool) (*Set, error)
FindOrCreate searches for a semaphore set that matches 'key'. If not found, it may create a new one if requested. If private is true, key is ignored and a new set is always created. If create is false, it fails if a set cannot be found. If exclusive is true, it fails if a set with the same key already exists.
func (*Registry) HighestIndex ¶
HighestIndex returns the index of the highest used entry in the kernel's array.
func (*Registry) IPCInfo ¶
IPCInfo returns information about system-wide semaphore limits and parameters.
func (*Registry) Remove ¶
Remove removes set with give 'id' from the registry and marks the set as dead. All waiters will be awakened and fail.
func (*Registry) SemInfo ¶
SemInfo returns a seminfo structure containing the same information as for IPC_INFO, except that SemUsz field returns the number of existing semaphore sets, and SemAem field returns the number of existing semaphores.
func (*Registry) StateFields ¶
func (*Registry) StateTypeName ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents a set of semaphores that can be operated atomically.
+stateify savable
func (*Set) AbortWait ¶
AbortWait notifies that a waiter is giving up and will not wait on the channel anymore.
func (*Set) CountNegativeWaiters ¶
CountNegativeWaiters returns number of waiters waiting for the sem to go to zero.
func (*Set) CountZeroWaiters ¶
CountZeroWaiters returns number of waiters waiting for the sem's value to increase.
func (*Set) Destroy ¶
func (s *Set) Destroy()
Destroy implements ipc.Mechanism.Destroy.
Preconditions: Caller must hold 's.mu'.
func (*Set) ExecuteOps ¶
func (s *Set) ExecuteOps(ctx context.Context, ops []linux.Sembuf, creds *auth.Credentials, pid int32) (chan struct{}, int32, error)
ExecuteOps attempts to execute a list of operations to the set. It only succeeds when all operations can be applied. No changes are made if it fails.
On failure, it may return an error (retries are hopeless) or it may return a channel that can be waited on before attempting again.
func (*Set) GetStatAny ¶
GetStatAny extracts semid_ds information from the set without requiring read access.
func (*Set) GetValAll ¶
func (s *Set) GetValAll(creds *auth.Credentials) ([]uint16, error)
GetValAll returns value for all semaphores.
func (*Set) SetVal ¶
func (s *Set) SetVal(ctx context.Context, num int32, val int16, creds *auth.Credentials, pid int32) error
SetVal overrides a semaphore value, waking up waiters as needed.
func (*Set) SetValAll ¶
func (s *Set) SetValAll(ctx context.Context, vals []uint16, creds *auth.Credentials, pid int32) error
SetValAll overrides all semaphores values, waking up waiters as needed. It also sets semaphore's PID which was fixed in Linux 4.6.
'len(vals)' must be equal to 's.Size()'.