Skip to content

Commit

Permalink
Fix ChronoController removing the wrong elements (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston authored May 7, 2018
1 parent 4e00b12 commit 84de008
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions NUClear.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
}
],
"settings": {
"ClangFormat": {
"format_on_save": true
"ClangFormat": {
"style": "file",
"format_on_save": true,
"languages": [ "C", "C++", "C++11", "Protobuf" ],
}
}
}
13 changes: 6 additions & 7 deletions src/extension/ChronoController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace extension {
: Reactor(std::move(environment)), wait_offset(std::chrono::milliseconds(0)) {

on<Trigger<ChronoTask>>().then("Add Chrono task", [this](std::shared_ptr<const ChronoTask> task) {

// Lock the mutex while we're doing stuff
{
std::lock_guard<std::mutex> lock(mutex);
Expand All @@ -46,7 +45,6 @@ namespace extension {

on<Trigger<dsl::operation::Unbind<ChronoTask>>>().then(
"Unbind Chrono Task", [this](const dsl::operation::Unbind<ChronoTask>& unbind) {

// Lock the mutex while we're doing stuff
{
std::lock_guard<std::mutex> lock(mutex);
Expand All @@ -69,7 +67,6 @@ namespace extension {
on<Shutdown>().then("Shutdown Chrono Controller", [this] { wait.notify_all(); });

on<Always, Priority::REALTIME>().then("Chrono Controller", [this] {

// Acquire the mutex lock so we can wait on it
std::unique_lock<std::mutex> lock(mutex);

Expand All @@ -89,16 +86,18 @@ namespace extension {
NUClear::clock::time_point now = NUClear::clock::now();

// Move back from the end poping the heap
for (auto end = tasks.end(); end != tasks.begin() && tasks.front().time < now; --end) {

for (auto end = tasks.end(); end != tasks.begin() && tasks.front().time < now;) {
// Run our task and if it returns false remove it
bool renew = tasks.front()();

// Move this to the back of the list
std::pop_heap(tasks.begin(), end);
std::pop_heap(tasks.begin(), end, std::greater<>());

if (!renew) {
tasks.pop_back();
end = tasks.erase(--end);
}
else {
--end;
}
}
}
Expand Down

0 comments on commit 84de008

Please sign in to comment.