diff --git a/include/ntl/resource b/include/ntl/resource index 9985dfa..17a4122 100644 --- a/include/ntl/resource +++ b/include/ntl/resource @@ -137,7 +137,7 @@ public: unique_lock() noexcept : lockable_(nullptr), owns_(false) {} - _NODISCARD_CTOR unique_lock(lock_type &lockable, std::adopt_lock_t) + unique_lock(lock_type &lockable, std::adopt_lock_t) : std::unique_lock(lockable, std::adopt_lock), lockable_(nullptr), owns_(false) { } // construct and assume already locked @@ -146,11 +146,11 @@ public: : std::unique_lock(lockable, std::defer_lock), lockable_(nullptr), owns_(false) {} // construct but don't lock - _NODISCARD_CTOR unique_lock(lock_type &lockable, std::try_to_lock_t) + unique_lock(lock_type &lockable, std::try_to_lock_t) : std::unique_lock(lockable, std::try_to_lock), lockable_(nullptr), owns_(false) {} // construct and try to lock - _NODISCARD_CTOR unique_lock(lock_type &lockable, adopt_critical_region_t) + unique_lock(lock_type &lockable, adopt_critical_region_t) : std::unique_lock(lockable, std::defer_lock), lockable_(std::addressof(lockable)), owns_(false) { lockable.lock_no_critical_region(); @@ -206,7 +206,7 @@ public: shared_lock() noexcept : lockable_(nullptr), owns_(false) {} - _NODISCARD_CTOR explicit shared_lock(lock_type &lockable) + explicit shared_lock(lock_type &lockable) : lockable_(_STD addressof(lockable)), owns_(true) { // construct with mutex and lock shared lockable.lock_shared(); @@ -217,24 +217,24 @@ public: lockable_(_STD addressof(lockable)), owns_(false) { } // construct with unlocked mutex - _NODISCARD_CTOR shared_lock(lock_type &lockable, std::try_to_lock_t) + shared_lock(lock_type &lockable, std::try_to_lock_t) : std::shared_lock(lockable, std::try_to_lock), lockable_(_STD addressof(lockable)), owns_(lockable.try_lock_shared()) { } // construct with mutex and try to lock shared - _NODISCARD_CTOR shared_lock(lock_type &lockable, std::adopt_lock_t) + shared_lock(lock_type &lockable, std::adopt_lock_t) : std::shared_lock(lockable, std::adopt_lock), lockable_(_STD addressof(lockable)), owns_(true) { } // construct with mutex and adopt ownership - _NODISCARD_CTOR shared_lock(lock_type &lockable, adopt_critical_region_t) + shared_lock(lock_type &lockable, adopt_critical_region_t) : std::shared_lock(lockable, std::defer_lock), lockable_(std::addressof(lockable)), owns_(false) { lockable.lock_shared_no_critical_region(); owns_ = true; } // construct but don't enter critical region - _NODISCARD_CTOR shared_lock(unique_lock &lock) + shared_lock(unique_lock &lock) : std::shared_lock(*lock.mutex(), std::defer_lock), lockable_(lock.mutex()), owns_(false) { lock.mutex()->convert_to_shared(); diff --git a/include/ntl/spin_lock b/include/ntl/spin_lock index 18f9965..1bfb889 100644 --- a/include/ntl/spin_lock +++ b/include/ntl/spin_lock @@ -71,14 +71,14 @@ public: unique_lock() noexcept : lockable_(nullptr), owns_(false) {} - _NODISCARD_CTOR explicit unique_lock(spin_lock &lockable) + explicit unique_lock(lock_type &lockable) : lockable_(_STD addressof(lockable)), owns_(false) { // construct and lock lockable_->lock(); owns_ = true; } - _NODISCARD_CTOR unique_lock(lock_type &lockable, std::adopt_lock_t) + unique_lock(lock_type &lockable, std::adopt_lock_t) : std::unique_lock(lockable, std::adopt_lock), lockable_(nullptr), owns_(false) { } // construct and assume already locked @@ -87,11 +87,11 @@ public: : std::unique_lock(lockable, std::defer_lock), lockable_(nullptr), owns_(false) {} // construct but don't lock - _NODISCARD_CTOR unique_lock(lock_type &lockable, std::try_to_lock_t) + unique_lock(lock_type &lockable, std::try_to_lock_t) : std::unique_lock(lockable, std::try_to_lock), lockable_(nullptr), owns_(false) {} // construct and try to lock - _NODISCARD_CTOR unique_lock(lock_type &lockable, at_dpc_level_lock_t) + unique_lock(lock_type &lockable, at_dpc_level_lock_t) : std::unique_lock(lockable, std::defer_lock), lockable_(std::addressof(lockable)), owns_(false) { lockable.lock_at_dpc_level(); diff --git a/test/common/rpc.hpp b/test/common/rpc.hpp index 9e6d266..bfdb9e2 100644 --- a/test/common/rpc.hpp +++ b/test/common/rpc.hpp @@ -40,7 +40,11 @@ NTL_ADD_CALLBACK_4(test_rpc, int, test_sum, int, a, int, b, int, c, int, d, NTL_ADD_CALLBACK_5(test_rpc, int, test_sum, int, a, int, b, int, c, int, d, int, e, { return a + b + c + d + e; }) +#if _MSC_VER <= 1916 +NTL_ADD_CALLBACK_0(test_rpc, int, test_void, { return 0; }) +#else NTL_ADD_CALLBACK_0(test_rpc, void, test_void, { return; }) +#endif NTL_ADD_CALLBACK_1(test_rpc, bool, test_vec, const std::vector &, vec, { return vec.empty(); }) @@ -75,4 +79,4 @@ NTL_ADD_CALLBACK_2(test_rpc, point, test_point_class, const point &, p1, const point &, p2, { return p1.get_x() > p2.get_x() ? p1 : p2; }) -NTL_RPC_END(test_rpc) \ No newline at end of file +NTL_RPC_END(test_rpc) diff --git a/test/driver/src/ntl.cpp b/test/driver/src/ntl.cpp index fa6bbff..77028bd 100644 --- a/test/driver/src/ntl.cpp +++ b/test/driver/src/ntl.cpp @@ -87,11 +87,11 @@ bool ntl_spin_lock_test() { if (!lock2.test()) return false; - std::unique_lock lk(lock); + std::unique_lock lk(lock); if (!lk.owns_lock()) return false; - std::unique_lock lk2(lock, std::try_to_lock); + std::unique_lock lk2(lock, std::try_to_lock); if (lk2.owns_lock()) return false; @@ -117,7 +117,7 @@ bool ntl_spin_lock_test() { bool ntl_resource_test() { ntl::resource res; { - std::shared_lock lk(res); + std::shared_lock lk(res); if (!lk.owns_lock()) return false; if (!res.locked()) @@ -125,7 +125,7 @@ bool ntl_resource_test() { if (!res.locked_shared()) return false; - std::unique_lock lk2(res, std::try_to_lock); + std::unique_lock lk2(res, std::try_to_lock); if (lk2.owns_lock()) return false; if (res.locked_exclusive()) @@ -139,7 +139,7 @@ bool ntl_resource_test() { return false; ntl::resource res2; - std::unique_lock lk3(res); + std::unique_lock lk3(res); if (!lk3.owns_lock()) return false; if (!res.locked()) @@ -147,7 +147,7 @@ bool ntl_resource_test() { if (!res.locked_exclusive()) return false; - std::shared_lock lk4(res, std::try_to_lock); + std::shared_lock lk4(res, std::try_to_lock); if (!lk4.owns_lock()) return false; if (res.locked_shared())