SOFA API  73d8bb95
Open source framework for multi-physics simuation
sofa::core::objectmodel::AspectBuffer Class Reference

#include <AspectPool.h>

Detailed Description

This class is responsible for providing a buffer for communicating aspects between threads, such that only the most up to date aspect is kept, and the previous one is reused to send the next update. This is similar to triple buffering.

Protected Attributes

AspectPoolpool
 
AtomicInt latestID
 -1 or aspect ID of the last version sent More...
 
AtomicInt availableID
 -1 or aspect ID available to send the next version More...
 

Public Member Functions

 AspectBuffer (AspectPool &pool)
 
 ~AspectBuffer ()
 
AspectRef allocate ()
 Allocate an aspect ID to prepare the next version, reusing a recent one if possible. More...
 
void push (AspectRef id)
 Send a new version, overriding the latest if it was not already received (in which case it can be "recycled" using allocate) More...
 
bool pop (AspectRef &id)
 Receive the latest version, return true if one is available, or false otherwise (in which case id is unchanged) More...
 
void clear ()
 

Attribute details

AtomicInt sofa::core::objectmodel::AspectBuffer::availableID
protected

-1 or aspect ID available to send the next version

AtomicInt sofa::core::objectmodel::AspectBuffer::latestID
protected

-1 or aspect ID of the last version sent

AspectPool& sofa::core::objectmodel::AspectBuffer::pool
protected

Constructor details

sofa::core::objectmodel::AspectBuffer::AspectBuffer ( AspectPool pool)
sofa::core::objectmodel::AspectBuffer::~AspectBuffer ( )

Function details

AspectRef sofa::core::objectmodel::AspectBuffer::allocate ( )

Allocate an aspect ID to prepare the next version, reusing a recent one if possible.

void sofa::core::objectmodel::AspectBuffer::clear ( )

Clear the buffers This must be called before either the AspectPool or this buffer is deleted

bool sofa::core::objectmodel::AspectBuffer::pop ( AspectRef id)

Receive the latest version, return true if one is available, or false otherwise (in which case id is unchanged)

void sofa::core::objectmodel::AspectBuffer::push ( AspectRef  id)

Send a new version, overriding the latest if it was not already received (in which case it can be "recycled" using allocate)