From 805451d4d329f4b49c6565b58d5662c6a1dea4f7 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 14 Oct 2024 14:18:45 -0400 Subject: [PATCH] cwFlowTypes.h/cpp : Added var_send_to_ui(). This included the addition of ui_var_head/stub/tail and ui_callback to flow_t and the ui_var and ui_var_link to variable_t. --- cwFlowTypes.cpp | 28 ++++++++++++++++++++++++++++ cwFlowTypes.h | 17 +++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cwFlowTypes.cpp b/cwFlowTypes.cpp index 0138e33..4994730 100644 --- a/cwFlowTypes.cpp +++ b/cwFlowTypes.cpp @@ -2438,6 +2438,34 @@ errLabel: return rc; } +cw::rc_t cw::flow::var_send_to_ui( variable_t* var ) +{ + + // var->ui_var_link is set to null when the var is removed from the list + + // 1. Atomically set _head to the new node and return 'old-head' + variable_t* prev = var->proc->ctx->ui_var_head.exchange(var,std::memory_order_acq_rel); + + // Note that at this point only the new node may have the 'old-head' as it's predecssor. + // Other threads may therefore safely interrupt at this point. + + // 2. Set the old-head next pointer to the new node (thereby adding the new node to the list) + prev->ui_var_link.store(var,std::memory_order_release); // RELEASE 'next' to consumer + + return kOkRC; +} + +cw::rc_t cw::flow::var_send_to_ui( proc_t* proc, unsigned vid, unsigned chIdx ) +{ + rc_t rc = kOkRC; + variable_t* var = nullptr; + + if((rc = var_find(proc, vid, chIdx, var )) == kOkRC ) + rc = var_send_to_ui(var); + + return rc; +} + cw::rc_t cw::flow::var_register_and_set( proc_t* proc, const char* var_label, unsigned sfx_id, unsigned vid, unsigned chIdx, variable_t*& varRef ) { return var_register( proc, var_label, sfx_id, vid, chIdx, nullptr, varRef ); diff --git a/cwFlowTypes.h b/cwFlowTypes.h index e323f61..68216dd 100644 --- a/cwFlowTypes.h +++ b/cwFlowTypes.h @@ -222,6 +222,8 @@ namespace cw struct variable_str* dst_tail; // struct variable_str* dst_link; // Link used by dst_head list. + ui_var_t* ui_var; // this variables UI description + std::atomic ui_var_link; // UI update var link based on flow_t ui_var_head; } variable_t; @@ -377,7 +379,14 @@ namespace cw network_preset_t* presetA; // presetA[presetN] partial (label and tid only) parsing of the network presets unsigned presetN; // - network_t* net; + network_t* net; // The root of the network instance + + ui_callback_t ui_callback; + void* ui_callback_arg; + + std::atomic ui_var_head; // Linked lists of var's to send to the UI + variable_t ui_var_stub; + variable_t* ui_var_tail; } flow_t; @@ -547,7 +556,11 @@ namespace cw // Get all the label-sfx-id's associated with a give var label rc_t var_mult_sfx_id_array( proc_t* proc, const char* var_label, unsigned* idA, unsigned idAllocN, unsigned& idN_ref ); - + + // Send a variable value to the UI + rc_t var_send_to_ui( variable_t* var ); + rc_t var_send_to_ui( proc_t* proc, unsigned vid, unsigned chIdx ); + //----------------- // // var_register