예제 #1
0
int jlog_logio_asynch_write(asynch_log_ctx *actx, asynch_log_line *line) {
  int rv;
  jlog_ctx *log = actx->userdata;
  rv = jlog_ctx_write(log, line->buf_dynamic ?
                             line->buf_dynamic :
                             line->buf_static,
                      line->len);
  if(rv == -1) {
    noitL(noit_error, "jlog_ctx_write failed(%d): %s\n",
          jlog_ctx_errno(log), jlog_ctx_err_string(log));
  }
  return rv;
}
예제 #2
0
static void *
jlog_logio_asynch_writer(void *vls) {
  noit_log_stream_t ls = vls;
  jlog_asynch_ctx *actx = ls->op_ctx;
  jlog_line *iter = NULL;
  int gen;
  gen = noit_atomic_inc32(&actx->gen);
  noitL(noit_error, "starting asynchronous jlog writer[%d/%p]\n",
        (int)getpid(), (void *)pthread_self());
  while(gen == actx->gen) {
    pthread_rwlock_t *lock;
    int fast = 0, max = 1000;
    jlog_line *line;
    lock = ls->lock;
    if(lock) pthread_rwlock_rdlock(lock);
    while(max > 0 && NULL != (line = jlog_asynch_pop(actx, &iter))) {
      if(jlog_ctx_write(actx->log, line->buf_dynamic ?
                                     line->buf_dynamic :
                                     line->buf_static,
                        line->len) == -1) {
        noitL(noit_error, "jlog_ctx_write failed(%d): %s\n",
              jlog_ctx_errno(actx->log), jlog_ctx_err_string(actx->log));
        abort();
      }
      if(line->buf_dynamic != NULL) free(line->buf_dynamic);
      free(line);
      fast = 1;
      max--;
    }
    if(lock) pthread_rwlock_unlock(lock);
    if(max > 0) {
      /* we didn't hit our limit... so we ran the queue dry */
      /* 200ms if there was nothing, 10ms otherwise */
      usleep(fast ? 10000 : 200000);
    }
  }
  noitL(noit_error, "stopping asynchronous jlog writer[%d/%p]\n",
        (int)getpid(), (void *)pthread_self());
  pthread_exit((void *)0);
}