Page MenuHomePhabricator

D4896.diff
No OneTemporary

D4896.diff

diff --git a/native/cpp/CommonCpp/Tools/WorkerThread.h b/native/cpp/CommonCpp/Tools/WorkerThread.h
--- a/native/cpp/CommonCpp/Tools/WorkerThread.h
+++ b/native/cpp/CommonCpp/Tools/WorkerThread.h
@@ -1,6 +1,7 @@
#pragma once
#include <folly/MPMCQueue.h>
+#include <future>
#include <memory>
#include <string>
#include <thread>
@@ -17,6 +18,7 @@
public:
WorkerThread(const std::string name);
void scheduleTask(const taskType task);
+ std::shared_ptr<std::promise<void>> flushAndBlock();
~WorkerThread();
};
diff --git a/native/cpp/CommonCpp/Tools/WorkerThread.cpp b/native/cpp/CommonCpp/Tools/WorkerThread.cpp
--- a/native/cpp/CommonCpp/Tools/WorkerThread.cpp
+++ b/native/cpp/CommonCpp/Tools/WorkerThread.cpp
@@ -26,6 +26,18 @@
}
}
+std::shared_ptr<std::promise<void>> WorkerThread::flushAndBlock() {
+ std::shared_ptr<std::promise<void>> queueBlockade =
+ std::make_shared<std::promise<void>>(std::promise<void>());
+ std::promise<void> taskStarted;
+ this->tasks.write(std::make_unique<taskType>([queueBlockade, &taskStarted]() {
+ taskStarted.set_value();
+ queueBlockade->get_future().get();
+ }));
+ taskStarted.get_future().get();
+ return queueBlockade;
+}
+
WorkerThread::~WorkerThread() {
this->tasks.blockingWrite(nullptr);
try {

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 2:55 PM (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2590631
Default Alt Text
D4896.diff (1 KB)

Event Timeline