CrossThreadValueNode Class
(CDP::StudioAPI::CrossThreadValueNode)A class for the cross-thread manipulatable value. Can be used in situations where a value needs to be manipulated (read and/or written) from a thread context. The shadow value of the node is created in the thread context and can be manipulated there. An addition, a thread context value copy is created for direct manipulation in the thread context and to determine if the thread context value has been changed and the change should be synced back to the node context. All value synchronization between the threads is done without mutexes - only using lockfree commands queues. More...
Header: | #include <CrossThreadValueNode> |
Public Functions
CrossThreadValueNode(ICDPNode *node, RunInThreadQueue *threadContextRunQueue, const std::function<void( CrossThreadValueNodeBase * pointerToMe ) > &onNodeRemove = {}) | |
~CrossThreadValueNode() override | |
T & | GetThreadContextValueRef() |
Reimplemented Public Functions
virtual void | AddSyncThreadContextValueToNodeQueue() override |
virtual bool | IsThreadContextAndShadowValuesDifferent() const override |
virtual void | UpdateThreadContextValueFromNodeShadow() override |
Detailed Description
A class for the cross-thread manipulatable value. Can be used in situations where a value needs to be manipulated (read and/or written) from a thread context. The shadow value of the node is created in the thread context and can be manipulated there. An addition, a thread context value copy is created for direct manipulation in the thread context and to determine if the thread context value has been changed and the change should be synced back to the node context. All value synchronization between the threads is done without mutexes - only using lockfree commands queues.
Note: The template type of the class can be different from the node that will be synced - then value converting occurs on sync time.
CrossThreadValueNode constructor parameters:
- node - The node to create the cross-thread manipulatable value for
- threadContextRunQueue - The run queue for the thread context to post value-change commands to
Note: When threadContextRunQueue is not set (nullptr), then the syncing will be unidirectional - i.e. value is not synced from node context to thread context. Value can then only be synced from thread context to node context (using AddSyncThreadContextValueToNodeQueue() method). This unidirectional syncing can be useful when the value is only written from the thread context and read in the node context (like updating values of read-only output signals, properties or arguments from thread).
- onNodeRemove - Optional callback to be called when the node context reports node was removed
Note: The constructor of the CrossThreadValueNode should be always called from thread context and with the node context GetMemberAccessMutex() locked.
Member Function Documentation
CrossThreadValueNode::CrossThreadValueNode(ICDPNode *node, RunInThreadQueue *threadContextRunQueue, const std::function<void( CrossThreadValueNodeBase * pointerToMe ) > &onNodeRemove = {})
Copy constructor.
CrossThreadValueNode::~CrossThreadValueNode()
Destroys the instance of CrossThreadValueNode.
[override virtual]
void CrossThreadValueNode::AddSyncThreadContextValueToNodeQueue()
Places a command to node context queue to sync the thread context to the node context value
Note: This method should be called only in the thread context.
T &CrossThreadValueNode::GetThreadContextValueRef()
Returns reference to thread context value for direct manipulation in thread context
Note: This method should be called only in the thread context
[override virtual]
bool CrossThreadValueNode::IsThreadContextAndShadowValuesDifferent() const
[override virtual]
void CrossThreadValueNode::UpdateThreadContextValueFromNodeShadow()
Copies the current shadow value to the thread context value
Note: This method should be called only in the thread context.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.