Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
GEO::Process::SpinLockArray Class Reference

An array of light-weight synchronisation primitives (spinlocks). More...

#include <geogram/basic/thread_sync.h>

Public Types

typedef Numeric::uint32 word_t
 Internal representation of SpinLockArray elements.
 

Public Member Functions

 SpinLockArray ()
 Constructs a new SpinLockArray of size 0.
 
 SpinLockArray (index_t size_in)
 Constructs a new SpinLockArray of size size_in.
 
void resize (index_t size_in)
 Resizes a SpinLockArray.
 
index_t size () const
 Gets the number of spinlocks in this array.
 
void clear ()
 Resets size to 0 and clears all the memory.
 
void acquire_spinlock (index_t i)
 Acquires a spinlock at a given index.
 
void release_spinlock (index_t i)
 Releases a spinlock at a given index.
 

Detailed Description

An array of light-weight synchronisation primitives (spinlocks).

In this implementation, storage is optimized so that a single bit per spinlock is used.

See also
acquire_spinlock(), release_spinlock()

Definition at line 513 of file thread_sync.h.

Member Typedef Documentation

◆ word_t

Internal representation of SpinLockArray elements.

Each word_t represents 32 spinlocks.

Definition at line 519 of file thread_sync.h.

Constructor & Destructor Documentation

◆ SpinLockArray() [1/2]

GEO::Process::SpinLockArray::SpinLockArray ( )
inline

Constructs a new SpinLockArray of size 0.

Definition at line 524 of file thread_sync.h.

◆ SpinLockArray() [2/2]

GEO::Process::SpinLockArray::SpinLockArray ( index_t  size_in)
inline

Constructs a new SpinLockArray of size size_in.

Parameters
[in]size_innumber of spinlocks in the array.

Definition at line 531 of file thread_sync.h.

Member Function Documentation

◆ acquire_spinlock()

void GEO::Process::SpinLockArray::acquire_spinlock ( index_t  i)
inline

Acquires a spinlock at a given index.

Loops until spinlock at index i is available then reserve it.

Parameters
[in]iindex of the spinlock

Definition at line 568 of file thread_sync.h.

◆ clear()

void GEO::Process::SpinLockArray::clear ( )
inline

Resets size to 0 and clears all the memory.

Definition at line 558 of file thread_sync.h.

◆ release_spinlock()

void GEO::Process::SpinLockArray::release_spinlock ( index_t  i)
inline

Releases a spinlock at a given index.

Makes spinlock at index i available to other threads.

Parameters
[in]iindex of the spinlock

Definition at line 585 of file thread_sync.h.

◆ resize()

void GEO::Process::SpinLockArray::resize ( index_t  size_in)
inline

Resizes a SpinLockArray.

All the spinlocks are reset to 0.

Parameters
[in]size_inThe desired new size.

Definition at line 540 of file thread_sync.h.

◆ size()

index_t GEO::Process::SpinLockArray::size ( ) const
inline

Gets the number of spinlocks in this array.

Definition at line 551 of file thread_sync.h.


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