Skip to content

Commit 366e6bb

Browse files
committed
DPL: Create consumeWhenAnyWithAllConditions completion policy, and revert consumeWhenAny to original behavior
1 parent 0642e2b commit 366e6bb

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

Framework/Core/include/Framework/CompletionPolicyHelpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ struct CompletionPolicyHelpers {
5151
}
5252
static CompletionPolicy consumeWhenAny(std::string matchName);
5353

54+
/// When any of the parts of the record have been received, consume them.
55+
static CompletionPolicy consumeWhenAnyWithAllConditions(const char* name, CompletionPolicy::Matcher matcher);
56+
/// Default matcher applies for all devices
57+
static CompletionPolicy consumeWhenAnyWithAllConditions(CompletionPolicy::Matcher matcher = [](auto const&) -> bool { return true; })
58+
{
59+
return consumeWhenAnyWithAllConditions("consume-any-all-conditions", matcher);
60+
}
61+
static CompletionPolicy consumeWhenAnyWithAllConditions(std::string matchName);
62+
5463
/// When any of the parts of the record have been received, process the existing and free the associated payloads.
5564
/// This allows freeing things as early as possible, while still being able to wait
5665
/// all the parts before disposing the timeslice completely

Framework/Core/src/CompletionPolicyHelpers.cxx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ CompletionPolicy CompletionPolicyHelpers::consumeExistingWhenAny(const char* nam
198198
}
199199

200200
CompletionPolicy CompletionPolicyHelpers::consumeWhenAny(const char* name, CompletionPolicy::Matcher matcher)
201+
{
202+
auto callback = [](InputSpan const& inputs) -> CompletionPolicy::CompletionOp {
203+
for (auto& input : inputs) {
204+
if (input.header != nullptr) {
205+
return CompletionPolicy::CompletionOp::Consume;
206+
}
207+
}
208+
return CompletionPolicy::CompletionOp::Wait;
209+
};
210+
return CompletionPolicy{name, matcher, callback, false};
211+
}
212+
213+
CompletionPolicy CompletionPolicyHelpers::consumeWhenAny(std::string matchName)
214+
{
215+
auto matcher = [matchName](DeviceSpec const& device) -> bool {
216+
return std::regex_match(device.name.begin(), device.name.end(), std::regex(matchName));
217+
};
218+
return consumeWhenAny(matcher);
219+
}
220+
221+
CompletionPolicy CompletionPolicyHelpers::consumeWhenAnyWithAllConditions(const char* name, CompletionPolicy::Matcher matcher)
201222
{
202223
auto callback = [](InputSpan const& inputs, std::vector<InputSpec> const& specs) -> CompletionPolicy::CompletionOp {
203224
bool canConsume = false;
@@ -258,12 +279,12 @@ CompletionPolicy CompletionPolicyHelpers::consumeWhenAny(const char* name, Compl
258279
return CompletionPolicy{name, matcher, callback, false};
259280
}
260281

261-
CompletionPolicy CompletionPolicyHelpers::consumeWhenAny(std::string matchName)
282+
CompletionPolicy CompletionPolicyHelpers::consumeWhenAnyWithAllConditions(std::string matchName)
262283
{
263284
auto matcher = [matchName](DeviceSpec const& device) -> bool {
264285
return std::regex_match(device.name.begin(), device.name.end(), std::regex(matchName));
265286
};
266-
return consumeWhenAny(matcher);
287+
return consumeWhenAnyWithAllConditions(matcher);
267288
}
268289

269290
CompletionPolicy CompletionPolicyHelpers::processWhenAny(const char* name, CompletionPolicy::Matcher matcher)

0 commit comments

Comments
 (0)