Add ConcurrentScheduler::get_thread_id.

This commit is contained in:
levlam 2022-10-04 23:12:50 +03:00
parent 67aa7082d6
commit 7aa6f2bf91
2 changed files with 11 additions and 0 deletions

View File

@ -70,6 +70,12 @@ void ConcurrentScheduler::test_one_thread_run() {
} while (!is_finished_.load(std::memory_order_relaxed));
}
thread::id ConcurrentScheduler::get_thread_id(int32 sched_id) {
auto thread_pos = static_cast<size_t>(sched_id - 1);
CHECK(thread_pos < threads_.size());
return threads_[thread_pos].get_id();
}
void ConcurrentScheduler::start() {
CHECK(state_ == State::Start);
is_finished_.store(false, std::memory_order_relaxed);
@ -100,6 +106,7 @@ void ConcurrentScheduler::start() {
state_ = State::Run;
}
static TD_THREAD_LOCAL double emscripten_timeout;
bool ConcurrentScheduler::run_main(Timestamp timeout) {

View File

@ -31,9 +31,11 @@ class ConcurrentScheduler final : private Scheduler::Callback {
void finish_async() {
schedulers_[0]->finish();
}
void wakeup() {
schedulers_[0]->wakeup();
}
SchedulerGuard get_main_guard() {
return schedulers_[0]->get_guard();
}
@ -48,6 +50,8 @@ class ConcurrentScheduler final : private Scheduler::Callback {
return is_finished_.load(std::memory_order_relaxed);
}
thread::id get_thread_id(int32 sched_id);
void start();
bool run_main(double timeout) {