Skip to content

Commit

Permalink
Require C++11 std::lock_guard and std::unique_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ballo committed Apr 12, 2016
1 parent dd1071f commit 40ed4f7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Expand Up @@ -844,12 +844,18 @@ hpx_check_for_cxx11_std_is_null_pointer(
hpx_check_for_cxx11_std_is_placeholder(
DEFINITIONS HPX_HAVE_CXX11_STD_IS_PLACEHOLDER)

hpx_check_for_cxx11_std_lock_guard(
REQUIRED "HPX needs support for C++11 std::lock_guard")

hpx_check_for_cxx11_std_reference_wrapper(
DEFINITIONS HPX_HAVE_CXX11_STD_REFERENCE_WRAPPER)

hpx_check_for_cxx11_std_to_string(
REQUIRED "HPX needs support for C++11 std::to_string")

hpx_check_for_cxx11_std_unique_lock(
REQUIRED "HPX needs support for C++11 std::unique_lock")

hpx_check_for_cxx11_std_unique_ptr(
REQUIRED "HPX needs support for C++11 std::unique_ptr")

Expand Down
40 changes: 27 additions & 13 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -280,6 +280,13 @@ macro(hpx_check_for_cxx11_explicit_variadic_templates)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_array)
add_hpx_config_test(HPX_WITH_CXX11_ARRAY
SOURCE cmake/tests/cxx11_std_array.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_chrono)
add_hpx_config_test(HPX_WITH_CXX11_CHRONO
Expand All @@ -294,6 +301,13 @@ macro(hpx_check_for_cxx11_std_cstdint)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_initializer_list)
add_hpx_config_test(HPX_WITH_CXX11_STD_INITIALIZER_LIST
SOURCE cmake/tests/cxx11_std_initializer_list.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_is_bind_expression)
add_hpx_config_test(HPX_WITH_CXX11_IS_BIND_EXPRESSION
Expand Down Expand Up @@ -322,6 +336,13 @@ macro(hpx_check_for_cxx11_std_is_placeholder)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_lock_guard)
add_hpx_config_test(HPX_WITH_CXX11_LOCK_GUARD
SOURCE cmake/tests/cxx11_std_lock_guard.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_reference_wrapper)
add_hpx_config_test(HPX_WITH_CXX11_REFERENCE_WRAPPER
Expand All @@ -337,23 +358,16 @@ macro(hpx_check_for_cxx11_std_to_string)
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_initializer_list)
add_hpx_config_test(HPX_WITH_CXX11_STD_INITIALIZER_LIST
SOURCE cmake/tests/cxx11_std_initializer_list.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_array)
add_hpx_config_test(HPX_WITH_CXX11_ARRAY
SOURCE cmake/tests/cxx11_std_array.cpp
macro(hpx_check_for_cxx11_std_type_traits)
add_hpx_config_test(HPX_WITH_CXX11_TYPE_TRAITS
SOURCE cmake/tests/cxx11_std_type_traits.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_type_traits)
add_hpx_config_test(HPX_WITH_CXX11_TYPE_TRAITS
SOURCE cmake/tests/cxx11_std_type_traits.cpp
macro(hpx_check_for_cxx11_std_unique_lock)
add_hpx_config_test(HPX_WITH_CXX11_UNIQUE_LOCK
SOURCE cmake/tests/cxx11_std_unique_lock.cpp
FILE ${ARGN})
endmacro()

Expand Down
21 changes: 21 additions & 0 deletions cmake/tests/cxx11_std_lock_guard.cpp
@@ -0,0 +1,21 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#include <mutex>

struct BasicLockable {
void lock() {}
void unlock() {}
};

int main()
{
BasicLockable basic_lockable;
std::lock_guard<BasicLockable> lk(basic_lockable);

std::lock_guard<BasicLockable> kl_adopt(basic_lockable, std::adopt_lock);
}
32 changes: 32 additions & 0 deletions cmake/tests/cxx11_std_unique_lock.cpp
@@ -0,0 +1,32 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#include <mutex>
#include <utility>

struct Lockable {
void lock() {}
bool try_lock() { return true; }
void unlock() {}
};

int main()
{
Lockable lockable;
std::unique_lock<Lockable> lk(lockable);
lk.lock();
lk.try_lock();
lk.owns_lock();
lk.unlock();
lk.release();

std::unique_lock<Lockable> mlk(std::move(lk));

std::unique_lock<Lockable> kl_adopt(lockable, std::adopt_lock);
std::unique_lock<Lockable> kl_defer(lockable, std::defer_lock);
std::unique_lock<Lockable> kl_try(lockable, std::try_to_lock);
}

0 comments on commit 40ed4f7

Please sign in to comment.