mirror of
https://github.com/curl/curl.git
synced 2026-08-25 13:23:33 +03:00
thrdqueue: drop name strdups from Curl_thrdq_create
The only usage of the thread queue and pool is for "DNS" which is a static string. No point in strdup'ing it (twice). Future users are *likely* to also used fixed strings, otherwise we revert this change when dynamic names are introduced. Reported-by: Max Dymond Closes #22555
This commit is contained in:
parent
eae88a7473
commit
d064bc2adb
2 changed files with 8 additions and 10 deletions
|
|
@ -50,7 +50,7 @@ struct thrdslot {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct curl_thrdpool {
|
struct curl_thrdpool {
|
||||||
char *name;
|
const char *name;
|
||||||
uint64_t refcount;
|
uint64_t refcount;
|
||||||
curl_mutex_t lock;
|
curl_mutex_t lock;
|
||||||
curl_cond_t await;
|
curl_cond_t await;
|
||||||
|
|
@ -236,7 +236,6 @@ static bool thrdpool_unlink(struct curl_thrdpool *tpool, bool locked)
|
||||||
thrdpool_join_zombies(tpool);
|
thrdpool_join_zombies(tpool);
|
||||||
if(locked)
|
if(locked)
|
||||||
Curl_mutex_release(&tpool->lock);
|
Curl_mutex_release(&tpool->lock);
|
||||||
curlx_free(tpool->name);
|
|
||||||
Curl_cond_destroy(&tpool->await);
|
Curl_cond_destroy(&tpool->await);
|
||||||
Curl_mutex_destroy(&tpool->lock);
|
Curl_mutex_destroy(&tpool->lock);
|
||||||
curlx_free(tpool);
|
curlx_free(tpool);
|
||||||
|
|
@ -312,6 +311,7 @@ CURLcode Curl_thrdpool_create(struct curl_thrdpool **ptpool,
|
||||||
{
|
{
|
||||||
struct curl_thrdpool *tpool;
|
struct curl_thrdpool *tpool;
|
||||||
CURLcode result = CURLE_OUT_OF_MEMORY;
|
CURLcode result = CURLE_OUT_OF_MEMORY;
|
||||||
|
DEBUGASSERT(name);
|
||||||
|
|
||||||
tpool = curlx_calloc(1, sizeof(*tpool));
|
tpool = curlx_calloc(1, sizeof(*tpool));
|
||||||
if(!tpool)
|
if(!tpool)
|
||||||
|
|
@ -327,9 +327,8 @@ CURLcode Curl_thrdpool_create(struct curl_thrdpool **ptpool,
|
||||||
tpool->fn_return = fn_return;
|
tpool->fn_return = fn_return;
|
||||||
tpool->fn_user_data = user_data;
|
tpool->fn_user_data = user_data;
|
||||||
|
|
||||||
tpool->name = curlx_strdup(name);
|
/* a const string that remains */
|
||||||
if(!tpool->name)
|
tpool->name = name;
|
||||||
goto out;
|
|
||||||
|
|
||||||
#ifdef DEBUGBUILD
|
#ifdef DEBUGBUILD
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
|
|
||||||
struct curl_thrdq {
|
struct curl_thrdq {
|
||||||
char *name;
|
const char *name;
|
||||||
curl_mutex_t lock;
|
curl_mutex_t lock;
|
||||||
curl_cond_t await;
|
curl_cond_t await;
|
||||||
struct Curl_llist sendq;
|
struct Curl_llist sendq;
|
||||||
|
|
@ -187,7 +187,6 @@ static void thrdq_unlink(struct curl_thrdq *tqueue, bool locked, bool join)
|
||||||
|
|
||||||
Curl_llist_destroy(&tqueue->sendq, NULL);
|
Curl_llist_destroy(&tqueue->sendq, NULL);
|
||||||
Curl_llist_destroy(&tqueue->recvq, NULL);
|
Curl_llist_destroy(&tqueue->recvq, NULL);
|
||||||
curlx_free(tqueue->name);
|
|
||||||
Curl_cond_destroy(&tqueue->await);
|
Curl_cond_destroy(&tqueue->await);
|
||||||
if(locked)
|
if(locked)
|
||||||
Curl_mutex_release(&tqueue->lock);
|
Curl_mutex_release(&tqueue->lock);
|
||||||
|
|
@ -207,6 +206,7 @@ CURLcode Curl_thrdq_create(struct curl_thrdq **ptqueue,
|
||||||
{
|
{
|
||||||
struct curl_thrdq *tqueue;
|
struct curl_thrdq *tqueue;
|
||||||
CURLcode result = CURLE_OUT_OF_MEMORY;
|
CURLcode result = CURLE_OUT_OF_MEMORY;
|
||||||
|
DEBUGASSERT(name);
|
||||||
|
|
||||||
tqueue = curlx_calloc(1, sizeof(*tqueue));
|
tqueue = curlx_calloc(1, sizeof(*tqueue));
|
||||||
if(!tqueue)
|
if(!tqueue)
|
||||||
|
|
@ -221,9 +221,8 @@ CURLcode Curl_thrdq_create(struct curl_thrdq **ptqueue,
|
||||||
tqueue->fn_event = fn_event;
|
tqueue->fn_event = fn_event;
|
||||||
tqueue->fn_user_data = user_data;
|
tqueue->fn_user_data = user_data;
|
||||||
|
|
||||||
tqueue->name = curlx_strdup(name);
|
/* a const string that remains */
|
||||||
if(!tqueue->name)
|
tqueue->name = name;
|
||||||
goto out;
|
|
||||||
|
|
||||||
result = Curl_thrdpool_create(&tqueue->tpool, name,
|
result = Curl_thrdpool_create(&tqueue->tpool, name,
|
||||||
min_threads, max_threads, idle_time_ms,
|
min_threads, max_threads, idle_time_ms,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue