diff options
author | Harald Welte <laforge@gnumonks.org> | 2019-03-28 10:49:05 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2019-06-04 10:47:30 +0200 |
commit | 171ef826e1489031bc48745f29fa2d4657bf165f (patch) | |
tree | 08c8c32fae7f33f59df7621d6e3e8b8e127d856b /src/utils.c | |
parent | 9b207419105c5e07504b1b7bf380eda07c127bb2 (diff) |
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
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c index 59dc8163..c38f5305 100644 --- a/src/utils.c +++ b/src/utils.c @@ -41,7 +41,7 @@ * * \file utils.c */ -static char namebuf[255]; +static __thread char namebuf[255]; /*! get human-readable string for given value * \param[in] vs Array of value_string tuples @@ -219,7 +219,7 @@ int osmo_hexparse(const char *str, uint8_t *b, int max_len) return nibblepos >> 1; } -static char hexd_buff[4096]; +static __thread char hexd_buff[4096]; static const char hex_chars[] = "0123456789abcdef"; /*! Convert binary sequence to hexadecimal ASCII string. @@ -492,7 +492,7 @@ uint64_t osmo_decode_big_endian(const uint8_t *data, size_t data_len) * sizeof(uint64_t), only the least significant bytes of value are encoded. */ uint8_t *osmo_encode_big_endian(uint64_t value, size_t data_len) { - static uint8_t buf[sizeof(uint64_t)]; + static __thread uint8_t buf[sizeof(uint64_t)]; OSMO_ASSERT(data_len <= ARRAY_SIZE(buf)); osmo_store64be_ext(value, buf, data_len); return buf; @@ -908,7 +908,7 @@ size_t osmo_str_tolower_buf(char *dest, size_t dest_len, const char *src) */ const char *osmo_str_tolower(const char *src) { - static char buf[128]; + static __thread char buf[128]; osmo_str_tolower_buf(buf, sizeof(buf), src); return buf; } @@ -967,7 +967,7 @@ size_t osmo_str_toupper_buf(char *dest, size_t dest_len, const char *src) */ const char *osmo_str_toupper(const char *src) { - static char buf[128]; + static __thread char buf[128]; osmo_str_toupper_buf(buf, sizeof(buf), src); return buf; } |