From: Daniel Stenberg Date: Thu, 6 Feb 2025 16:22:36 +0000 (+0100) Subject: asyn-thread: avoid the separate curl_mutex_t alloc X-Git-Tag: curl-8_13_0~472 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ee754d830da084c386d1f1778de5e00fb1c348e;p=thirdparty%2Fcurl.git asyn-thread: avoid the separate curl_mutex_t alloc Just make it a part of the thread_sync_data struct. Closes #16323 --- diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c index b6cf8dfa83..f5a533b34b 100644 --- a/lib/asyn-thread.c +++ b/lib/asyn-thread.c @@ -158,10 +158,7 @@ static struct thread_sync_data *conn_thread_sync_data(struct Curl_easy *data) static void destroy_thread_sync_data(struct thread_sync_data *tsd) { - if(tsd->mtx) { - Curl_mutex_destroy(tsd->mtx); - free(tsd->mtx); - } + Curl_mutex_destroy(&tsd->mutx); free(tsd->hostname); @@ -206,11 +203,7 @@ int init_thread_sync_data(struct thread_data *td, (void) hints; #endif - tsd->mtx = malloc(sizeof(curl_mutex_t)); - if(!tsd->mtx) - goto err_exit; - - Curl_mutex_init(tsd->mtx); + Curl_mutex_init(&tsd->mutx); #ifndef CURL_DISABLE_SOCKETPAIR /* create socket pair or pipe */ @@ -291,10 +284,10 @@ CURL_STDCALL getaddrinfo_thread(void *arg) Curl_addrinfo_set_port(tsd->res, tsd->port); } - Curl_mutex_acquire(tsd->mtx); + Curl_mutex_acquire(&tsd->mutx); if(tsd->done) { /* too late, gotta clean up the mess */ - Curl_mutex_release(tsd->mtx); + Curl_mutex_release(&tsd->mutx); destroy_thread_sync_data(tsd); } else { @@ -313,7 +306,7 @@ CURL_STDCALL getaddrinfo_thread(void *arg) } #endif tsd->done = TRUE; - Curl_mutex_release(tsd->mtx); + Curl_mutex_release(&tsd->mutx); } return 0; @@ -382,10 +375,10 @@ static void destroy_async_data(struct Curl_easy *data) * if the thread is still blocking in the resolve syscall, detach it and * let the thread do the cleanup... */ - Curl_mutex_acquire(td->tsd.mtx); + Curl_mutex_acquire(&td->tsd.mutx); done = td->tsd.done; td->tsd.done = TRUE; - Curl_mutex_release(td->tsd.mtx); + Curl_mutex_release(&td->tsd.mutx); if(!done) { Curl_thread_destroy(td->thread_hnd); @@ -588,9 +581,9 @@ CURLcode Curl_resolver_is_resolved(struct Curl_easy *data, return CURLE_UNRECOVERABLE_POLL; #endif - Curl_mutex_acquire(td->tsd.mtx); + Curl_mutex_acquire(&td->tsd.mutx); done = td->tsd.done; - Curl_mutex_release(td->tsd.mtx); + Curl_mutex_release(&td->tsd.mutx); if(done) { getaddrinfo_complete(data); diff --git a/lib/asyn.h b/lib/asyn.h index 21b01fe984..6e8e2debde 100644 --- a/lib/asyn.h +++ b/lib/asyn.h @@ -39,9 +39,9 @@ struct Curl_dns_entry; /* Data for synchronization between resolver thread and its parent */ struct thread_sync_data { - curl_mutex_t *mtx; char *hostname; /* hostname to resolve, Curl_async.hostname duplicate */ + curl_mutex_t mutx; #ifndef CURL_DISABLE_SOCKETPAIR curl_socket_t sock_pair[2]; /* eventfd/pipes/socket pair */ #endif