diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-01-09 13:31:21 +0000 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2006-01-09 13:31:21 +0000 |
| commit | d4082e3a7a3ac85fd31375eed5d7a76055fda799 (patch) | |
| tree | dbed1aff2729000e1d8aabca259ef6b63c05d042 | |
| parent | e8a016d66318ba976760a7dc645e54e1478148db (diff) | |
| download | btpd-d4082e3a7a3ac85fd31375eed5d7a76055fda799.tar.gz btpd-d4082e3a7a3ac85fd31375eed5d7a76055fda799.zip | |
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.
| -rw-r--r-- | btpd/http.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/btpd/http.c b/btpd/http.c index 82a0750..34fc760 100644 --- a/btpd/http.c +++ b/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); } |