Skip to content

Commit

Permalink
dispatcher #3
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Oct 8, 2019
1 parent 0425e60 commit 308ed52
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,11 +1201,35 @@ dispatch_runner(void *arg)
pthread_rwlock_rdlock(&dispatchpollerlock);
}
pthread_rwlock_unlock(&dispatchpollerlock);
struct timeval stop;
gettimeofday(&stop, NULL);
for (c = 0; c < connectionslen; c++) {
conn = &(connections[c]);
if (!__sync_val_compare_and_swap(
&(conn->event), POLL_IN, POLL_IDLE))
&(conn->event), POLL_IN, POLL_IDLE)) {
if (__sync_bool_compare_and_swap(
&(conn->takenby), 0, self->id)) {
continue;
}
if (!conn->noexpire &&
timediff(conn->lastwork, stop) > IDLE_DISCONNECT_TIME)
{
/* force close connection below */
tracef("dispatcher: %d, connfd: %d, len: %d [%s], disconnecting\n",
self->id, conn->sock, len,
len < 0 ? strerror(errno) : "");
__sync_add_and_fetch(&closedconnections, 1);
conn->strm->strmclose(conn->strm);

/* flag this connection as no longer in use, unless there is
* pending metrics to send */
__sync_bool_compare_and_swap(&(conn->takenby), self->id, -1);
} else {
/* no timeout, release connection */
__sync_bool_compare_and_swap(&(conn->takenby), self->id, 0);
}
continue;
}
/* atomically try to "claim" this connection */
if (!__sync_bool_compare_and_swap(
&(conn->takenby), 0, self->id))
Expand Down

0 comments on commit 308ed52

Please sign in to comment.