Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/threading/Reaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ namespace threading {
// Forward declare
class ReactionTask;
struct ReactionIdentifiers;
namespace scheduler {
class Scheduler;
} // namespace scheduler

/**
* This class holds the definition of a Reaction.
Expand Down Expand Up @@ -131,6 +134,10 @@ namespace threading {

/// The callback generator function (creates databound callbacks)
TaskGenerator generator;

/// Cached data for this reaction added by the scheduler
std::shared_ptr<void> scheduler_data;
friend class scheduler::Scheduler; /// Let the scheduler mess with reaction objects
};

} // namespace threading
Expand Down
19 changes: 17 additions & 2 deletions src/threading/scheduler/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,23 @@ namespace threading {
return;
}

// Get the pool and locks for the group group
auto pool = get_pool(task->pool_descriptor);
// If we have run this task before, we know which pool it should be submitted to and cached it
// This avoids every single submit having to lock a mutex to find the pool
std::shared_ptr<Pool> pool;
if (task->parent) {
if (task->parent->scheduler_data) {
pool = std::static_pointer_cast<Pool>(task->parent->scheduler_data);
}
else {
pool = get_pool(task->pool_descriptor);
task->parent->scheduler_data = pool;
}
}
else {
pool = get_pool(task->pool_descriptor);
}

// Get any locks that are required for this task
auto group_lock = get_groups_lock(task->id, task->priority, pool, task->group_descriptors);

// If this task should run immediately and not limited by the group lock
Expand Down
Loading