File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,15 @@ void Executor::Add(std::function<void()> fn)
191
191
192
192
void Executor::Synchronize ()
193
193
{
194
- Call ([] {});
194
+ assert (!IsExecutorThread () && " Calling Synchronize() inside Call() will cause a deadlock" );
195
+ SynchronizeInternally ();
196
+ }
197
+
198
+ void Executor::SynchronizeInternally ()
199
+ {
200
+ std::promise<bool > sync;
201
+ Add ([&sync]() { sync.set_value (true ); });
202
+ sync.get_future ().get ();
195
203
}
196
204
197
205
ScheduledCall TimedExecutor::CallAt (const TimePoint& at, std::function<void ()> fn)
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ class Executor
104
104
template <typename Fn>
105
105
auto Call (Fn fn)
106
106
{
107
- assert (!IsExecutorThread ());
107
+ assert (!IsExecutorThread () && " Calling Call() inside Call() will cause a deadlock " );
108
108
std::packaged_task<decltype (fn ())()> task (fn);
109
109
Add ([&task]() { task (); });
110
110
return task.get_future ().get ();
@@ -126,6 +126,7 @@ class Executor
126
126
void Synchronize ();
127
127
128
128
protected:
129
+ void SynchronizeInternally ();
129
130
void SetExecutorThread ();
130
131
void SetExecutorThread (std::thread::id id);
131
132
void Add (std::function<void ()> fn);
@@ -138,7 +139,7 @@ class Executor
138
139
139
140
private:
140
141
SynchronizedQueue<std::function<void ()>> m_q;
141
- std::thread::id m_threadId;
142
+ std::atomic<std:: thread::id> m_threadId;
142
143
};
143
144
144
145
class TimedExecutor : private ExecutorBase ,
You can’t perform that action at this time.
0 commit comments