Skip to content

Commit 14838d1

Browse files
committed
Make is_lock_free constexpr.
This makes it possible to use it in `static_assert`, which is better than a runtime error.
1 parent feb72d0 commit 14838d1

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

blockingconcurrentqueue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ class BlockingConcurrentQueue
544544
// Returns true if the underlying atomic variables used by
545545
// the queue are lock-free (they should be on most platforms).
546546
// Thread-safe.
547-
static bool is_lock_free()
547+
static constexpr bool is_lock_free()
548548
{
549549
return ConcurrentQueue::is_lock_free();
550550
}

concurrentqueue.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ class ConcurrentQueue
13141314
// Returns true if the underlying atomic variables used by
13151315
// the queue are lock-free (they should be on most platforms).
13161316
// Thread-safe.
1317-
static bool is_lock_free()
1317+
static constexpr bool is_lock_free()
13181318
{
13191319
return
13201320
details::static_is_lock_free<bool>::value == 2 &&

tests/unittests/unittests.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3643,9 +3643,9 @@ class ConcurrentQueueTests : public TestClass<ConcurrentQueueTests>
36433643

36443644
// is_lock_free()
36453645
{
3646-
bool lockFree = ConcurrentQueue<Foo, Traits>::is_lock_free();
3646+
constexpr bool lockFree = ConcurrentQueue<Foo, Traits>::is_lock_free();
36473647
#if defined(__amd64__) || defined(_M_X64) || defined(__x86_64__) || defined(_M_IX86) || defined(__i386__) || defined(_M_PPC) || defined(__powerpc__)
3648-
ASSERT_OR_FAIL(lockFree);
3648+
static_assert(lockFree, "is_lock_free should be true");
36493649
#else
36503650
(void)lockFree;
36513651
#endif

0 commit comments

Comments
 (0)