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

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

#include <sync.hh>

Public Member Functions

 Spinlock ()
 Create a Spinlock.
 
void acquire ()
 Acquires the Spinlock.
 
void release ()
 Releases the Spinlock.
 
bool attempt ()
 Attempts to acquire the Spinlock.
 
bool nested () const
 Returns true iff the Spinlock has been acquired more than once by the current thread.
 

Detailed Description

A recursive spinlock for SMP Click threads.

The Spinlock class abstracts a 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 OK for a thread to acquire a lock it has already acquired, but you must release it as many times as you have acquired it.

See also
SimpleSpinlock, SpinlockIRQ

Constructor & Destructor Documentation

◆ Spinlock()

Spinlock::Spinlock ( )
inline

Create a Spinlock.

Member Function Documentation

◆ acquire()

void Spinlock::acquire ( )
inline

Acquires the Spinlock.

On return, this thread has acquired the lock. The function will spin indefinitely until the lock is acquired. It is OK to acquire a lock you have already acquired, but you must release it as many times as you have acquired it.

◆ release()

void Spinlock::release ( )
inline

Releases the Spinlock.

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

◆ attempt()

bool Spinlock::attempt ( )
inline

Attempts to acquire the Spinlock.

Returns
True iff the Spinlock was acquired.

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

◆ nested()

bool Spinlock::nested ( ) const
inline

Returns true iff the Spinlock has been acquired more than once by the current thread.


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