Skip to content

Commit

Permalink
Fix a name and a bug.
Browse files Browse the repository at this point in the history
Function conn_list_empty_p() should have been conn_list_any_p().

Newly-allocated conns should be empty lists, as should newly-removed
conns. So set their prev and next pointers to themselves.
  • Loading branch information
Keith Rarick committed Sep 25, 2007
1 parent 25171e7 commit 235b8e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int cur_conn_ct = 0, cur_worker_ct = 0, cur_producer_ct = 0;
static int
pool_conn_p()
{
return conn_list_empty_p(&pool);
return conn_list_any_p(&pool);
}

static conn
Expand Down Expand Up @@ -54,6 +54,7 @@ make_conn(int fd, char start_state)
c->cmd_read = 0;
c->in_job = c->out_job = c->reserved_job = NULL;
c->in_job_read = c->out_job_sent = 0;
c->prev = c->next = c; /* must be out of a linked list right now */

cur_conn_ct++; /* stats */

Expand Down Expand Up @@ -126,26 +127,26 @@ conn_update_evq(conn c, const int events)
}

int
conn_list_empty_p(conn head)
conn_list_any_p(conn head)
{
return head->next != head;
return head->next != head || head->prev != head;
}

void
conn_remove(conn c)
{
if (!c->next || !c->prev) return; /* not in a doubly-linked list */
if (!conn_list_any_p(c)) return; /* not in a doubly-linked list */

c->next->prev = c->prev;
c->prev->next = c->next;

c->prev = c->next = NULL;
c->prev = c->next = c;
}

void
conn_insert(conn head, conn c)
{
if (c->prev || c->next) return; /* already in a linked list */
if (conn_list_any_p(c)) return; /* already in a linked list */

c->prev = head->prev;
c->next = head;
Expand Down
2 changes: 1 addition & 1 deletion conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int conn_update_evq(conn c, const int flags);

void conn_close(conn c);

int conn_list_empty_p(conn head);
int conn_list_any_p(conn head);
void conn_remove(conn c);
void conn_insert(conn head, conn c);

Expand Down
2 changes: 1 addition & 1 deletion prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static struct conn wait_queue = { &wait_queue, &wait_queue, 0 };
static int
waiting_conn_p()
{
return conn_list_empty_p(&wait_queue);
return conn_list_any_p(&wait_queue);
}

void
Expand Down

0 comments on commit 235b8e6

Please sign in to comment.