Skip to content

Commit

Permalink
Reserve any ready job, even in the safety margin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith Rarick committed Mar 8, 2008
1 parent f96ee87 commit dc266b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ conn_has_close_deadline(conn c)
return j && t >= j->deadline - SAFETY_MARGIN;
}

int
conn_ready(conn c)
{
size_t i;

for (i = 0; i < c->watch.used; i++) {
if (((tube) c->watch.items[i])->ready.used) return 1;
}
return 0;
}

void
conn_close(conn c)
{
Expand Down
1 change: 1 addition & 0 deletions conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ void conn_set_worker(conn c);
job soonest_job(conn c);
int has_reserved_this_job(conn c, job j);
int conn_has_close_deadline(conn c);
int conn_ready(conn c);

#endif /*conn_h*/
4 changes: 2 additions & 2 deletions doc/protocol.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ the job times out, when the server will put the job back into the ready queue.
The time available can be found by asking the server for the job's stats.

If the client has previously reserved job J and issues a reserve command when
J has less than one second left in its ttr interval, the server will respond
with:
J has less than one second left in its ttr interval and there are no ready
jobs, the server will respond with:

TIMEOUT\r\n

Expand Down
4 changes: 3 additions & 1 deletion prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,9 @@ dispatch_cmd(conn c)
reserve_ct++; /* stats */
conn_set_worker(c);

if (conn_has_close_deadline(c)) return reply_msg(c, MSG_TIMEOUT);
if (conn_has_close_deadline(c) && !conn_ready(c)) {
return reply_msg(c, MSG_TIMEOUT);
}

/* try to get a new job for this guy */
wait_for_job(c);
Expand Down

0 comments on commit dc266b8

Please sign in to comment.