Skip to content

Commit 1eb253f

Browse files
Cache pool information on reactions to avoid finding it each time
1 parent be97aa5 commit 1eb253f

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/threading/Reaction.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ namespace threading {
4444
// Forward declare
4545
class ReactionTask;
4646
struct ReactionIdentifiers;
47+
namespace scheduler {
48+
class Scheduler;
49+
}
4750

4851
/**
4952
* This class holds the definition of a Reaction.
@@ -131,6 +134,10 @@ namespace threading {
131134

132135
/// The callback generator function (creates databound callbacks)
133136
TaskGenerator generator;
137+
138+
/// Cached data for this reaction added by the scheduler
139+
std::shared_ptr<void> scheduler_data;
140+
friend class scheduler::Scheduler; /// Let the scheduler mess with reaction objects
134141
};
135142

136143
} // namespace threading

src/threading/scheduler/Scheduler.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,23 @@ namespace threading {
188188
return;
189189
}
190190

191-
// Get the pool and locks for the group group
192-
auto pool = get_pool(task->pool_descriptor);
191+
// If we have run this task before, we know which pool it should be submitted to and cached it
192+
// This avoids every single submit having to lock a mutex to find the pool
193+
std::shared_ptr<Pool> pool;
194+
if (task->parent) {
195+
if (task->parent->scheduler_data) {
196+
pool = std::static_pointer_cast<Pool>(task->parent->scheduler_data);
197+
}
198+
else {
199+
pool = get_pool(task->pool_descriptor);
200+
task->parent->scheduler_data = pool;
201+
}
202+
}
203+
else {
204+
pool = get_pool(task->pool_descriptor);
205+
}
206+
207+
// Get any locks that are required for this task
193208
auto group_lock = get_groups_lock(task->id, task->priority, pool, task->group_descriptors);
194209

195210
// If this task should run immediately and not limited by the group lock

0 commit comments

Comments
 (0)