Skip to content

Commit 564444d

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Fix race in thread pool test.
TEST=vm/cc/ThreadPool_RunOne Bug: #60698 Change-Id: I97dedcea70d389c5f3b9c94ebd99b617cbd70bc9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428082 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent c0d1583 commit 564444d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

runtime/vm/thread_pool.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "vm/allocation.h"
1313
#include "vm/globals.h"
1414
#include "vm/intrusive_dlist.h"
15+
#include "vm/lockers.h"
1516
#include "vm/os_thread.h"
1617

1718
namespace dart {
@@ -76,10 +77,16 @@ class ThreadPool {
7677
static void RequestShutdown(ThreadPool* pool,
7778
std::function<void(void)>&& shutdown_complete);
7879

79-
// Exposed for unit test in thread_pool_test.cc
80-
uint64_t workers_started() const { return count_idle_ + count_running_; }
81-
// Exposed for unit test in thread_pool_test.cc
82-
bool has_pending_dead_worker() const { return last_dead_worker_ != nullptr; }
80+
#if defined(TESTING)
81+
uint64_t workers_started() const {
82+
MutexLocker ml(&pool_mutex_);
83+
return count_idle_ + count_running_;
84+
}
85+
bool has_pending_dead_worker() const {
86+
MutexLocker ml(&pool_mutex_);
87+
return last_dead_worker_ != nullptr;
88+
}
89+
#endif
8390

8491
protected:
8592
class Worker : public IntrusiveDListEntry<Worker> {
@@ -149,7 +156,7 @@ class ThreadPool {
149156

150157
void DeleteLastDeadWorker();
151158

152-
Mutex pool_mutex_;
159+
mutable Mutex pool_mutex_;
153160
bool shutting_down_ = false;
154161
uint64_t count_running_ = 0;
155162
uint64_t count_idle_ = 0;

0 commit comments

Comments
 (0)