Change in ...libosmocore[master]: make all library-internal static buffers thread-local
Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/13436 ) Change subject: make all library-internal static buffers thread-local .. 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 --- M src/fsm.c M src/gb/gprs_ns.c M src/gsm/abis_nm.c M src/gsm/apn.c M src/gsm/gsm0808_utils.c M src/gsm/gsm23003.c M src/gsm/gsm48.c M src/gsm/gsm_utils.c M src/gsm/rsl.c M src/msgb.c M src/sim/core.c M src/socket.c M src/utils.c 13 files changed, 32 insertions(+), 33 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/fsm.c b/src/fsm.c index 882a2b4..411797d 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -545,7 +545,7 @@ */ 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_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; diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index cee4885..c77ebb3 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -1552,7 +1552,7 @@ const char *gprs_ns_ll_str(const struct gprs_nsvc *nsvc) { - static char buf[80]; + static __thread char buf[80]; return gprs_ns_ll_str_buf(buf, sizeof(buf), nsvc); } diff --git a/src/gsm/abis_nm.c b/src/gsm/abis_nm.c index a4c0e41..3fb8f0f 100644 --- a/src/gsm/abis_nm.c +++ b/src/gsm/abis_nm.c @@ -939,7 +939,7 @@ 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 88b45a4..a7074ea 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 26f7944..70eed15 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -611,7 +611,7 @@ 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 @@ */ 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_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 @@ * 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 @@ 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 a97ed07..4cc2671 100644 --- a/src/gsm/gsm23003.c +++ b/src/gsm/gsm23003.c @@ -107,7 +107,7 @@ */ 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 @@ */ const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits) { - static char buf[8]; + static
Change in ...libosmocore[master]: make all library-internal static buffers thread-local
Harald Welte has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/13436 ) Change subject: make all library-internal static buffers thread-local .. Patch Set 9: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 9 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-CC: Max Gerrit-Comment-Date: Tue, 04 Jun 2019 08:52:55 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in ...libosmocore[master]: make all library-internal static buffers thread-local
Hello fixeria, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/13436 to look at the new patch set (#9). Change subject: make all library-internal static buffers thread-local .. 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 --- M src/fsm.c M src/gb/gprs_ns.c M src/gsm/abis_nm.c M src/gsm/apn.c M src/gsm/gsm0808_utils.c M src/gsm/gsm23003.c M src/gsm/gsm48.c M src/gsm/gsm_utils.c M src/gsm/rsl.c M src/msgb.c M src/sim/core.c M src/socket.c M src/utils.c 13 files changed, 32 insertions(+), 33 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/13436/9 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 9 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-CC: Max Gerrit-MessageType: newpatchset
Change in ...libosmocore[master]: make all library-internal static buffers thread-local
Hello fixeria, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/libosmocore/+/13436 to look at the new patch set (#8). Change subject: make all library-internal static buffers thread-local .. 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 --- M src/fsm.c M src/gb/gprs_ns.c M src/gsm/abis_nm.c M src/gsm/apn.c M src/gsm/gsm0808_utils.c M src/gsm/gsm23003.c M src/gsm/gsm48.c M src/gsm/gsm_utils.c M src/gsm/rsl.c M src/msgb.c M src/sim/core.c M src/socket.c M src/utils.c 13 files changed, 32 insertions(+), 33 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/13436/8 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 8 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria Gerrit-CC: Max Gerrit-MessageType: newpatchset
Change in libosmocore[master]: make all library-internal static buffers thread-local
Max has posted comments on this change. ( https://gerrit.osmocom.org/13436 ) Change subject: make all library-internal static buffers thread-local .. Patch Set 6: (1 comment) https://gerrit.osmocom.org/#/c/13436/6//COMMIT_MSG Commit Message: https://gerrit.osmocom.org/#/c/13436/6//COMMIT_MSG@15 PS6, Line 15: execute the same functiosn once. They're of course still not typo: functions -- To view, visit https://gerrit.osmocom.org/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 6 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Vadim Yanitskiy Gerrit-CC: Max Gerrit-Comment-Date: Fri, 26 Apr 2019 11:00:50 + Gerrit-HasComments: Yes Gerrit-HasLabels: No
Change in libosmocore[master]: make all library-internal static buffers thread-local
Vadim Yanitskiy has posted comments on this change. ( https://gerrit.osmocom.org/13436 ) Change subject: make all library-internal static buffers thread-local .. Patch Set 5: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 5 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Vadim Yanitskiy Gerrit-Comment-Date: Thu, 11 Apr 2019 03:47:00 + Gerrit-HasComments: No Gerrit-HasLabels: Yes
Change in libosmocore[master]: make all library-internal static buffers thread-local
Hello Vadim Yanitskiy, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/13436 to look at the new patch set (#5). Change subject: make all library-internal static buffers thread-local .. 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 functiosn once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix versionf of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 --- M src/fsm.c M src/gb/gprs_ns.c M src/gsm/abis_nm.c M src/gsm/apn.c M src/gsm/gsm0808_utils.c M src/gsm/gsm23003.c M src/gsm/gsm48.c M src/gsm/gsm_utils.c M src/gsm/rsl.c M src/msgb.c M src/sim/core.c M src/socket.c M src/utils.c 13 files changed, 32 insertions(+), 33 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/13436/5 -- To view, visit https://gerrit.osmocom.org/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: newpatchset Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 5 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Vadim Yanitskiy
Change in libosmocore[master]: make all library-internal static buffers thread-local
Vadim Yanitskiy has posted comments on this change. ( https://gerrit.osmocom.org/13436 ) Change subject: make all library-internal static buffers thread-local .. Patch Set 4: Code-Review+1 (1 comment) https://gerrit.osmocom.org/#/c/13436/4/src/utils.c File src/utils.c: https://gerrit.osmocom.org/#/c/13436/4/src/utils.c@493 PS4, Line 493: static uint8_t buf[sizeof(uint64_t)]; What about this one? ;) This is the only one I could find using: git grep "static uint". -- To view, visit https://gerrit.osmocom.org/13436 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: comment Gerrit-Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 Gerrit-Change-Number: 13436 Gerrit-PatchSet: 4 Gerrit-Owner: Harald Welte Gerrit-Reviewer: Jenkins Builder (102) Gerrit-Reviewer: Vadim Yanitskiy Gerrit-Comment-Date: Wed, 03 Apr 2019 17:52:04 + Gerrit-HasComments: Yes Gerrit-HasLabels: Yes
Change in libosmocore[master]: make all library-internal static buffers thread-local
Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/13436 Change subject: make all library-internal static buffers thread-local .. 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 functiosn once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix versionf of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 --- M src/fsm.c M src/gb/gprs_ns.c M src/gsm/abis_nm.c M src/gsm/apn.c M src/gsm/gsm0808_utils.c M src/gsm/gsm23003.c M src/gsm/gsm48.c M src/gsm/gsm_utils.c M src/gsm/rsl.c M src/msgb.c M src/sim/core.c M src/socket.c M src/utils.c 13 files changed, 31 insertions(+), 32 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/36/13436/1 diff --git a/src/fsm.c b/src/fsm.c index d86ff4b..351e490 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -412,7 +412,7 @@ */ 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; @@ -442,7 +442,7 @@ */ 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; diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index d72003e..e4141ee 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -1548,7 +1548,7 @@ const char *gprs_ns_ll_str(const struct gprs_nsvc *nsvc) { - static char buf[80]; + static __thread char buf[80]; return gprs_ns_ll_str_buf(buf, sizeof(buf), nsvc); } diff --git a/src/gsm/abis_nm.c b/src/gsm/abis_nm.c index a4c0e41..3fb8f0f 100644 --- a/src/gsm/abis_nm.c +++ b/src/gsm/abis_nm.c @@ -939,7 +939,7 @@ 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 88b45a4..a7074ea 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 99cf188..c86496d 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -592,7 +592,7 @@ 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 @@ -1799,7 +1799,7 @@ */ 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); } @@ -1809,7 +1809,7 @@ */ 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); } @@ -1866,7 +1866,7 @@ * 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; } @@ -1893,7 +1893,7 @@ 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 6a8e509..20ee1ca 100644 --- a/src/gsm/gsm23003.c +++ b/src/gsm/gsm23003.c @@ -107,7 +107,7 @@ */ 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 @@ */ const char *osmo_mnc_name(uint16_t mnc, bool mnc_3_digits) { - static char buf[8]; + static __thread char buf[8];