Skip to content

Commit d49dcb1

Browse files
committed
chore: fix data race in executor group
1 parent 2bbb606 commit d49dcb1

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

include/mrdox/Support/ExecutorGroup.hpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,24 @@
2222
namespace clang {
2323
namespace mrdox {
2424

25+
class MRDOX_DECL
26+
ExecutorGroupBase
27+
{
28+
protected:
29+
struct MRDOX_DECL
30+
AnyAgent
31+
{
32+
virtual ~AnyAgent() = 0;
33+
virtual void* get() noexcept = 0;
34+
};
35+
36+
public:
37+
};
38+
2539
/** A set of execution agents for performing concurrent work.
2640
*/
2741
template<class Agent>
28-
class ExecutorGroup
42+
class ExecutorGroup : public ExecutorGroupBase
2943
{
3044
struct Impl
3145
{
@@ -124,7 +138,6 @@ class ExecutorGroup
124138
: group_(group)
125139
, agent_(std::move(agent))
126140
{
127-
MRDOX_ASSERT(agent_.get() != nullptr);
128141
}
129142

130143
~scoped_agent()
@@ -136,32 +149,28 @@ class ExecutorGroup
136149

137150
Agent& operator*() const noexcept
138151
{
139-
MRDOX_ASSERT(agent_.get() != nullptr);
140152
return *agent_;
141153
}
142154
};
143155

144156
void
145157
run(std::unique_lock<std::mutex> lock)
146158
{
147-
MRDOX_ASSERT(lock.owns_lock());
148159
std::unique_ptr<Agent> agent(std::move(agents_.back()));
149-
MRDOX_ASSERT(agent.get() != nullptr);
150160
agents_.pop_back();
151161
++busy_;
152162

153163
threadPool_.async(
154164
[this, agent = std::move(agent)]() mutable
155165
{
156-
MRDOX_ASSERT(agent.get() != nullptr);
157-
scoped_agent scope(*this, std::move(agent));
158-
MRDOX_ASSERT(agent.get() == nullptr);
159166
std::unique_lock<std::mutex> lock(impl_->mutex_);
167+
scoped_agent scope(*this, std::move(agent));
160168
for(;;)
161169
{
162170
if(work_.empty())
163171
break;
164-
any_callable<void(Agent&)> work(std::move(work_.front()));
172+
any_callable<void(Agent&)> work(
173+
std::move(work_.front()));
165174
work_.pop_front();
166175
unlock_guard unlock(impl_->mutex_);
167176
work(*scope);

source/Support/ExecutorGroup.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdox
9+
//
10+
11+
#include <mrdox/Support/ExecutorGroup.hpp>
12+
13+
namespace clang {
14+
namespace mrdox {
15+
16+
} // mrdox
17+
} // clang

0 commit comments

Comments
 (0)