Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor

  • Loading branch information...
commit 3ff79f810fa4c5202c4287b5da9d6ab9066dc7b5 1 parent 8ce5d36
@kr authored
Showing with 17 additions and 48 deletions.
  1. +1 −33 conn.c
  2. +2 −5 dat.h
  3. +14 −10 prot.c
View
34 conn.c
@@ -49,7 +49,6 @@ make_conn(int fd, char start_state, tube use, tube watch)
c->state = start_state;
c->pending_timeout = -1;
c->tickpos = -1;
- c->prev = c->next = c; /* must be out of a linked list right now */
j = &c->reserved_jobs;
j->prev = j->next = j;
@@ -134,10 +133,9 @@ conntickat(conn c)
void
-connwant(conn c, int rw, conn list)
+connwant(conn c, int rw)
{
c->rw = rw;
- conn_insert(list, c);
connsched(c);
}
@@ -150,35 +148,6 @@ connsched(conn c)
}
-static int
-conn_list_any_p(conn head)
-{
- return head->next != head || head->prev != head;
-}
-
-conn
-conn_remove(conn c)
-{
- if (!conn_list_any_p(c)) return NULL; /* not in a doubly-linked list */
-
- c->next->prev = c->prev;
- c->prev->next = c->next;
-
- c->prev = c->next = c;
- return c;
-}
-
-void
-conn_insert(conn head, conn c)
-{
- if (conn_list_any_p(c)) return; /* already in a linked list */
-
- c->prev = head->prev;
- c->next = head;
- head->prev->next = c;
- head->prev = c;
-}
-
/* return the reserved job with the earliest deadline,
* or NULL if there's no reserved job */
job
@@ -262,7 +231,6 @@ conn_close(conn c)
cur_conn_ct--; /* stats */
remove_waiting_conn(c);
- conn_remove(c);
if (has_reserved_job(c)) enqueue_reserved_jobs(c);
ms_clear(&c->watch);
View
7 dat.h
@@ -171,7 +171,7 @@ struct tube {
};
struct conn {
- conn prev, next; /* linked list of connections */
+ conn next;
Server *srv;
Socket sock;
char state;
@@ -278,14 +278,11 @@ conn make_conn(int fd, char start_state, tube use, tube watch);
int connless(conn a, conn b);
void connrec(conn c, int i);
-void connwant(conn c, const int mask, conn list);
+void connwant(conn c, int rw);
void connsched(conn c);
void conn_close(conn c);
-conn conn_remove(conn c);
-void conn_insert(conn head, conn c);
-
int count_cur_conns(void);
uint count_tot_conns(void);
int count_cur_producers(void);
View
24 prot.c
@@ -229,10 +229,7 @@ static int drain_mode = 0;
static int64 started_at;
static uint64 op_ct[TOTAL_OPS], timeout_ct = 0;
-static struct conn dirty = {&dirty, &dirty};
-
-/* Doubly-linked list of connections with at least one reserved job. */
-static struct conn running = { &running, &running };
+static conn dirty;
static const char * op_names[] = {
"<unknown>",
@@ -274,7 +271,9 @@ reply(conn c, const char *line, int len, int state)
{
if (!c) return;
- connwant(c, 'w', &dirty);
+ connwant(c, 'w');
+ c->next = dirty;
+ dirty = c;
c->reply = line;
c->reply_len = len;
c->reply_sent = 0;
@@ -484,7 +483,6 @@ enqueue_reserved_jobs(conn c)
global_stat.reserved_ct--;
j->tube->stat.reserved_ct--;
c->soonest_job = NULL;
- if (!job_list_any_p(&c->reserved_jobs)) conn_remove(c);
}
}
@@ -970,7 +968,9 @@ wait_for_job(conn c, int timeout)
/* Set the pending timeout to the requested timeout amount */
c->pending_timeout = timeout;
- connwant(c, 'h', &dirty); // only care if they hang up
+ connwant(c, 'h'); // only care if they hang up
+ c->next = dirty;
+ dirty = c;
}
typedef int(*fmt_fn)(char *, size_t, void *);
@@ -1116,7 +1116,6 @@ remove_this_reserved_job(conn c, job j)
j->reserver = NULL;
}
c->soonest_job = NULL;
- if (!job_list_any_p(&c->reserved_jobs)) conn_remove(c);
return j;
}
@@ -1598,7 +1597,9 @@ do_cmd(conn c)
static void
reset_conn(conn c)
{
- connwant(c, 'r', &dirty);
+ connwant(c, 'r');
+ c->next = dirty;
+ dirty = c;
/* was this a peek or stats command? */
if (c->out_job && c->out_job->r.state == Copy) job_free(c->out_job);
@@ -1726,7 +1727,10 @@ update_conns()
int r;
conn c;
- while ((c = conn_remove(dirty.next))) { /* assignment */
+ while (dirty) {
+ c = dirty;
+ dirty = dirty->next;
+ c->next = NULL;
r = sockwant(&c->sock, c->rw);
if (r == -1) {
twarn("sockwant");
Please sign in to comment.
Something went wrong with that request. Please try again.