Tests
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
#include "RuntimeStore.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto kCompatibilityPollFallbackInterval = std::chrono::milliseconds(250);
|
||||
}
|
||||
|
||||
ControlServices::ControlServices(RuntimeEventDispatcher& runtimeEventDispatcher) :
|
||||
mControlServer(std::make_unique<ControlServer>()),
|
||||
mOscServer(std::make_unique<OscServer>()),
|
||||
@@ -130,6 +135,7 @@ bool ControlServices::QueueOscCommit(const std::string& routeKey, const std::str
|
||||
std::lock_guard<std::mutex> lock(mPendingOscCommitMutex);
|
||||
mPendingOscCommits[routeKey] = std::move(commit);
|
||||
}
|
||||
WakePolling();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -184,6 +190,7 @@ void ControlServices::StopPolling()
|
||||
if (!mPollRunning.exchange(false))
|
||||
return;
|
||||
|
||||
WakePolling();
|
||||
if (mPollThread.joinable())
|
||||
mPollThread.join();
|
||||
}
|
||||
@@ -224,11 +231,23 @@ void ControlServices::PollLoop(RuntimeCoordinator& runtimeCoordinator)
|
||||
if (pollResult.runtimeStateBroadcastRequired || pollResult.shaderBuildRequested || pollResult.compileStatusChanged)
|
||||
QueueRuntimeCoordinatorResult(pollResult, pollResult.compileStatusChanged && !pollResult.compileStatusSucceeded && !pollResult.compileStatusMessage.empty());
|
||||
|
||||
for (int i = 0; i < 25 && mPollRunning; ++i)
|
||||
Sleep(10);
|
||||
std::unique_lock<std::mutex> wakeLock(mPollWakeMutex);
|
||||
mPollWakeCondition.wait_for(wakeLock, kCompatibilityPollFallbackInterval, [this]() {
|
||||
return !mPollRunning.load() || mPollWakeRequested;
|
||||
});
|
||||
mPollWakeRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ControlServices::WakePolling()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mPollWakeMutex);
|
||||
mPollWakeRequested = true;
|
||||
}
|
||||
mPollWakeCondition.notify_one();
|
||||
}
|
||||
|
||||
void ControlServices::QueueRuntimeCoordinatorResult(const RuntimeCoordinatorResult& result, bool failed)
|
||||
{
|
||||
RuntimeCoordinatorServiceResult serviceResult;
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "ShaderTypes.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -76,6 +78,7 @@ private:
|
||||
void StartPolling(RuntimeCoordinator& runtimeCoordinator);
|
||||
void StopPolling();
|
||||
void PollLoop(RuntimeCoordinator& runtimeCoordinator);
|
||||
void WakePolling();
|
||||
void QueueRuntimeCoordinatorResult(const RuntimeCoordinatorResult& result, bool failed = false);
|
||||
void PublishRuntimeStateBroadcastRequested(const std::string& reason);
|
||||
void PublishOscValueReceived(const PendingOscUpdate& update, const std::string& routeKey);
|
||||
@@ -86,6 +89,9 @@ private:
|
||||
RuntimeEventDispatcher& mRuntimeEventDispatcher;
|
||||
std::thread mPollThread;
|
||||
std::atomic<bool> mPollRunning;
|
||||
std::mutex mPollWakeMutex;
|
||||
std::condition_variable mPollWakeCondition;
|
||||
bool mPollWakeRequested = false;
|
||||
std::mutex mRuntimeCoordinatorResultMutex;
|
||||
std::vector<RuntimeCoordinatorServiceResult> mRuntimeCoordinatorResults;
|
||||
std::mutex mPendingOscMutex;
|
||||
|
||||
Reference in New Issue
Block a user