Skip to content

Commit

Permalink
Use the doubly-linked list for the free conn pool as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Rarick committed Sep 25, 2007
1 parent 42ee606 commit 25171e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
25 changes: 12 additions & 13 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include "util.h"
#include "prot.h"

/* Singly-linked list of free connections (the prev pointer isn't used here). */
static conn pool_front = NULL, pool_rear = NULL;
/* Doubly-linked list of free connections. */
static struct conn pool = { &pool, &pool, 0 };

int cur_conn_ct = 0, cur_worker_ct = 0, cur_producer_ct = 0;

static int
pool_conn_p()
{
return !!pool_front;
return conn_list_empty_p(&pool);
}

static conn
Expand All @@ -27,9 +27,8 @@ conn_alloc()
if (!pool_conn_p()) return malloc(sizeof(struct conn));

/* remove it from the list */
c = pool_front;
pool_front = c->next;
c->prev = c->next = NULL;
c = pool.next;
conn_remove(c);

return c;
}
Expand All @@ -38,13 +37,7 @@ static void
conn_free(conn c)
{
c->fd = 0;
c->prev = c->next = NULL;
if (pool_conn_p()) {
pool_rear->next = c;
} else {
pool_front = c;
}
pool_rear = c;
conn_insert(&pool, c);
}

conn
Expand Down Expand Up @@ -132,6 +125,12 @@ conn_update_evq(conn c, const int events)
return conn_set_evq(c, events, c->evq.ev_callback);
}

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

void
conn_remove(conn c)
{
Expand Down
3 changes: 2 additions & 1 deletion conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
typedef struct conn *conn;

struct conn {
conn prev, next; /* linked list of connections */
int fd;
char state;
char type;
Expand All @@ -54,7 +55,6 @@ struct conn {
job out_job;
int out_job_sent;
job reserved_job;
conn prev, next; /* linked list of connections */
};

void conn_init();
Expand All @@ -66,6 +66,7 @@ int conn_update_evq(conn c, const int flags);

void conn_close(conn c);

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

Expand Down
5 changes: 2 additions & 3 deletions prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
static pq ready_q;

/* Doubly-linked list of waiting connections. */
static struct conn wait_queue; /* sentinel */
static struct conn wait_queue = { &wait_queue, &wait_queue, 0 };

static int
waiting_conn_p()
{
return wait_queue.next != &wait_queue;
return conn_list_empty_p(&wait_queue);
}

void
Expand Down Expand Up @@ -110,5 +110,4 @@ void
prot_init()
{
ready_q = make_pq(HEAP_SIZE);
wait_queue.next = wait_queue.prev = &wait_queue;
}

0 comments on commit 25171e7

Please sign in to comment.