Skip to content

Commit

Permalink
[scheduler] Account for insertion into the current level.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Jun 3, 2022
1 parent e09ad62 commit e2ee83f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/threaded/worker_assignments.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,28 @@ static void worker_assignments_free() {
* @param worker The number of a worker needing work.
*/
static reaction_t* get_reaction(size_t worker) {
#ifndef FEDERATED
int index = lf_atomic_add_fetch(num_reactions_by_worker + worker, -1);
if (index >= 0) {
return reactions_by_worker[worker][index];
}
num_reactions_by_worker[worker] = 0;
return NULL;
#else
int old_num_reactions;
int current_num_reactions = num_reactions_by_worker[worker];
int index;
do {
if (old_num_reactions <= 0) return NULL;
} while (
__sync_bool_compare_and_swap(
num_reactions_by_worker + worker,
old_num_reactions,
(index = old_num_reactions - 1)
) != old_num_reactions
);
return reactions_by_worker[worker][index];
#endif
}

/**
Expand Down

0 comments on commit e2ee83f

Please sign in to comment.