summaryrefslogtreecommitdiffstats
path: root/src/gsm
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-03-28 10:49:05 +0100
committerHarald Welte <laforge@gnumonks.org>2019-06-04 10:47:30 +0200
commit171ef826e1489031bc48745f29fa2d4657bf165f (patch)
tree08c8c32fae7f33f59df7621d6e3e8b8e127d856b /src/gsm
parent9b207419105c5e07504b1b7bf380eda07c127bb2 (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/gsm')
-rw-r--r--src/gsm/abis_nm.c2
-rw-r--r--src/gsm/apn.c2
-rw-r--r--src/gsm/gsm0808_utils.c10
-rw-r--r--src/gsm/gsm23003.c16
-rw-r--r--src/gsm/gsm48.c8
-rw-r--r--src/gsm/gsm_utils.c2
-rw-r--r--src/gsm/rsl.c2
7 files changed, 21 insertions, 21 deletions
diff --git a/src/gsm/abis_nm.c b/src/gsm/abis_nm.c
index a4c0e41f..3fb8f0f5 100644
--- a/src/gsm/abis_nm.c
+++ b/src/gsm/abis_nm.c
@@ -939,7 +939,7 @@ char *abis_nm_dump_foh_buf(char *buf, size_t buf_len, const struct abis_om_fom_h
const char *abis_nm_dump_foh(const struct abis_om_fom_hdr *foh)
{
- static char foh_buf[128];
+ static __thread char foh_buf[128];
return abis_nm_dump_foh_buf(foh_buf, sizeof(foh_buf), foh);
}
diff --git a/src/gsm/apn.c b/src/gsm/apn.c
index 88b45a4b..a7074eab 100644
--- a/src/gsm/apn.c
+++ b/src/gsm/apn.c
@@ -31,7 +31,7 @@
#define APN_OI_GPRS_FMT "mnc%03u.mcc%03u.gprs"
#define APN_GPRS_FMT "%s.mnc%03u.mcc%03u.gprs"
-static char apn_strbuf[APN_MAXLEN+1];
+static __thread char apn_strbuf[APN_MAXLEN+1];
char *osmo_apn_qualify_buf(char *buf, size_t buf_len, unsigned int mcc, unsigned int mnc, const char *ni)
{
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);
}
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c
index a97ed079..4cc2671f 100644
--- a/src/gsm/gsm23003.c
+++ b/src/gsm/gsm23003.c
@@ -107,7 +107,7 @@ char *osmo_mcc_name_buf(char *buf, size_t buf_len, uint16_t mcc)
*/
const char *osmo_mcc_name(uint16_t mcc)
{
- static char buf[8];
+ static __thread char buf[8];
return osmo_mcc_name_buf(buf, sizeof(buf), mcc);
}
@@ -158,7 +158,7 @@ char *osmo_mnc_name_c(const void *ctx, uint16_t mnc, bool mnc_3_digits)
*/
const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits)
{
- static char buf[8];
+ static __thread char buf[8];
return osmo_mnc_name_buf(buf, sizeof(buf), mnc, mnc_3_digits);
}
@@ -182,7 +182,7 @@ char *osmo_plmn_name_buf(char *buf, size_t buf_len, const struct osmo_plmn_id *p
*/
const char *osmo_plmn_name(const struct osmo_plmn_id *plmn)
{
- static char buf[16];
+ static __thread char buf[16];
return osmo_plmn_name_buf(buf, sizeof(buf), plmn);
}
@@ -193,7 +193,7 @@ const char *osmo_plmn_name(const struct osmo_plmn_id *plmn)
*/
const char *osmo_plmn_name2(const struct osmo_plmn_id *plmn)
{
- static char buf[16];
+ static __thread char buf[16];
return osmo_plmn_name_buf(buf, sizeof(buf), plmn);
}
@@ -230,7 +230,7 @@ char *osmo_lai_name_buf(char *buf, size_t buf_len, const struct osmo_location_ar
*/
const char *osmo_lai_name(const struct osmo_location_area_id *lai)
{
- static char buf[32];
+ static __thread char buf[32];
return osmo_lai_name_buf(buf, sizeof(buf), lai);
}
@@ -265,7 +265,7 @@ char *osmo_cgi_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global
*/
const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi)
{
- static char buf[32];
+ static __thread char buf[32];
return osmo_cgi_name_buf(buf, sizeof(buf), cgi);
}
@@ -276,7 +276,7 @@ const char *osmo_cgi_name(const struct osmo_cell_global_id *cgi)
*/
const char *osmo_cgi_name2(const struct osmo_cell_global_id *cgi)
{
- static char buf[32];
+ static __thread char buf[32];
return osmo_cgi_name_buf(buf, sizeof(buf), cgi);
}
@@ -320,7 +320,7 @@ char *osmo_gummei_name_buf(char *buf, size_t buf_len, const struct osmo_gummei *
*/
const char *osmo_gummei_name(const struct osmo_gummei *gummei)
{
- static char buf[32];
+ static __thread char buf[32];
return osmo_gummei_name_buf(buf, sizeof(buf), gummei);
}
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index c2c19cfe..c97337b6 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -203,7 +203,7 @@ char *osmo_rai_name_buf(char *buf, size_t buf_len, const struct gprs_ra_id *rai)
*/
const char *osmo_rai_name(const struct gprs_ra_id *rai)
{
- static char buf[32];
+ static __thread char buf[32];
return osmo_rai_name_buf(buf, sizeof(buf), rai);
}
@@ -502,7 +502,7 @@ char *osmo_mi_name_buf(char *buf, size_t buf_len, const uint8_t *mi, uint8_t mi_
*/
const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
{
- static char mi_name[10 + GSM48_MI_SIZE + 1];
+ static __thread char mi_name[10 + GSM48_MI_SIZE + 1];
return osmo_mi_name_buf(mi_name, sizeof(mi_name), mi, mi_len);
}
@@ -1150,7 +1150,7 @@ char *gsm48_pdisc_msgtype_name_buf(char *buf, size_t buf_len, uint8_t pdisc, uin
*/
const char *gsm48_pdisc_msgtype_name(uint8_t pdisc, uint8_t msg_type)
{
- static char namebuf[64];
+ static __thread char namebuf[64];
return gsm48_pdisc_msgtype_name_buf(namebuf, sizeof(namebuf), pdisc, msg_type);
}
@@ -1303,7 +1303,7 @@ char *osmo_gsm48_classmark_a5_name_buf(char *buf, size_t buf_len, const struct o
*/
const char *osmo_gsm48_classmark_a5_name(const struct osmo_gsm48_classmark *cm)
{
- static char buf[128];
+ static __thread char buf[128];
return osmo_gsm48_classmark_a5_name_buf(buf, sizeof(buf), cm);
}
diff --git a/src/gsm/gsm_utils.c b/src/gsm/gsm_utils.c
index 07f053c2..f154c2b6 100644
--- a/src/gsm/gsm_utils.c
+++ b/src/gsm/gsm_utils.c
@@ -897,7 +897,7 @@ char *osmo_dump_gsmtime_buf(char *buf, size_t buf_len, const struct gsm_time *tm
char *osmo_dump_gsmtime(const struct gsm_time *tm)
{
- static char buf[64];
+ static __thread char buf[64];
return osmo_dump_gsmtime_buf(buf, sizeof(buf), tm);
}
diff --git a/src/gsm/rsl.c b/src/gsm/rsl.c
index 0409734e..3be01112 100644
--- a/src/gsm/rsl.c
+++ b/src/gsm/rsl.c
@@ -264,7 +264,7 @@ char *rsl_chan_nr_str_buf(char *buf, size_t buf_len, uint8_t chan_nr)
*/
const char *rsl_chan_nr_str(uint8_t chan_nr)
{
- static char str[20];
+ static __thread char str[20];
return rsl_chan_nr_str_buf(str, sizeof(str), chan_nr);
}