rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rexlib::access_hazard_tracker Class Reference

Tracks the commands that access a piece of memory. More...

#include <rexlib/core/ndarray/access_hazard_tracker.hpp>

Public Member Functions

 access_hazard_tracker ()
 Construct a tracker with no command recorded.
 
 access_hazard_tracker (const access_hazard_tracker &other)=delete
 
 access_hazard_tracker (access_hazard_tracker &&other)=delete
 
access_hazard_tracker & operator= (const access_hazard_tracker &other)=delete
 
access_hazard_tracker & operator= (access_hazard_tracker &&other)=delete
 
void add (command_token token, access_flags access)
 Record a command that accesses the memory.
 
void collect (access_flags access, std::vector< command_token > &tokens) const
 Get the tokens that an access has to wait for.
 
void wait (access_flags access) const
 Block the calling thread until an access can take place.
 

Detailed Description

Tracks the commands that access a piece of memory.

The tracker holds the token of the last command that writes the memory and the tokens of the commands that read it since. It tells an access which of them it has to wait for: a read waits for the write, and a write waits for the write and for every read.

An access that includes a write is a write.

Thread safety
Every method may be called concurrently.

Member Function Documentation

◆ add()

void rexlib::access_hazard_tracker::add ( command_token  token,
access_flags  access 
)

Record a command that accesses the memory.

A read is added to the reads recorded since the last write. A write replaces everything recorded before it, so the command has to wait for the tokens that collect gives a write.

Parameters
tokenThe token of the command. An empty token is not kept.
accessHow the command accesses the memory.
Exceptions
std::invalid_argumentIf access is empty.

◆ collect()

void rexlib::access_hazard_tracker::collect ( access_flags  access,
std::vector< command_token > &  tokens 
) const

Get the tokens that an access has to wait for.

Parameters
accessHow the memory is going to be accessed.
tokensOutput parameter where the tokens are appended.
Exceptions
std::invalid_argumentIf access is empty.

◆ wait()

void rexlib::access_hazard_tracker::wait ( access_flags  access) const

Block the calling thread until an access can take place.

Waits for the tokens that collect gives access.

Parameters
accessHow the memory is going to be accessed.
Exceptions
std::invalid_argumentIf access is empty.

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