A token to hold the scope of an ArrayHandle
or other object.
A Token
is an object that is held in the stack or state of another object and is used when creating references to resouces that may be used by other threads. For example, when preparing an ArrayHandle
or ExecutionObject
for a device, a Token
is given. The returned object will be valid as long as the Token
remains in scope.
template<typename T >
void vtkm::cont::Token::Attach |
( |
T && |
object, |
|
|
vtkm::cont::Token::ReferenceCount * |
referenceCountPoiner, |
|
|
std::mutex * |
mutexPointer, |
|
|
std::condition_variable * |
conditionVariablePointer |
|
) |
| |
|
inline |
Add an object to attach to the Token
.
To attach an object to a Token
, you need the object itself, a pointer to a Token::ReferenceCount
that is used to count how many Token
s hold the object, a pointer to a std::mutex
used to safely use the ReferenceCount
, and a pointer to a std::condition_variable
that other threads will wait on if they are blocked by the Token
(using the same mutex
in the given unique_lock
). The mutex can also be passed in as a std::unique_lock<std::mutex>
to signal whether or not the mutex is already locked by the current thread.
When the Token
is attached, it will increment the reference count (safely with the mutex) and store away these items. Other items will be able tell if a token is attached to the object by looking at the reference count.
When the Token
is released, it will decrement the reference count (safely with the mutex) and then notify all threads waiting on the condition variable.
template<typename T >
void vtkm::cont::Token::Attach |
( |
T && |
object, |
|
|
vtkm::cont::Token::ReferenceCount * |
referenceCountPointer, |
|
|
std::unique_lock< std::mutex > & |
lock, |
|
|
std::condition_variable * |
conditionVariablePointer |
|
) |
| |
|
inline |
Add an object to attach to the Token
.
To attach an object to a Token
, you need the object itself, a pointer to a Token::ReferenceCount
that is used to count how many Token
s hold the object, a pointer to a std::mutex
used to safely use the ReferenceCount
, and a pointer to a std::condition_variable
that other threads will wait on if they are blocked by the Token
(using the same mutex
in the given unique_lock
). The mutex can also be passed in as a std::unique_lock<std::mutex>
to signal whether or not the mutex is already locked by the current thread.
When the Token
is attached, it will increment the reference count (safely with the mutex) and store away these items. Other items will be able tell if a token is attached to the object by looking at the reference count.
When the Token
is released, it will decrement the reference count (safely with the mutex) and then notify all threads waiting on the condition variable.