ran client sessions in separated thread pool
This commit is contained in:
@@ -262,7 +262,7 @@ public:
|
||||
};
|
||||
|
||||
_updateFunc = [controls, this](std::stop_token stop_token) -> std::error_code {
|
||||
std::lock_guard lock{*_updateMutex};
|
||||
// std::lock_guard lock{*_updateMutex};
|
||||
|
||||
// first, update mount quantities
|
||||
typename hardware_t::hardware_state_t hw_pos;
|
||||
@@ -420,38 +420,11 @@ public:
|
||||
_internalUpdatingStopSource = std::stop_source{};
|
||||
*_internalUpdating = false;
|
||||
|
||||
_dataUpdatingRequested->clear();
|
||||
_dataUpdatingStart->clear();
|
||||
// _dataUpdatingRequested->clear();
|
||||
// _dataUpdatingStart->clear();
|
||||
|
||||
_updatingFuture =
|
||||
std::async(std::launch::async, &MccTelemetry::updateLoop, this, _internalUpdatingStopSource.get_token());
|
||||
|
||||
// _updatingFuture = std::async(
|
||||
// std::launch::async,
|
||||
// [controls, this](std::stop_token stoken) {
|
||||
// bool stop_flag = stoken.stop_requested();
|
||||
// // controls->logTrace(std::format("stop_requested() = {}", stop_flag));
|
||||
// // while (!stoken.stop_requested()) {
|
||||
// while (!stop_flag) {
|
||||
// _dataUpdatingRequested->wait(false);
|
||||
|
||||
// stop_flag = stoken.stop_requested();
|
||||
// if (!stop_flag) {
|
||||
// // if (!stoken.stop_requested()) {
|
||||
// *_internalUpdating = true;
|
||||
// std::lock_guard lock{*_timeoutMutex};
|
||||
|
||||
// _dataUpdatingStart->test_and_set();
|
||||
// _dataUpdatingStart->notify_all();
|
||||
|
||||
// _lastUpdateError = _updateFunc(stoken);
|
||||
|
||||
// _dataUpdatingStart->clear();
|
||||
// _dataUpdatingRequested->clear();
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// _internalUpdatingStopSource.get_token());
|
||||
// _updatingFuture =
|
||||
// std::async(std::launch::async, &MccTelemetry::updateLoop, this, _internalUpdatingStopSource.get_token());
|
||||
}
|
||||
|
||||
|
||||
@@ -514,6 +487,10 @@ public:
|
||||
// asynchronuosly periodicaly update telemetry data (internal synchronization)
|
||||
void startInternalTelemetryDataUpdating()
|
||||
{
|
||||
*_internalUpdating = true;
|
||||
_internalUpdatingStopSource = std::stop_source{};
|
||||
return;
|
||||
|
||||
using intv_t = std::remove_cvref_t<decltype(_currentUpdateInterval)>;
|
||||
|
||||
if (_internalUpdatingStopSource.stop_requested()) {
|
||||
@@ -549,6 +526,9 @@ public:
|
||||
{
|
||||
// reset all possible locks
|
||||
_internalUpdatingStopSource.request_stop();
|
||||
*_internalUpdating = false;
|
||||
|
||||
return;
|
||||
|
||||
_dataUpdatingRequested->test_and_set();
|
||||
_dataUpdatingRequested->notify_one();
|
||||
@@ -581,6 +561,26 @@ public:
|
||||
|
||||
error_t updateTelemetryData(traits::mcc_time_duration_c auto const& timeout)
|
||||
{
|
||||
std::lock_guard thread_lock{*_updateMutex};
|
||||
|
||||
// _internalUpdatingStopSource = std::stop_source{};
|
||||
// return _lastUpdateError = _updateFunc(_internalUpdatingStopSource.get_token());
|
||||
|
||||
|
||||
auto ft = std::async(std::launch::async, _updateFunc, _internalUpdatingStopSource.get_token());
|
||||
auto st = ft.wait_for(timeout);
|
||||
if (st == std::future_status::ready) {
|
||||
return _lastUpdateError;
|
||||
} else if (st == std::future_status::deferred) {
|
||||
ft.get();
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
} else {
|
||||
_lastUpdateError = MccTelemetryErrorCode::ERROR_DATA_TIMEOUT;
|
||||
}
|
||||
|
||||
return _lastUpdateError;
|
||||
|
||||
|
||||
// trigger updating
|
||||
_dataUpdatingRequested->test_and_set();
|
||||
_dataUpdatingRequested->notify_one();
|
||||
|
||||
Reference in New Issue
Block a user