Skip to content

Commit a97d29d

Browse files
authored
Refactor[bmqsys] Remove tlsbool to set thread names (#1227)
Signed-off-by: Christopher Beard <cbeard9@bloomberg.net>
1 parent c74473e commit a97d29d

7 files changed

Lines changed: 98 additions & 665 deletions

File tree

src/groups/bmq/bmqsys/bmqsys_threadutil.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#include <bmqscm_version.h>
2020

21-
#include <bmqu_tlsbool.h>
22-
2321
// BDE
2422
#include <ball_log.h>
2523
#include <bsl_cstring.h>
@@ -51,12 +49,7 @@ void ThreadUtil::setCurrentThreadName(const bsl::string& value)
5149

5250
void ThreadUtil::setCurrentThreadNameOnce(const bsl::string& value)
5351
{
54-
#ifdef BSLS_PLATFORM_CMP_CLANG
55-
// Suppress "exit-time-destructor" warning on Clang by qualifying the
56-
// static variable 's_named' with Clang-specific attribute.
57-
[[clang::no_destroy]]
58-
#endif
59-
static bmqu::TLSBool s_named(false, true);
52+
static BSLS_KEYWORD_THREAD_LOCAL bool s_named = false;
6053

6154
if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(!s_named)) {
6255
BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright 2026 Bloomberg Finance L.P.
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// bmqsys_threadutil.t.cpp -*-C++-*-
17+
#include <bmqsys_threadutil.h>
18+
19+
// BDE
20+
#include <bdlf_bind.h>
21+
#include <bslmt_threadutil.h>
22+
23+
// TEST DRIVER
24+
#include <bmqtst_testhelper.h>
25+
26+
// CONVENIENCE
27+
using namespace BloombergLP;
28+
using namespace bsl;
29+
30+
// ============================================================================
31+
// TESTS
32+
// ----------------------------------------------------------------------------
33+
34+
static void test1_breathingTest()
35+
// ------------------------------------------------------------------------
36+
// BREATHING TEST
37+
//
38+
// Concerns:
39+
// Exercise the basic functionality of the component.
40+
//
41+
// Plan:
42+
// Set the thread name "once".
43+
// Validate the thread name does not update.
44+
//
45+
// Testing:
46+
// ------------------------------------------------------------------------
47+
{
48+
bmqtst::TestHelper::printTestName("BREATHING TEST");
49+
50+
// Skip under MemorySanitizer: bslmt::ThreadUtil::getThreadName uses
51+
// pthread_getname_np which leaves the buffer uninitialized from MSan's
52+
// perspective.
53+
#if defined(__has_feature) // Clang-supported method for checking sanitizers.
54+
const bool skipTest = __has_feature(memory_sanitizer);
55+
#elif defined(__SANITIZE_MEMORY__)
56+
// GCC-supported macros for checking MSAN.
57+
const bool skipTest = true;
58+
#else
59+
const bool skipTest = false;
60+
#endif
61+
62+
if (skipTest) {
63+
bsl::cout << "Test skipped (running under sanitizer)" << bsl::endl;
64+
return; // RETURN
65+
}
66+
67+
bsl::string threadName;
68+
69+
bmqsys::ThreadUtil::setCurrentThreadNameOnce("TestThread1");
70+
bslmt::ThreadUtil::getThreadName(&threadName);
71+
BMQTST_ASSERT_EQ(threadName, "TestThread1");
72+
73+
bmqsys::ThreadUtil::setCurrentThreadNameOnce("TestThread2");
74+
bslmt::ThreadUtil::getThreadName(&threadName);
75+
BMQTST_ASSERT_EQ(threadName, "TestThread1");
76+
}
77+
78+
// ============================================================================
79+
// MAIN PROGRAM
80+
// ----------------------------------------------------------------------------
81+
82+
int main(int argc, char* argv[])
83+
{
84+
TEST_PROLOG(bmqtst::TestHelper::e_DEFAULT);
85+
86+
switch (_testCase) {
87+
case 0:
88+
case 1: test1_breathingTest(); break;
89+
default: {
90+
cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl;
91+
bmqtst::TestHelperUtil::testStatus() = -1;
92+
} break;
93+
}
94+
95+
TEST_EPILOG(bmqtst::TestHelper::e_CHECK_DEF_GBL_ALLOC);
96+
}

src/groups/bmq/bmqu/bmqu_tlsbool.cpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)