mirror of
https://github.com/curl/curl.git
synced 2026-04-14 22:41:40 +03:00
share: concurrency handling, easy updates
Replace the `volatile int dirty` with a reference counter protected by a mutex when available. Solve the problem of when to call application's lock function by adding a volatile flag that indicates a share has been added to easy handles in its lifetime. That flag ever goes from FALSE to TRUE, so volatile might work (in the absence of a mutex). (The problem is that the lock/unlock functions need 2-3 `curl_share_setopt()` invocations to become usable and there is no way of telling if the third will ever happen. Calling the lock function before the 3rd setopt may crash the application.) When removing a share from an easy handle (or replacing it with another share), detach the easy connection on a share with a connection pool. When cleaning up a share, allow this even if it is still used in easy handles. It will be destroyed when the reference count drops to 0. Closes #20870
This commit is contained in:
parent
745344ea4e
commit
82009c4220
26 changed files with 378 additions and 210 deletions
|
|
@ -25,7 +25,11 @@
|
|||
***************************************************************************/
|
||||
#include "curl_setup.h"
|
||||
|
||||
#ifdef USE_THREADS_POSIX
|
||||
#ifdef USE_MUTEX
|
||||
#ifdef HAVE_THREADS_POSIX
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
# define CURL_THREAD_RETURN_T unsigned int
|
||||
# define CURL_STDCALL
|
||||
# define curl_mutex_t pthread_mutex_t
|
||||
|
|
@ -35,7 +39,7 @@
|
|||
# define Curl_mutex_acquire(m) pthread_mutex_lock(m)
|
||||
# define Curl_mutex_release(m) pthread_mutex_unlock(m)
|
||||
# define Curl_mutex_destroy(m) pthread_mutex_destroy(m)
|
||||
#elif defined(USE_THREADS_WIN32)
|
||||
#elif defined(_WIN32)
|
||||
# define CURL_THREAD_RETURN_T DWORD
|
||||
# define CURL_STDCALL WINAPI
|
||||
# define curl_mutex_t CRITICAL_SECTION
|
||||
|
|
@ -45,9 +49,12 @@
|
|||
# define Curl_mutex_acquire(m) EnterCriticalSection(m)
|
||||
# define Curl_mutex_release(m) LeaveCriticalSection(m)
|
||||
# define Curl_mutex_destroy(m) DeleteCriticalSection(m)
|
||||
#else
|
||||
#error neither HAVE_THREADS_POSIX nor _WIN32 defined
|
||||
#endif
|
||||
#endif /* USE_MUTEX */
|
||||
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_THREADS
|
||||
|
||||
curl_thread_t Curl_thread_create(CURL_THREAD_RETURN_T
|
||||
(CURL_STDCALL *func) (void *), void *arg);
|
||||
|
|
@ -56,6 +63,6 @@ void Curl_thread_destroy(curl_thread_t *hnd);
|
|||
|
||||
int Curl_thread_join(curl_thread_t *hnd);
|
||||
|
||||
#endif /* USE_THREADS_POSIX || USE_THREADS_WIN32 */
|
||||
#endif /* USE_THREADS */
|
||||
|
||||
#endif /* HEADER_CURL_THREADS_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue