aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/jemalloc/src/mutex.c
diff options
context:
space:
mode:
authorrdna <rdna@yandex-team.ru>2022-02-10 16:48:05 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:05 +0300
commit37a2795395ba606e239b750ff2afb17905274ec4 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /contrib/libs/jemalloc/src/mutex.c
parent7804d69d166cc162c0be19dafd698a6ad7e42b25 (diff)
downloadydb-37a2795395ba606e239b750ff2afb17905274ec4.tar.gz
Restoring authorship annotation for <rdna@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/jemalloc/src/mutex.c')
-rw-r--r--contrib/libs/jemalloc/src/mutex.c162
1 files changed, 81 insertions, 81 deletions
diff --git a/contrib/libs/jemalloc/src/mutex.c b/contrib/libs/jemalloc/src/mutex.c
index 92965c26bd7..3f920f5b1cd 100644
--- a/contrib/libs/jemalloc/src/mutex.c
+++ b/contrib/libs/jemalloc/src/mutex.c
@@ -1,48 +1,48 @@
#define JEMALLOC_MUTEX_C_
#include "jemalloc/internal/jemalloc_preamble.h"
#include "jemalloc/internal/jemalloc_internal_includes.h"
-
+
#include "jemalloc/internal/assert.h"
#include "jemalloc/internal/malloc_io.h"
#include "jemalloc/internal/spin.h"
-
-#ifndef _CRT_SPINCOUNT
+
+#ifndef _CRT_SPINCOUNT
#define _CRT_SPINCOUNT 4000
-#endif
-
-/******************************************************************************/
-/* Data. */
-
-#ifdef JEMALLOC_LAZY_LOCK
-bool isthreaded = false;
-#endif
-#ifdef JEMALLOC_MUTEX_INIT_CB
-static bool postpone_init = true;
-static malloc_mutex_t *postponed_mutexes = NULL;
-#endif
-
-/******************************************************************************/
-/*
- * We intercept pthread_create() calls in order to toggle isthreaded if the
- * process goes multi-threaded.
- */
-
-#if defined(JEMALLOC_LAZY_LOCK) && !defined(_WIN32)
-JEMALLOC_EXPORT int
-pthread_create(pthread_t *__restrict thread,
- const pthread_attr_t *__restrict attr, void *(*start_routine)(void *),
+#endif
+
+/******************************************************************************/
+/* Data. */
+
+#ifdef JEMALLOC_LAZY_LOCK
+bool isthreaded = false;
+#endif
+#ifdef JEMALLOC_MUTEX_INIT_CB
+static bool postpone_init = true;
+static malloc_mutex_t *postponed_mutexes = NULL;
+#endif
+
+/******************************************************************************/
+/*
+ * We intercept pthread_create() calls in order to toggle isthreaded if the
+ * process goes multi-threaded.
+ */
+
+#if defined(JEMALLOC_LAZY_LOCK) && !defined(_WIN32)
+JEMALLOC_EXPORT int
+pthread_create(pthread_t *__restrict thread,
+ const pthread_attr_t *__restrict attr, void *(*start_routine)(void *),
void *__restrict arg) {
return pthread_create_wrapper(thread, attr, start_routine, arg);
-}
-#endif
-
-/******************************************************************************/
-
-#ifdef JEMALLOC_MUTEX_INIT_CB
-JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
- void *(calloc_cb)(size_t, size_t));
-#endif
-
+}
+#endif
+
+/******************************************************************************/
+
+#ifdef JEMALLOC_MUTEX_INIT_CB
+JEMALLOC_EXPORT int _pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+ void *(calloc_cb)(size_t, size_t));
+#endif
+
void
malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
mutex_prof_data_t *data = &mutex->prof_data;
@@ -131,44 +131,44 @@ mutex_addr_comp(const witness_t *witness1, void *mutex1,
}
}
-bool
+bool
malloc_mutex_init(malloc_mutex_t *mutex, const char *name,
witness_rank_t rank, malloc_mutex_lock_order_t lock_order) {
mutex_prof_data_init(&mutex->prof_data);
-#ifdef _WIN32
+#ifdef _WIN32
# if _WIN32_WINNT >= 0x0600
InitializeSRWLock(&mutex->lock);
# else
- if (!InitializeCriticalSectionAndSpinCount(&mutex->lock,
+ if (!InitializeCriticalSectionAndSpinCount(&mutex->lock,
_CRT_SPINCOUNT)) {
return true;
}
# endif
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
mutex->lock = OS_UNFAIR_LOCK_INIT;
-#elif (defined(JEMALLOC_MUTEX_INIT_CB))
- if (postpone_init) {
- mutex->postponed_next = postponed_mutexes;
- postponed_mutexes = mutex;
- } else {
+#elif (defined(JEMALLOC_MUTEX_INIT_CB))
+ if (postpone_init) {
+ mutex->postponed_next = postponed_mutexes;
+ postponed_mutexes = mutex;
+ } else {
if (_pthread_mutex_init_calloc_cb(&mutex->lock,
bootstrap_calloc) != 0) {
return true;
}
- }
-#else
- pthread_mutexattr_t attr;
-
+ }
+#else
+ pthread_mutexattr_t attr;
+
if (pthread_mutexattr_init(&attr) != 0) {
return true;
}
- pthread_mutexattr_settype(&attr, MALLOC_MUTEX_TYPE);
- if (pthread_mutex_init(&mutex->lock, &attr) != 0) {
- pthread_mutexattr_destroy(&attr);
+ pthread_mutexattr_settype(&attr, MALLOC_MUTEX_TYPE);
+ if (pthread_mutex_init(&mutex->lock, &attr) != 0) {
+ pthread_mutexattr_destroy(&attr);
return true;
- }
- pthread_mutexattr_destroy(&attr);
-#endif
+ }
+ pthread_mutexattr_destroy(&attr);
+#endif
if (config_debug) {
mutex->lock_order = lock_order;
if (lock_order == malloc_mutex_address_ordered) {
@@ -179,45 +179,45 @@ malloc_mutex_init(malloc_mutex_t *mutex, const char *name,
}
}
return false;
-}
-
-void
+}
+
+void
malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex) {
malloc_mutex_lock(tsdn, mutex);
-}
-
-void
+}
+
+void
malloc_mutex_postfork_parent(tsdn_t *tsdn, malloc_mutex_t *mutex) {
malloc_mutex_unlock(tsdn, mutex);
-}
-
-void
+}
+
+void
malloc_mutex_postfork_child(tsdn_t *tsdn, malloc_mutex_t *mutex) {
-#ifdef JEMALLOC_MUTEX_INIT_CB
+#ifdef JEMALLOC_MUTEX_INIT_CB
malloc_mutex_unlock(tsdn, mutex);
-#else
+#else
if (malloc_mutex_init(mutex, mutex->witness.name,
mutex->witness.rank, mutex->lock_order)) {
- malloc_printf("<jemalloc>: Error re-initializing mutex in "
- "child\n");
+ malloc_printf("<jemalloc>: Error re-initializing mutex in "
+ "child\n");
if (opt_abort) {
- abort();
+ abort();
}
- }
-#endif
-}
-
-bool
+ }
+#endif
+}
+
+bool
malloc_mutex_boot(void) {
-#ifdef JEMALLOC_MUTEX_INIT_CB
- postpone_init = false;
- while (postponed_mutexes != NULL) {
- if (_pthread_mutex_init_calloc_cb(&postponed_mutexes->lock,
+#ifdef JEMALLOC_MUTEX_INIT_CB
+ postpone_init = false;
+ while (postponed_mutexes != NULL) {
+ if (_pthread_mutex_init_calloc_cb(&postponed_mutexes->lock,
bootstrap_calloc) != 0) {
return true;
}
- postponed_mutexes = postponed_mutexes->postponed_next;
- }
-#endif
+ postponed_mutexes = postponed_mutexes->postponed_next;
+ }
+#endif
return false;
-}
+}