Skip to content

Commit

Permalink
Replace boost::atomic with std::atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ballo committed Jul 17, 2017
1 parent 944eb27 commit 8b20f5b
Show file tree
Hide file tree
Showing 186 changed files with 710 additions and 4,699 deletions.
7 changes: 7 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -383,6 +383,13 @@ macro(hpx_check_for_cxx11_std_array)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_atomic)
add_hpx_config_test(HPX_WITH_CXX11_ATOMIC
SOURCE cmake/tests/cxx11_std_atomic.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_chrono)
add_hpx_config_test(HPX_WITH_CXX11_CHRONO
Expand Down
3 changes: 3 additions & 0 deletions cmake/HPX_PerformCxxFeatureTests.cmake
Expand Up @@ -82,6 +82,9 @@ macro(hpx_perform_cxx_feature_tests)
hpx_check_for_cxx11_std_array(
DEFINITIONS HPX_HAVE_CXX11_STD_ARRAY)

hpx_check_for_cxx11_std_atomic(
REQUIRED "HPX needs support for C++11 std::atomic")

hpx_check_for_cxx11_std_chrono(
REQUIRED "HPX needs support for C++11 std::chrono")

Expand Down
19 changes: 0 additions & 19 deletions cmake/HPX_SetupBoost.cmake
Expand Up @@ -102,20 +102,6 @@ if(Boost_RANDOM_FOUND)
set(Boost_TMP_LIBRARIES ${Boost_TMP_LIBRARIES} ${Boost_LIBRARIES})
endif()

# If the found Boost installation is < 1.53, we need to include our packaged
# atomic library
if(Boost_VERSION LESS 105300)
set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/external/atomic")
set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} "${PROJECT_SOURCE_DIR}/external/lockfree")
else()
find_package(Boost 1.53 QUIET REQUIRED COMPONENTS atomic)
if(Boost_ATOMIC_FOUND)
hpx_info(" atomic")
endif()

set(Boost_TMP_LIBRARIES ${Boost_TMP_LIBRARIES} ${Boost_LIBRARIES})
endif()

set(Boost_LIBRARIES ${Boost_TMP_LIBRARIES})

# If we compile natively for the MIC, we need some workarounds for certain
Expand All @@ -141,11 +127,6 @@ hpx_add_config_define(HPX_HAVE_LOG_NO_TSS)
hpx_add_config_define(HPX_HAVE_LOG_NO_TS)
hpx_add_config_cond_define(BOOST_BIGINT_HAS_NATIVE_INT64)

# Disable usage of std::atomics in lockfree
if(Boost_VERSION LESS 105300)
hpx_add_config_cond_define(BOOST_NO_0X_HDR_ATOMIC)
endif()

include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
if((NOT MSVC) OR HPX_WITH_BOOST_ALL_DYNAMIC_LINK OR HPX_WITH_VCPKG)
Expand Down
22 changes: 22 additions & 0 deletions cmake/tests/cxx11_std_atomic.cpp
@@ -0,0 +1,22 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 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 <atomic>

int main()
{
std::atomic<int> at;
at.store(0);
int i = at.load();

std::memory_order mo;
mo = std::memory_order_relaxed;
mo = std::memory_order_acquire;
mo = std::memory_order_release;
mo = std::memory_order_acq_rel;
mo = std::memory_order_seq_cst;
}
Expand Up @@ -9,13 +9,12 @@
#include <hpx/hpx_init.hpp>
#include <hpx/include/performance_counters.hpp>

#include <boost/atomic.hpp>

#include <atomic>
#include <cstdint>

///////////////////////////////////////////////////////////////////////////////
// The atomic variable 'counter' ensures the thread safety of the counter.
boost::atomic<std::int64_t> counter(0);
std::atomic<std::int64_t> counter(0);

std::int64_t some_performance_data(bool reset)
{
Expand Down
5 changes: 3 additions & 2 deletions examples/quickstart/composable_guard.cpp
Expand Up @@ -4,7 +4,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <hpx/lcos/local/composable_guard.hpp>
#include <hpx/hpx_init.hpp>
#include <boost/atomic.hpp>

#include <atomic>
#include <iostream>
#include <memory>

Expand All @@ -27,7 +28,7 @@
// To use guards, call the run_guarded() method, supplying it with
// a guard or guard set, and a task to be performed.

typedef boost::atomic<int> int_atomic;
typedef std::atomic<int> int_atomic;
int_atomic i1(0), i2(0);
hpx::lcos::local::guard_set guards;
std::shared_ptr<hpx::lcos::local::guard> l1(new hpx::lcos::local::guard());
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart/fibonacci_futures_distributed.cpp
Expand Up @@ -9,13 +9,13 @@
#include <hpx/include/lcos.hpp>
#include <hpx/util/unwrapped.hpp>

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

#include <boost/atomic.hpp>
#include <boost/format.hpp>

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -24,7 +24,7 @@ std::uint64_t distribute_at = 2;
int num_repeats = 1;

///////////////////////////////////////////////////////////////////////////////
boost::atomic<std::size_t> serial_execution_count(0);
std::atomic<std::size_t> serial_execution_count(0);

std::size_t get_serial_execution_count()
{
Expand All @@ -33,7 +33,7 @@ std::size_t get_serial_execution_count()
HPX_PLAIN_ACTION(get_serial_execution_count);

///////////////////////////////////////////////////////////////////////////////
boost::atomic<std::size_t> next_locality(0);
std::atomic<std::size_t> next_locality(0);
std::vector<hpx::id_type> localities;
hpx::id_type here;

Expand Down
2 changes: 0 additions & 2 deletions examples/quickstart/quicksort.cpp
Expand Up @@ -10,8 +10,6 @@
#include <hpx/util/high_resolution_timer.hpp>
#include <hpx/include/async.hpp>

#include <boost/atomic.hpp>

#include <algorithm>
#include <cstddef>
#include <cstdint>
Expand Down
4 changes: 2 additions & 2 deletions examples/quickstart/shared_mutex.cpp
Expand Up @@ -13,10 +13,10 @@
#include <hpx/include/iostreams.hpp>
#include <hpx/util/unused.hpp>

#include <boost/atomic.hpp>
#include <boost/random.hpp>
#include <boost/thread/locks.hpp>

#include <atomic>
#include <chrono>
#include <cstdint>
#include <ctime>
Expand All @@ -32,7 +32,7 @@ using std::chrono::milliseconds;
int main()
{
std::vector<hpx::thread> threads;
boost::atomic<bool> ready(false);
std::atomic<bool> ready(false);
hpx::lcos::local::shared_mutex stm;

for (int i = 0; i < writers; ++i)
Expand Down

0 comments on commit 8b20f5b

Please sign in to comment.