소스 검색

Move finished http requests to a queue and post the whole queue at once.

This can potentially reduce the time the http thread keeps the post lock
and the httpq lock.
master
Richard Nyberg 19 년 전
부모
커밋
d4082e3a7a
1개의 변경된 파일14개의 추가작업 그리고 13개의 파일을 삭제
  1. +14
    -13
      btpd/http.c

+ 14
- 13
btpd/http.c 파일 보기

@@ -126,16 +126,18 @@ http_td_cb(void *arg)
static void
http_td_actions(void)
{
int nmsgs, has_posted;
int nmsgs;
struct http *http, *next;
struct http_tq postq;
CURLMsg *cmsg;

pthread_mutex_lock(&m_httpq_lock);
do {
has_posted = 0;
while (BTPDQ_EMPTY(&m_httpq))
pthread_cond_wait(&m_httpq_cond, &m_httpq_lock);

BTPDQ_INIT(&postq);

BTPDQ_FOREACH_MUTABLE(http, &m_httpq, entry, next) {
switch (http->state) {
case HS_ADD:
@@ -146,13 +148,9 @@ http_td_actions(void)
curl_multi_remove_handle(m_curlh, http->curlh);
case HS_NOADD:
BTPDQ_REMOVE(&m_httpq, http, entry);
BTPDQ_INSERT_TAIL(&postq, http, entry);
http->state = HS_CANCEL;
http->res.res = HRES_CANCEL;
if (!has_posted) {
has_posted = 1;
td_post_begin();
}
td_post(http_td_cb, http);
break;
case HS_DONE:
abort();
@@ -168,6 +166,7 @@ http_td_actions(void)
}
assert(http != NULL);
BTPDQ_REMOVE(&m_httpq, http, entry);
BTPDQ_INSERT_TAIL(&postq, http, entry);
http->state = HS_DONE;
if (cmsg->data.result == 0)
http->res.res = HRES_OK;
@@ -176,14 +175,16 @@ http_td_actions(void)
http->res.code = cmsg->data.result;
}
curl_multi_remove_handle(m_curlh, http->curlh);
if (!has_posted) {
td_post_begin();
has_posted = 1;
}
td_post(http_td_cb, http);
}
if (has_posted)

if (!BTPDQ_EMPTY(&postq)) {
pthread_mutex_unlock(&m_httpq_lock);
td_post_begin();
BTPDQ_FOREACH(http, &postq, entry)
td_post(http_td_cb, http);
td_post_end();
pthread_mutex_lock(&m_httpq_lock);
}
} while (BTPDQ_EMPTY(&m_httpq));
pthread_mutex_unlock(&m_httpq_lock);
}


불러오는 중...
취소
저장