async-threaded resolver: use ref counter

Allocate the data shared between a transfer and an aync resolver thread
separately and use a reference counter to determine its release.

Change `Curl_thread_destroy()` to clear the thread handle, so that the
thread is considered "gone" and we do not try to join (and fail to)
afterwards.

Retake of the revert in fb15a986c0

Closes #16916
This commit is contained in:
Stefan Eissing 2025-04-02 12:25:21 +02:00 committed by Daniel Stenberg
parent 01e76702ac
commit 9b6148e9d9
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 145 additions and 106 deletions

View file

@ -82,11 +82,12 @@ err:
return curl_thread_t_null;
}
void Curl_thread_destroy(curl_thread_t hnd)
void Curl_thread_destroy(curl_thread_t *hnd)
{
if(hnd != curl_thread_t_null) {
pthread_detach(*hnd);
free(hnd);
if(*hnd != curl_thread_t_null) {
pthread_detach(**hnd);
free(*hnd);
*hnd = curl_thread_t_null;
}
}
@ -138,10 +139,12 @@ curl_thread_t Curl_thread_create(
return t;
}
void Curl_thread_destroy(curl_thread_t hnd)
void Curl_thread_destroy(curl_thread_t *hnd)
{
if(hnd != curl_thread_t_null)
CloseHandle(hnd);
if(*hnd != curl_thread_t_null) {
CloseHandle(*hnd);
*hnd = curl_thread_t_null;
}
}
int Curl_thread_join(curl_thread_t *hnd)
@ -153,9 +156,7 @@ int Curl_thread_join(curl_thread_t *hnd)
int ret = (WaitForSingleObjectEx(*hnd, INFINITE, FALSE) == WAIT_OBJECT_0);
#endif
Curl_thread_destroy(*hnd);
*hnd = curl_thread_t_null;
Curl_thread_destroy(hnd);
return ret;
}