non-blocking http
This commit is contained in:
@@ -22,19 +22,31 @@ void RuntimeShaderBridge::Start(const std::string& layerId, const std::string& s
|
||||
mOnArtifactReady = std::move(onArtifactReady);
|
||||
mOnError = std::move(onError);
|
||||
mStopping.store(false, std::memory_order_release);
|
||||
mFinished.store(false, std::memory_order_release);
|
||||
mCompiler.StartShaderBuild(shaderId);
|
||||
mThread = std::thread([this]() { ThreadMain(); });
|
||||
}
|
||||
|
||||
void RuntimeShaderBridge::Stop()
|
||||
void RuntimeShaderBridge::RequestStop()
|
||||
{
|
||||
mStopping.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
void RuntimeShaderBridge::Stop()
|
||||
{
|
||||
RequestStop();
|
||||
if (mThread.joinable())
|
||||
mThread.join();
|
||||
mCompiler.Stop();
|
||||
mLayerId.clear();
|
||||
mOnArtifactReady = ArtifactCallback();
|
||||
mOnError = ErrorCallback();
|
||||
mFinished.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
bool RuntimeShaderBridge::CanStopWithoutWaiting() const
|
||||
{
|
||||
return mFinished.load(std::memory_order_acquire) && !mCompiler.Running();
|
||||
}
|
||||
|
||||
void RuntimeShaderBridge::ThreadMain()
|
||||
@@ -54,8 +66,10 @@ void RuntimeShaderBridge::ThreadMain()
|
||||
{
|
||||
mOnError(build.message);
|
||||
}
|
||||
mFinished.store(true, std::memory_order_release);
|
||||
return;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
mFinished.store(true, std::memory_order_release);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public:
|
||||
|
||||
void Start(const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
|
||||
void Start(const std::string& layerId, const std::string& shaderId, ArtifactCallback onArtifactReady, ErrorCallback onError);
|
||||
void RequestStop();
|
||||
void Stop();
|
||||
bool CanStopWithoutWaiting() const;
|
||||
|
||||
private:
|
||||
void ThreadMain();
|
||||
@@ -29,6 +31,7 @@ private:
|
||||
RuntimeSlangShaderCompiler mCompiler;
|
||||
std::thread mThread;
|
||||
std::atomic<bool> mStopping{ false };
|
||||
std::atomic<bool> mFinished{ true };
|
||||
std::string mLayerId;
|
||||
ArtifactCallback mOnArtifactReady;
|
||||
ErrorCallback mOnError;
|
||||
|
||||
Reference in New Issue
Block a user