Click
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SimpleSpinlock Class Reference

A non-recursive spinlock for SMP Click threads. More...

#include <sync.hh>

Public Member Functions

 SimpleSpinlock ()
 Create a SimpleSpinlock.
 
void acquire ()
 Acquires the SimpleSpinlock.
 
void release ()
 Releases the SimpleSpinlock.
 
bool attempt ()
 Attempts to acquire the SimpleSpinlock.
 

Detailed Description

A non-recursive spinlock for SMP Click threads.

The Spinlock class abstracts a non-recursive spinlock, or polling mutex, in SMP Click. This is a type of mutual-exclusion lock in which acquiring the lock is a polling operation (basically a "while (lock.acquired()) do nothing;" loop). Spinlocks can be used to synchronize access to shared data among multiple Click SMP threads. Spinlocks should not be held for long periods of time: use them for quick updates and such.

Spinlock operations do nothing unless Click was compiled with SMP support (with –enable-multithread). Therefore, Spinlock should not be used to, for example, synchronize handlers with main element threads. See also SpinlockIRQ.

The main Spinlock operations are acquire(), which acquires the lock, and release(), which releases the lock. attempt() acquires the lock only if it can be acquired instantaneously.

It is NOT OK for a thread to acquire a lock it has already acquired.

See also
Spinlock, SpinlockIRQ

Constructor & Destructor Documentation

◆ SimpleSpinlock()

SimpleSpinlock::SimpleSpinlock ( )
inline

Create a SimpleSpinlock.

Member Function Documentation

◆ acquire()

void SimpleSpinlock::acquire ( )
inline

Acquires the SimpleSpinlock.

On return, this thread has acquired the lock. The function will spin indefinitely until the lock is acquired.

◆ release()

void SimpleSpinlock::release ( )
inline

Releases the SimpleSpinlock.

The SimpleSpinlock must have been previously acquired by either SimpleSpinlock::acquire or SimpleSpinlock::attempt.

◆ attempt()

bool SimpleSpinlock::attempt ( )
inline

Attempts to acquire the SimpleSpinlock.

Returns
True iff the SimpleSpinlock was acquired.

This function will acquire the lock and return true only if the SimpleSpinlock can be acquired right away, without retries.


The documentation for this class was generated from the following file: