Make combination of rworker_local values easier
The `values` helper method provides a convenient way to access all of the internal values as a vector.
This commit is contained in:
parent
58c0b4f5f4
commit
1e7d088aed
@ -508,6 +508,30 @@ public:
|
||||
mxs_rworker_broadcast(update_value, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all local values
|
||||
*
|
||||
* Note: this method must be called from the main worker thread.
|
||||
*
|
||||
* @return A vector containing the individual values for each worker
|
||||
*/
|
||||
std::vector<T> values() const
|
||||
{
|
||||
mxb_assert_message(RoutingWorker::get_current() == RoutingWorker::get(RoutingWorker::MAIN),
|
||||
"this method must be called from the main worker thread");
|
||||
std::vector<T> rval;
|
||||
std::mutex lock;
|
||||
mxb::Semaphore sem;
|
||||
|
||||
auto n = RoutingWorker::broadcast([&](){
|
||||
std::lock_guard<std::mutex> guard(lock);
|
||||
rval.push_back(*get_local_value());
|
||||
}, &sem, RoutingWorker::EXECUTE_AUTO);
|
||||
|
||||
sem.wait_n(n);
|
||||
return std::move(rval);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint64_t m_handle; // The handle to the worker local data
|
||||
|
Loading…
x
Reference in New Issue
Block a user