Embedded Multicore Building Blocks V1.0.0
Public Member Functions | List of all members
embb::base::Spinlock Class Reference

Spinlock. More...

#include <mutex.h>

Public Member Functions

 Spinlock ()
 Creates a spinlock which is in unlocked state. More...
 
 ~Spinlock ()
 Destructs a spinlock. More...
 
void Lock ()
 Waits until the spinlock can be locked and locks it. More...
 
bool TryLock (unsigned int number_spins=1)
 Tries to lock the spinlock for number_spins times and returns. More...
 
void Unlock ()
 Unlocks the spinlock. More...
 

Detailed Description

Spinlock.

Implemented concepts:
Mutex Concept

Constructor & Destructor Documentation

embb::base::Spinlock::Spinlock ( )

Creates a spinlock which is in unlocked state.

Concurrency
Not thread-safe
embb::base::Spinlock::~Spinlock ( )

Destructs a spinlock.

Concurrency
Not thread-safe

Member Function Documentation

void embb::base::Spinlock::Lock ( )

Waits until the spinlock can be locked and locks it.

Note
This method yields the current thread in regular, implementation-defined intervals.
Precondition
The spinlock is not locked by the current thread.
Postcondition
The spinlock is locked.
Concurrency
Thread-safe
See also
TryLock(), Unlock()
bool embb::base::Spinlock::TryLock ( unsigned int  number_spins = 1)

Tries to lock the spinlock for number_spins times and returns.

Precondition
The spinlock is not locked by the current thread.
Postcondition
If successful, the spinlock is locked.
Returns
true if the spinlock could be locked, otherwise false.
Concurrency
Thread-safe
See also
Lock(), Unlock()
Parameters
[in]number_spinsMaximal number of spins when trying to acquire the lock. Note that passing 0 here results in not trying to obtain the lock at all. The default parameter is 1.
void embb::base::Spinlock::Unlock ( )

Unlocks the spinlock.

Precondition
The spinlock is locked by the current thread.
Postcondition
The spinlock is unlocked.
Concurrency
Thread-safe
See also
Lock(), TryLock()