Skip to content

Commit

Permalink
Fix code (for VS2017, VS2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoskrnl7 committed Aug 24, 2022
1 parent 91b57fa commit 64236c2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
16 changes: 8 additions & 8 deletions include/ntl/resource
Original file line number Diff line number Diff line change
Expand Up @@ -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<lock_type>(lockable, std::adopt_lock),
lockable_(nullptr), owns_(false) {
} // construct and assume already locked
Expand All @@ -146,11 +146,11 @@ public:
: std::unique_lock<lock_type>(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<lock_type>(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<lock_type>(lockable, std::defer_lock),
lockable_(std::addressof(lockable)), owns_(false) {
lockable.lock_no_critical_region();
Expand Down Expand Up @@ -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();
Expand All @@ -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<lock_type>(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<lock_type>(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<lock_type>(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_type> &lock)
shared_lock(unique_lock<lock_type> &lock)
: std::shared_lock<lock_type>(*lock.mutex(), std::defer_lock),
lockable_(lock.mutex()), owns_(false) {
lock.mutex()->convert_to_shared();
Expand Down
8 changes: 4 additions & 4 deletions include/ntl/spin_lock
Original file line number Diff line number Diff line change
Expand Up @@ -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<lock_type>(lockable, std::adopt_lock),
lockable_(nullptr), owns_(false) {
} // construct and assume already locked
Expand All @@ -87,11 +87,11 @@ public:
: std::unique_lock<lock_type>(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<lock_type>(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<lock_type>(lockable, std::defer_lock),
lockable_(std::addressof(lockable)), owns_(false) {
lockable.lock_at_dpc_level();
Expand Down
6 changes: 5 additions & 1 deletion test/common/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &, vec,
{ return vec.empty(); })
Expand Down Expand Up @@ -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)
NTL_RPC_END(test_rpc)
12 changes: 6 additions & 6 deletions test/driver/src/ntl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ bool ntl_spin_lock_test() {
if (!lock2.test())
return false;

std::unique_lock lk(lock);
std::unique_lock<ntl::spin_lock> lk(lock);
if (!lk.owns_lock())
return false;

std::unique_lock lk2(lock, std::try_to_lock);
std::unique_lock<ntl::spin_lock> lk2(lock, std::try_to_lock);
if (lk2.owns_lock())
return false;

Expand All @@ -117,15 +117,15 @@ bool ntl_spin_lock_test() {
bool ntl_resource_test() {
ntl::resource res;
{
std::shared_lock lk(res);
std::shared_lock<ntl::resource> lk(res);
if (!lk.owns_lock())
return false;
if (!res.locked())
return false;
if (!res.locked_shared())
return false;

std::unique_lock lk2(res, std::try_to_lock);
std::unique_lock<ntl::resource> lk2(res, std::try_to_lock);
if (lk2.owns_lock())
return false;
if (res.locked_exclusive())
Expand All @@ -139,15 +139,15 @@ bool ntl_resource_test() {
return false;

ntl::resource res2;
std::unique_lock lk3(res);
std::unique_lock<ntl::resource> lk3(res);
if (!lk3.owns_lock())
return false;
if (!res.locked())
return false;
if (!res.locked_exclusive())
return false;

std::shared_lock lk4(res, std::try_to_lock);
std::shared_lock<ntl::resource> lk4(res, std::try_to_lock);
if (!lk4.owns_lock())
return false;
if (res.locked_shared())
Expand Down

0 comments on commit 64236c2

Please sign in to comment.