Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation of marl::Ticket::onCall() #101

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions include/marl/ticket.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Ticket {
struct Record;

public:
using OnCall = std::function<void()>;

// Queue hands out Tickets.
class Queue {
public:
Expand Down Expand Up @@ -93,7 +95,7 @@ class Ticket {
// onCall() registers the function f to be invoked when this ticket is
// called. If the ticket is already called prior to calling onCall(), then
// f() will be executed immediately.
// F must be a function of the signature: void F()
// F must be a function of the OnCall signature.
template <typename F>
inline void onCall(F&& f) const;

Expand All @@ -111,7 +113,7 @@ class Ticket {
Record* next = nullptr; // guarded by shared->mutex
Record* prev = nullptr; // guarded by shared->mutex
inline void unlink(); // guarded by shared->mutex
Task onCall; // guarded by shared->mutex
OnCall onCall; // guarded by shared->mutex
bool isCalled = false; // guarded by shared->mutex
std::atomic<bool> isDone = {false};
};
Expand Down Expand Up @@ -155,7 +157,7 @@ void Ticket::onCall(Function&& f) const {
a();
b();
}
Task a, b;
OnCall a, b;
};
record->onCall = std::move(Joined{std::move(record->onCall), std::move(f)});
} else {
Expand Down Expand Up @@ -228,13 +230,13 @@ void Ticket::Record::callAndUnlock(std::unique_lock<std::mutex>& lock) {
return;
}
isCalled = true;
Task task;
std::swap(task, onCall);
OnCall callback;
std::swap(callback, onCall);
isCalledCondVar.notify_all();
lock.unlock();

if (task) {
marl::schedule(std::move(task));
if (callback) {
marl::schedule(std::move(callback));
}
}

Expand Down