mirror of
https://github.com/curl/curl.git
synced 2026-08-25 18:33:42 +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
|
|
@ -65,14 +65,14 @@ static struct backtrace_state *btstate;
|
|||
static char membuf[10000];
|
||||
static size_t memwidx = 0; /* write index */
|
||||
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_MUTEX
|
||||
static bool dbg_mutex_init = 0;
|
||||
static curl_mutex_t dbg_mutex;
|
||||
#endif
|
||||
|
||||
static bool curl_dbg_lock(void)
|
||||
{
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_MUTEX
|
||||
if(dbg_mutex_init) {
|
||||
Curl_mutex_acquire(&dbg_mutex);
|
||||
return TRUE;
|
||||
|
|
@ -83,7 +83,7 @@ static bool curl_dbg_lock(void)
|
|||
|
||||
static void curl_dbg_unlock(bool was_locked)
|
||||
{
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_MUTEX
|
||||
if(was_locked)
|
||||
Curl_mutex_release(&dbg_mutex);
|
||||
#else
|
||||
|
|
@ -108,7 +108,7 @@ static void curl_dbg_cleanup(void)
|
|||
fclose(curl_dbg_logfile);
|
||||
}
|
||||
curl_dbg_logfile = NULL;
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_MUTEX
|
||||
if(dbg_mutex_init) {
|
||||
Curl_mutex_destroy(&dbg_mutex);
|
||||
dbg_mutex_init = FALSE;
|
||||
|
|
@ -157,7 +157,7 @@ void curl_dbg_memdebug(const char *logname)
|
|||
setbuf(curl_dbg_logfile, (char *)NULL);
|
||||
#endif
|
||||
}
|
||||
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
|
||||
#ifdef USE_MUTEX
|
||||
if(!dbg_mutex_init) {
|
||||
dbg_mutex_init = TRUE;
|
||||
Curl_mutex_init(&dbg_mutex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue