Module: kamailio
Branch: master
Commit: 1c70775530b1a3a905e8a983610cb0d092b0d240
URL:
https://github.com/kamailio/kamailio/commit/1c70775530b1a3a905e8a983610cb0d…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: S-P Chan <shihping.chan(a)gmail.com>
Date: 2024-01-05T08:09:34+08:00
tls: thread-local, revert 1a9b0b6361 as double-layer locking is redundant
- the 2nd lock was put in place as defensive programming for shm contention
- GH #3695: the underlying issue is early init of thread-locals
---
Modified: src/modules/tls/tls_init.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1c70775530b1a3a905e8a983610cb0d…
Patch:
https://github.com/kamailio/kamailio/commit/1c70775530b1a3a905e8a983610cb0d…
---
diff --git a/src/modules/tls/tls_init.c b/src/modules/tls/tls_init.c
index 6a46ecbf2aa..d077b41e08a 100644
--- a/src/modules/tls/tls_init.c
+++ b/src/modules/tls/tls_init.c
@@ -259,9 +259,6 @@ static void *ser_malloc(size_t size, const char *file, int line)
static ticks_t st = 0;
#endif
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
-
#ifdef RAND_NULL_MALLOC
/* start random null returns only after
* NULL_GRACE_PERIOD from first call */
@@ -288,8 +285,6 @@ static void *ser_malloc(size_t size, const char *file, int line)
size, file, line, bt_buf);
}
#endif
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
return p;
}
@@ -303,9 +298,6 @@ static void *ser_realloc(void *ptr, size_t size, const char *file, int
line)
static ticks_t st = 0;
#endif
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
-
#ifdef RAND_NULL_MALLOC
/* start random null returns only after
* NULL_GRACE_PERIOD from first call */
@@ -333,21 +325,14 @@ static void *ser_realloc(void *ptr, size_t size, const char *file,
int line)
}
#endif
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
-
return p;
}
static void ser_free(void *ptr, const char *fname, int fline)
{
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
if(ptr) {
shm_free(ptr);
}
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
}
#endif /* LIBRESSL_VERSION_NUMBER */
@@ -361,11 +346,7 @@ static void *ser_malloc(size_t size)
{
void *p;
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
p = shm_malloc(size);
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
return p;
}
@@ -373,22 +354,14 @@ static void *ser_malloc(size_t size)
static void *ser_realloc(void *ptr, size_t size)
{
void *p;
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
p = shm_realloc(ptr, size);
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
return p;
}
#else
static void *ser_malloc(size_t size, const char *fname, int fline)
{
void *p;
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
p = shm_malloc(size);
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
return p;
}
@@ -396,11 +369,7 @@ static void *ser_malloc(size_t size, const char *fname, int fline)
static void *ser_realloc(void *ptr, size_t size, const char *fname, int fline)
{
void *p;
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
p = shm_realloc(ptr, size);
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
return p;
}
#endif
@@ -417,24 +386,16 @@ static void ser_free(void *ptr)
* As shm_free() aborts on null pointers, we have to check for null pointer
* here in the wrapper function.
*/
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
if(ptr) {
shm_free(ptr);
}
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
}
#else
static void ser_free(void *ptr, const char *fname, int fline)
{
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_lock(ksr_tls_lock_shm);
if(ptr) {
shm_free(ptr);
}
- if(ksr_tls_init_mode & TLS_MODE_PTHREAD_LOCK_SHM)
- pthread_mutex_unlock(ksr_tls_lock_shm);
}
#endif