Skip to content

Commit

Permalink
Provide stats count of current "using" per tube.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Rarick committed Mar 8, 2008
1 parent 9b48dbc commit ad38067
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static void
conn_free(conn c)
{
c->fd = 0;
TUBE_ASSIGN(c->use, NULL);
conn_insert(&pool, c);
}

Expand Down Expand Up @@ -77,6 +76,7 @@ make_conn(int fd, char start_state, tube use, tube watch)

c->use = NULL; /* initialize */
TUBE_ASSIGN(c->use, use);
use->using_ct++;

c->fd = fd;
c->state = start_state;
Expand Down Expand Up @@ -251,6 +251,8 @@ conn_close(conn c)
if (has_reserved_job(c)) enqueue_reserved_jobs(c);

ms_clear(&c->watch);
c->use->using_ct--;
TUBE_ASSIGN(c->use, NULL);

conn_free(c);
}
4 changes: 4 additions & 0 deletions prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"current-jobs-reserved: %u\n" \
"current-jobs-buried: %u\n" \
"total-jobs: %llu\n" \
"current-using: %u\n" \
"current-watching: %u\n" \
"current-waiting: %u\n" \
"\r\n"
Expand Down Expand Up @@ -892,6 +893,7 @@ fmt_stats_tube(char *buf, size_t size, tube t)
t->stat.reserved_ct,
t->stat.buried_ct,
t->stat.total_jobs_ct,
t->using_ct,
t->watching_ct,
t->stat.waiting_ct);
}
Expand Down Expand Up @@ -1214,8 +1216,10 @@ dispatch_cmd(conn c)
TUBE_ASSIGN(t, find_or_make_tube(name));
if (!t) return reply_serr(c, MSG_OUT_OF_MEMORY);

c->use->using_ct--;
TUBE_ASSIGN(c->use, t);
TUBE_ASSIGN(t, NULL);
c->use->using_ct++;

use_ct++;
reply_line(c, STATE_SENDWORD, "USING %s\r\n", c->use->name);
Expand Down
2 changes: 1 addition & 1 deletion tube.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ make_tube(const char *name)
ms_init(&t->waiting, NULL, NULL);

t->stat = (struct stats) {0, 0, 0, 0};
t->watching_ct = 0;
t->using_ct = t->watching_ct = 0;

return t;
}
Expand Down
1 change: 1 addition & 0 deletions tube.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct tube {
struct job buried;
struct ms waiting; /* set of conns */
struct stats stat;
unsigned int using_ct;
unsigned int watching_ct;
};

Expand Down

0 comments on commit ad38067

Please sign in to comment.