Skip to content

Commit abef927

Browse files
authored
Fixed bug with reactions triggered my multiple inputs (#331)
* Fixed bug with reactions triggered my multiple inputs 1. Fixed a bug causing assertion fail on the reaction queue capacity when a reaction is triggered my two or more inputs. When two inputs trigger the same reaction, the reaction is inserted in the reaction queue only once. Hence, the check on the capacity must be done after checking whether the reaction is already in the queue. * Ran make format
1 parent 22a1715 commit abef927

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/queues.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,22 @@ static lf_ret_t ReactionQueue_insert(ReactionQueue* self, Reaction* reaction) {
129129
validate(reaction);
130130
validate(reaction->level < (int)self->capacity);
131131
validate(reaction->level >= 0);
132-
validate(self->level_size[reaction->level] < (int)self->capacity);
132+
133133
validate(self->curr_level <= reaction->level);
134134

135+
// checking if the reaction to be inserted is already in the queue
136+
// e.g., when a reaction is triggered by two or more inputs.
137+
// This needs to be done before checking if the queue is full, because
138+
// if the reaction is already in the queue, we don't need to insert it again.
135139
for (int i = 0; i < self->level_size[reaction->level]; i++) {
136140
if (ACCESS(self->array, self->capacity, reaction->level, i) == reaction) {
137141
return LF_OK;
138142
}
139143
}
144+
145+
// now we can check if the queue is full
146+
validate(self->level_size[reaction->level] < (int)self->capacity);
147+
140148
ACCESS(self->array, self->capacity, reaction->level, self->level_size[reaction->level]) = reaction;
141149
self->level_size[reaction->level]++;
142150
if (reaction->level > self->max_active_level) {

0 commit comments

Comments
 (0)