Skip to content

Commit

Permalink
correct two warnings, add consistency checks (#4934)
Browse files Browse the repository at this point in the history
* correct two warnings, add consistency checks

* remove checks in muteximpl
  • Loading branch information
Jeffrey Mendelsohn authored and GitHub Enterprise committed Sep 16, 2024
1 parent 7449d6e commit 04d8378
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions groups/bsl/bslmt/bslmt_threadutil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
#include <bslma_defaultallocatorguard.h>
#include <bslma_testallocator.h>

#include <bslmf_assert.h>
#include <bslmf_issame.h>

#include <bsls_assert.h>
#include <bsls_asserttest.h>
#include <bsls_atomic.h>
#include <bsls_libraryfeatures.h>
#include <bsls_platform.h>
#include <bsls_stopwatch.h>
#include <bsls_systemclocktype.h>
Expand Down Expand Up @@ -57,6 +61,7 @@

#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
#include <thread>
#include <bsl_thread.h>
#endif

using namespace BloombergLP;
Expand Down Expand Up @@ -1488,20 +1493,14 @@ long myAbs(long a)
return a >= 0 ? a : -a;
}

#ifdef BSLS_PLATFORM_PRAGMA_GCC_DIAGNOSTIC_CLANG
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winfinite-recursion"
#endif
#ifdef BSLS_PLATFORM_CMP_MSVC
#pragma warning(push)
#pragma warning(disable:4717)
#endif

void testCaseMinus1Recurser(const char *start)
{
enum { k_BUF_LEN = 1024 };

char buffer[k_BUF_LEN];
static double lastDistance = 1;

static double lastDistance = 1;
static unsigned iterations = 0;

double distance = (double) mymax(myAbs(&buffer[0] - start),
myAbs(&buffer[k_BUF_LEN - 1] - start));
Expand All @@ -1510,7 +1509,10 @@ void testCaseMinus1Recurser(const char *start)
lastDistance = distance;
}

testCaseMinus1Recurser(start);
if (iterations < 0xffffffffu) {
++iterations;
testCaseMinus1Recurser(start);
}
}

extern "C" void *testCaseMinus1ThreadMain(void *)
Expand All @@ -1520,12 +1522,6 @@ extern "C" void *testCaseMinus1ThreadMain(void *)

return 0;
}
#ifdef BSLS_PLATFORM_CMP_MSVC
#pragma warning(pop)
#endif
#ifdef BSLS_PLATFORM_PRAGMA_GCC_DIAGNOSTIC_CLANG
#pragma GCC diagnostic pop
#endif

// ----------------------------------------------------------------------------
// TEST CASE -2
Expand Down Expand Up @@ -1595,6 +1591,8 @@ extern "C" void *secondClearanceTest(void *vStackSize)
printf("%d\n", diff);
}

pc = 0;

return 0;
}

Expand Down Expand Up @@ -1629,6 +1627,25 @@ int main(int argc, char *argv[])
#endif

switch (test) { case 0: // Zero is always the leading case.
case 20: {
// --------------------------------------------------------------------
// THREAD LIBRARY CONSISTENCY
//
// Concern:
//: 1 The used thread library matches the one used in 'std'.
//
// Plan:
//: 1 Assert the native types for thread handles match. (C-1)
// --------------------------------------------------------------------

#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY

BSLMF_ASSERT(
(bsl::is_same<BloombergLP::bslmt::ThreadUtil::NativeHandle,
std::thread::native_handle_type>::value));

#endif
} break;
case 19: {
// --------------------------------------------------------------------
// NAMED DETACHED THREADS
Expand Down

0 comments on commit 04d8378

Please sign in to comment.