From 171ef826e1489031bc48745f29fa2d4657bf165f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 28 Mar 2019 10:49:05 +0100 Subject: make all library-internal static buffers thread-local We have a number of library-internal static global buffers which are mainly used for various stringification functions. This worked as all of the related Osmocom programs were strictly single-threaded. Let's make those buffers at least thread-local. This way every thread gets their own set of buffers, and it's safe for multiple threads to execute the same functions once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix version of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 --- src/fsm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/fsm.c') diff --git a/src/fsm.c b/src/fsm.c index 882a2b44..411797d6 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -545,7 +545,7 @@ void osmo_fsm_inst_free(struct osmo_fsm_inst *fi) */ const char *osmo_fsm_event_name(struct osmo_fsm *fsm, uint32_t event) { - static char buf[32]; + static __thread char buf[32]; if (!fsm->event_names) { snprintf(buf, sizeof(buf), "%"PRIu32, event); return buf; @@ -575,7 +575,7 @@ const char *osmo_fsm_inst_name(struct osmo_fsm_inst *fi) */ const char *osmo_fsm_state_name(struct osmo_fsm *fsm, uint32_t state) { - static char buf[32]; + static __thread char buf[32]; if (state >= fsm->num_states) { snprintf(buf, sizeof(buf), "unknown %"PRIu32, state); return buf; -- cgit v1.2.3