Browse Source

Reap curls that are unused for over a minute.

This allows connections to be closed, thereby allowing the number of curl handles to always be the minimum necessary to not delay networking.
nfactor-troky
ckolivas 13 years ago committed by Con Kolivas
parent
commit
85008a7853
  1. 26
      cgminer.c
  2. 1
      miner.h

26
cgminer.c

@ -1951,7 +1951,8 @@ static void sighandler(int __maybe_unused sig)
kill_work(); kill_work();
} }
/* Called with pool_lock held */ /* Called with pool_lock held. Recruit an extra curl if none are available for
* this pool. */
static void recruit_curl(struct pool *pool) static void recruit_curl(struct pool *pool)
{ {
struct curl_ent *ce = calloc(sizeof(struct curl_ent), 1); struct curl_ent *ce = calloc(sizeof(struct curl_ent), 1);
@ -1981,7 +1982,8 @@ static struct curl_ent *pop_curl_entry(struct pool *pool)
static void push_curl_entry(struct curl_ent *ce, struct pool *pool) static void push_curl_entry(struct curl_ent *ce, struct pool *pool)
{ {
mutex_lock(&pool->pool_lock); mutex_lock(&pool->pool_lock);
list_add(&ce->node, &pool->curlring); list_add_tail(&ce->node, &pool->curlring);
gettimeofday(&ce->tv, NULL);
mutex_unlock(&pool->pool_lock); mutex_unlock(&pool->pool_lock);
} }
@ -3980,6 +3982,25 @@ void reinit_device(struct cgpu_info *cgpu)
static struct timeval rotate_tv; static struct timeval rotate_tv;
/* We reap curls if they are unused for over a minute */
static void reap_curl(struct pool *pool)
{
struct curl_ent *ent, *iter;
struct timeval now;
gettimeofday(&now, NULL);
mutex_lock(&pool->pool_lock);
list_for_each_entry_safe(ent, iter, &pool->curlring, node) {
if (now.tv_sec - ent->tv.tv_sec > 60) {
applog(LOG_DEBUG, "Reaped curl from pool %d", pool->pool_no);
list_del(&ent->node);
curl_easy_cleanup(ent->curl);
free(ent);
}
}
mutex_unlock(&pool->pool_lock);
}
static void *watchpool_thread(void __maybe_unused *userdata) static void *watchpool_thread(void __maybe_unused *userdata)
{ {
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@ -3993,6 +4014,7 @@ static void *watchpool_thread(void __maybe_unused *userdata)
for (i = 0; i < total_pools; i++) { for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i]; struct pool *pool = pools[i];
reap_curl(pool);
if (!pool->enabled) if (!pool->enabled)
continue; continue;

1
miner.h

@ -601,6 +601,7 @@ typedef struct {
struct curl_ent { struct curl_ent {
CURL *curl; CURL *curl;
struct list_head node; struct list_head node;
struct timeval tv;
}; };
struct pool { struct pool {

Loading…
Cancel
Save