From: Jérémie Galarneau Date: Mon, 17 Apr 2023 18:46:56 +0000 (-0400) Subject: Replace uses of the URCU tls helpers by the standard thread_local X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=9fd09ab6c005d062ce436ad54738e83313f65af2;p=lttng-tools.git Replace uses of the URCU tls helpers by the standard thread_local Signed-off-by: Jérémie Galarneau Change-Id: I6751ad8c3a121638b07d333ac6f28547b25f54f2 --- diff --git a/include/lttng/health-internal.hpp b/include/lttng/health-internal.hpp index a3bf001ce..eee164cb1 100644 --- a/include/lttng/health-internal.hpp +++ b/include/lttng/health-internal.hpp @@ -65,7 +65,7 @@ struct health_comm_reply { } LTTNG_PACKED; /* Declare TLS health state. */ -extern DECLARE_URCU_TLS(struct health_state, health_state); +extern thread_local struct health_state health_state; /* * Update current counter by 1 to indicate that the thread entered or left a @@ -75,9 +75,9 @@ extern DECLARE_URCU_TLS(struct health_state, health_state); static inline void health_poll_entry() { /* Code MUST be in code execution state which is an even number. */ - LTTNG_ASSERT(!(uatomic_read(&URCU_TLS(health_state).current) & HEALTH_POLL_VALUE)); + LTTNG_ASSERT(!(uatomic_read(&health_state.current) & HEALTH_POLL_VALUE)); - uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); + uatomic_add(&health_state.current, HEALTH_POLL_VALUE); } /* @@ -88,9 +88,9 @@ static inline void health_poll_entry() static inline void health_poll_exit() { /* Code MUST be in poll execution state which is an odd number. */ - LTTNG_ASSERT(uatomic_read(&URCU_TLS(health_state).current) & HEALTH_POLL_VALUE); + LTTNG_ASSERT(uatomic_read(&health_state.current) & HEALTH_POLL_VALUE); - uatomic_add(&URCU_TLS(health_state).current, HEALTH_POLL_VALUE); + uatomic_add(&health_state.current, HEALTH_POLL_VALUE); } /* @@ -99,7 +99,7 @@ static inline void health_poll_exit() */ static inline void health_code_update() { - uatomic_add(&URCU_TLS(health_state).current, HEALTH_CODE_VALUE); + uatomic_add(&health_state.current, HEALTH_CODE_VALUE); } /* @@ -107,7 +107,7 @@ static inline void health_code_update() */ static inline void health_error() { - uatomic_or(&URCU_TLS(health_state).flags, HEALTH_ERROR); + uatomic_or(&health_state.flags, HEALTH_ERROR); } struct health_app *health_app_create(int nr_types); diff --git a/src/common/error.cpp b/src/common/error.cpp index cafb15f92..6bf1e30f0 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -29,10 +29,10 @@ namespace { int lttng_opt_abort_on_error = -1; /* TLS variable that contains the time of one single log entry. */ -DEFINE_URCU_TLS(struct log_time, error_log_time); +thread_local struct log_time error_log_time; } /* namespace */ -DEFINE_URCU_TLS(const char *, logger_thread_name); +thread_local const char * logger_thread_name; const char *log_add_time() { @@ -54,8 +54,8 @@ const char *log_add_time() } /* Format time in the TLS variable. */ - ret = snprintf(URCU_TLS(error_log_time).str, - sizeof(URCU_TLS(error_log_time).str), + ret = snprintf(error_log_time.str, + sizeof(error_log_time.str), "%02d:%02d:%02d.%09ld", tm.tm_hour, tm.tm_min, @@ -66,7 +66,7 @@ const char *log_add_time() } errno = errsv; - return URCU_TLS(error_log_time).str; + return error_log_time.str; error: /* Return an empty string on error so logging is not affected. */ @@ -79,7 +79,7 @@ void logger_set_thread_name(const char *name, bool set_pthread_name) int ret; LTTNG_ASSERT(name); - URCU_TLS(logger_thread_name) = name; + logger_thread_name = name; if (set_pthread_name) { ret = lttng_thread_setname(name); diff --git a/src/common/error.hpp b/src/common/error.hpp index 93616718f..d1996384d 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -46,7 +46,8 @@ struct log_time { /* Format: 00:00:00.000000000 plus NULL byte. */ char str[19]; }; -extern DECLARE_URCU_TLS(const char *, logger_thread_name); + +extern thread_local const char * logger_thread_name; extern int lttng_opt_quiet; extern int lttng_opt_verbose; @@ -159,7 +160,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) msg " - %s [%s]: " fmt " (in %s() at " __FILE__ \ ":" XSTR(__LINE__) ")\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args, \ __func__); \ } \ @@ -179,7 +180,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) __lttng_print(type, \ msg " - %s [%s]: " fmt "\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args); \ } \ } while (0) diff --git a/src/common/health/health.cpp b/src/common/health/health.cpp index 1969ea44c..444621f3a 100644 --- a/src/common/health/health.cpp +++ b/src/common/health/health.cpp @@ -44,7 +44,7 @@ struct health_app { }; /* Define TLS health state. */ -DEFINE_URCU_TLS(struct health_state, health_state); +thread_local struct health_state health_state; /* * Initialize health check subsytem. @@ -258,16 +258,16 @@ void health_register(struct health_app *ha, int type) LTTNG_ASSERT(type < ha->nr_types); /* Init TLS state. */ - uatomic_set(&URCU_TLS(health_state).last, 0); - uatomic_set(&URCU_TLS(health_state).last_time.tv_sec, 0); - uatomic_set(&URCU_TLS(health_state).last_time.tv_nsec, 0); - uatomic_set(&URCU_TLS(health_state).current, 0); - uatomic_set(&URCU_TLS(health_state).flags, (health_flags) 0); - uatomic_set(&URCU_TLS(health_state).type, type); + uatomic_set(&health_state.last, 0); + uatomic_set(&health_state.last_time.tv_sec, 0); + uatomic_set(&health_state.last_time.tv_nsec, 0); + uatomic_set(&health_state.current, 0); + uatomic_set(&health_state.flags, (health_flags) 0); + uatomic_set(&health_state.type, type); /* Add it to the global TLS state list. */ state_lock(ha); - cds_list_add(&URCU_TLS(health_state).node, &ha->list); + cds_list_add(&health_state.node, &ha->list); state_unlock(ha); } @@ -281,9 +281,9 @@ void health_unregister(struct health_app *ha) * On error, set the global_error_state since we are about to remove * the node from the global list. */ - if (uatomic_read(&URCU_TLS(health_state).flags) & HEALTH_ERROR) { - uatomic_set(&ha->flags[URCU_TLS(health_state).type], HEALTH_ERROR); + if (uatomic_read(&health_state.flags) & HEALTH_ERROR) { + uatomic_set(&ha->flags[health_state.type], HEALTH_ERROR); } - cds_list_del(&URCU_TLS(health_state).node); + cds_list_del(&health_state.node); state_unlock(ha); }