Documentation
¶
Overview ¶
Package semaphore provides synchronisation primitives for controlling access to shared resources.
Index ¶
- type Semaphore
- func (s *Semaphore) Lock()
- func (s *Semaphore) LockContext(ctx context.Context) error
- func (s *Semaphore) RLock()
- func (s *Semaphore) RLockContext(ctx context.Context) error
- func (s *Semaphore) RUnlock()
- func (s *Semaphore) TryLock() bool
- func (s *Semaphore) TryRLock() bool
- func (s *Semaphore) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore provides a synchronisation primitive for controlling access to shared resources using a spinlock mechanism. It supports both exclusive and read locks with context-aware and blocking acquisition methods.
func (*Semaphore) Lock ¶
func (s *Semaphore) Lock()
Lock acquires an exclusive lock. Blocks until the lock is acquired and cannot be cancelled. Panics if the lock cannot be acquired.
func (*Semaphore) LockContext ¶
LockContext attempts to acquire an exclusive lock with a context. Blocks until the lock is acquired or the context is cancelled. Returns an error if the context is cancelled before acquisition.
func (*Semaphore) RLock ¶
func (s *Semaphore) RLock()
RLock acquires a read lock. Blocks until the lock is acquired and cannot be cancelled. Panics if the semaphore is nil.
func (*Semaphore) RLockContext ¶
RLockContext attempts to acquire a read lock with a context. Blocks until the lock is acquired or the context is cancelled. Returns an error if the context is cancelled before acquisition.
func (*Semaphore) RUnlock ¶
func (s *Semaphore) RUnlock()
RUnlock releases a read lock, allowing other readers or writers to acquire the lock. Panics if the lock is not held or cannot be released.
func (*Semaphore) TryLock ¶
TryLock attempts to acquire an exclusive lock without blocking. Returns immediately with a boolean indicating success. Returns true if the lock was successfully acquired, false otherwise.