[vm] Fix race in thread pool test.

TEST=vm/cc/ThreadPool_RunOne
Bug: https://github.com/dart-lang/sdk/issues/60698
Change-Id: I97dedcea70d389c5f3b9c94ebd99b617cbd70bc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428082
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2025-05-12 12:32:19 -07:00
committed by Commit Queue
parent c0d1583d60
commit 564444d92b
+12 -5
View File
@@ -12,6 +12,7 @@
#include "vm/allocation.h"
#include "vm/globals.h"
#include "vm/intrusive_dlist.h"
#include "vm/lockers.h"
#include "vm/os_thread.h"
namespace dart {
@@ -76,10 +77,16 @@ class ThreadPool {
static void RequestShutdown(ThreadPool* pool,
std::function<void(void)>&& shutdown_complete);
// Exposed for unit test in thread_pool_test.cc
uint64_t workers_started() const { return count_idle_ + count_running_; }
// Exposed for unit test in thread_pool_test.cc
bool has_pending_dead_worker() const { return last_dead_worker_ != nullptr; }
#if defined(TESTING)
uint64_t workers_started() const {
MutexLocker ml(&pool_mutex_);
return count_idle_ + count_running_;
}
bool has_pending_dead_worker() const {
MutexLocker ml(&pool_mutex_);
return last_dead_worker_ != nullptr;
}
#endif
protected:
class Worker : public IntrusiveDListEntry<Worker> {
@@ -149,7 +156,7 @@ class ThreadPool {
void DeleteLastDeadWorker();
Mutex pool_mutex_;
mutable Mutex pool_mutex_;
bool shutting_down_ = false;
uint64_t count_running_ = 0;
uint64_t count_idle_ = 0;