Replace uses of the URCU tls helpers by the standard thread_local
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 17 Apr 2023 18:46:56 +0000 (14:46 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 18 Apr 2023 14:39:14 +0000 (10:39 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I6751ad8c3a121638b07d333ac6f28547b25f54f2

include/lttng/health-internal.hpp
src/common/error.cpp
src/common/error.hpp
src/common/health/health.cpp

index a3bf001ce757879c8eb728286c1961b720da18a5..eee164cb141d4b86ed009d52d31c8ccfa9f5508e 100644 (file)
@@ -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);
index cafb15f92948b8ee209fae25422ff9459a6da382..6bf1e30f09274e6b7215bd6b6cde9151ffb0c646 100644 (file)
@@ -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);
index 93616718f65dd89481492d39bf7ef0fe8ba1d261..d1996384db5c839cd2764e62d36dcb7d26e6499c 100644 (file)
@@ -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)
index 1969ea44c5e2629ca147d270abb99731b2e23bd3..444621f3a94df593c74327f2eff5a940669e0167 100644 (file)
@@ -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);
 }
This page took 0.030096 seconds and 4 git commands to generate.