Skip to content

Commit 3655d9e

Browse files
Use standard std::shared_lock for C++14 (#1651)
While the `std::shared_mutex` is C++17, the lock implementation was added in C++14 Relates-To: MINOR Signed-off-by: Andrey Kashcheev <[email protected]>
1 parent 8d13756 commit 3655d9e

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

olp-cpp-sdk-core/include/olp/core/porting/shared_mutex.h

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,24 @@
3434
#endif
3535

3636
#ifndef THROW_OR_ABORT
37-
# if __cpp_exceptions
38-
# define THROW_OR_ABORT(exception) (throw (exception))
39-
# else
40-
# include <cstdlib>
41-
# define THROW_OR_ABORT(exception) \
42-
do { \
43-
(void)exception; \
44-
std::abort(); \
45-
} while (0)
46-
# endif
37+
#if __cpp_exceptions
38+
#define THROW_OR_ABORT(exception) (throw(exception))
39+
#else
40+
#include <cstdlib>
41+
#define THROW_OR_ABORT(exception) \
42+
do { \
43+
(void)exception; \
44+
std::abort(); \
45+
} while (0)
46+
#endif
4747
#endif
4848

4949
namespace std {
5050
namespace detail {
5151

5252
// C++11 compatible std::exchange
53-
template<class T, class U = T>
54-
T
55-
exchange(T& obj, U&& new_value)
56-
{
53+
template <class T, class U = T>
54+
T exchange(T& obj, U&& new_value) {
5755
T old_value = std::move(obj);
5856
obj = std::forward<U>(new_value);
5957
return old_value;
@@ -341,6 +339,15 @@ class shared_mutex {
341339
#endif
342340
};
343341

342+
} // namespace std
343+
344+
// `std::shared_lock` is available since C++14
345+
#if ((__cplusplus >= 201402L) || (defined(_MSC_VER) && _MSC_VER >= 1900))
346+
#include <shared_mutex>
347+
#else
348+
349+
namespace std {
350+
344351
template <typename Mutex>
345352
/**
346353
* @brief A shared mutex wrapper that supports timed lock operations
@@ -556,6 +563,7 @@ void swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept {
556563
}
557564

558565
} // namespace std
566+
#endif
559567

560568
#if defined(HAVE_PTHREAD_RWLOCK)
561569
#undef HAVE_PTHREAD_RWLOCK

0 commit comments

Comments
 (0)