Skip to content

Commit

Permalink
Reorganized event back-references to be easier to read
Browse files Browse the repository at this point in the history
All queue manipulations are currently synchronized, so order
is irrelevant. Moving the back-references after the reference
assignment makes the dependents of the back-references more
notable.
  • Loading branch information
geky committed Aug 3, 2016
1 parent be5ffc1 commit 52e0aa2
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,42 +167,40 @@ static void equeue_enqueue(equeue_t *q, struct equeue_event *e, unsigned ms) {
}

if (*p && (*p)->target == e->target) {
if (*p) {
(*p)->ref = &e->sibling;
e->next = (*p)->next;
if (e->next) {
e->next->ref = &e->next;
}
e->sibling = *p;

if ((*p)->next) {
(*p)->next->ref = &e->next;
}
e->next = (*p)->next;
e->sibling = *p;
e->sibling->ref = &e->sibling;
} else {
if (*p) {
(*p)->ref = &e->next;
}
e->next = *p;
if (e->next) {
e->next->ref = &e->next;
}

e->sibling = 0;
}

e->ref = p;
*p = e;
e->ref = p;
}

static void equeue_unqueue(equeue_t *q, struct equeue_event *e) {
if (e->sibling) {
if (e->next) {
e->next->ref = &e->sibling->next;
}
e->sibling->next = e->next;
if (e->sibling->next) {
e->sibling->next->ref = &e->sibling->next;
}

e->sibling->ref = e->ref;
*e->ref = e->sibling;
e->sibling->ref = e->ref;
} else {
*e->ref = e->next;
if (e->next) {
e->next->ref = e->ref;
}
*e->ref = e->next;
}
}

Expand Down

0 comments on commit 52e0aa2

Please sign in to comment.