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/gsm/gsm0808_utils.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/gsm/gsm0808_utils.c') diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c index 26f7944d..70eed15e 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -611,7 +611,7 @@ int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp) return ret; } -static char dbuf[256]; +static __thread char dbuf[256]; /*! Dump LCLS parameters (GCR excluded) into string for printing. * \param[out] buf caller-allocated output string buffer @@ -1819,7 +1819,7 @@ char *gsm0808_cell_id_name_buf(char *buf, size_t buflen, const struct gsm0808_ce */ const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid) { - static char buf[64]; + static __thread char buf[64]; return gsm0808_cell_id_name_buf(buf, sizeof(buf), cid); } @@ -1829,7 +1829,7 @@ const char *gsm0808_cell_id_name(const struct gsm0808_cell_id *cid) */ const char *gsm0808_cell_id_name2(const struct gsm0808_cell_id *cid) { - static char buf[64]; + static __thread char buf[64]; return gsm0808_cell_id_name_buf(buf, sizeof(buf), cid); } @@ -1886,7 +1886,7 @@ int gsm0808_cell_id_list_name_buf(char *buf, size_t buflen, const struct gsm0808 * See also gsm0808_cell_id_list_name_buf(). */ const char *gsm0808_cell_id_list_name(const struct gsm0808_cell_id_list2 *cil) { - static char buf[1024]; + static __thread char buf[1024]; gsm0808_cell_id_list_name_buf(buf, sizeof(buf), cil); return buf; } @@ -1913,7 +1913,7 @@ char *gsm0808_channel_type_name_buf(char *buf, size_t buf_len, const struct gsm0 const char *gsm0808_channel_type_name(const struct gsm0808_channel_type *ct) { - static char buf[128]; + static __thread char buf[128]; return gsm0808_channel_type_name_buf(buf, sizeof(buf), ct); } -- cgit v1.2.3