Skip to content

Commit

Permalink
Replace boost::atomic with std::atomic (were possible)
Browse files Browse the repository at this point in the history
  • Loading branch information
K-ballo committed Jul 23, 2017
1 parent 5640334 commit b80d1e2
Show file tree
Hide file tree
Showing 167 changed files with 648 additions and 733 deletions.
8 changes: 8 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -383,6 +383,14 @@ 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
LIBRARIES "-latomic"
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
26 changes: 26 additions & 0 deletions cmake/tests/cxx11_std_atomic.cpp
@@ -0,0 +1,26 @@
////////////////////////////////////////////////////////////////////////////////
// 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_flag af = ATOMIC_FLAG_INIT;
if (af.test_and_set())
af.clear();

std::atomic<int> ai;
ai.store(0);
int i = ai.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
4 changes: 2 additions & 2 deletions hpx/components/iostreams/ostream.hpp
Expand Up @@ -16,9 +16,9 @@
#include <hpx/runtime/components/client_base.hpp>
#include <hpx/util/register_locks.hpp>

#include <boost/atomic.hpp>
#include <boost/iostreams/stream.hpp>

#include <atomic>
#include <cstdint>
#include <ios>
#include <iostream>
Expand Down Expand Up @@ -168,7 +168,7 @@ namespace hpx { namespace iostreams

private:
using detail::buffer::mtx_;
boost::atomic<std::uint64_t> generational_count_;
std::atomic<std::uint64_t> generational_count_;

// Performs a lazy streaming operation.
template <typename T>
Expand Down
5 changes: 2 additions & 3 deletions hpx/compute/cuda/concurrent_executor.hpp
Expand Up @@ -17,9 +17,8 @@
#include <hpx/compute/host/block_executor.hpp>
#include <hpx/compute/host/target.hpp>

#include <boost/atomic.hpp>

#include <array>
#include <atomic>
#include <cstddef>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -196,7 +195,7 @@ namespace hpx { namespace compute { namespace cuda
private:
host_executor_type host_executor_;
std::vector<cuda_executor_type> cuda_executors_;
boost::atomic<std::size_t> current_;
std::atomic<std::size_t> current_;
};
}}}

Expand Down
2 changes: 0 additions & 2 deletions hpx/compute/detail/target_distribution_policy.hpp
Expand Up @@ -17,8 +17,6 @@
#include <utility>
#include <vector>

#include <boost/atomic.hpp>

namespace hpx { namespace compute { namespace detail
{
/// This class specifies the parameters for a simple distribution policy
Expand Down
5 changes: 2 additions & 3 deletions hpx/compute/host/block_executor.hpp
Expand Up @@ -20,9 +20,8 @@
#include <hpx/util/range.hpp>
#include <hpx/util/unwrapped.hpp>

#include <boost/atomic.hpp>

#include <algorithm>
#include <atomic>
#include <cstddef>
#include <exception>
#include <iterator>
Expand Down Expand Up @@ -239,7 +238,7 @@ namespace hpx { namespace compute { namespace host
}
}
std::vector<host::target> targets_;
boost::atomic<std::size_t> current_;
std::atomic<std::size_t> current_;
std::vector<Executor> executors_;
};
}}}
Expand Down
4 changes: 2 additions & 2 deletions hpx/lcos/dataflow.hpp
Expand Up @@ -40,10 +40,10 @@
#endif
#include <hpx/parallel/executors/execution.hpp>

#include <boost/atomic.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/ref.hpp>

#include <atomic>
#include <cstddef>
#include <exception>
#include <functional>
Expand Down Expand Up @@ -521,7 +521,7 @@ namespace hpx { namespace lcos { namespace detail
Policy policy_;
Func func_;
Futures futures_;
boost::atomic<bool> done_;
std::atomic<bool> done_;
};

///////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 7 additions & 7 deletions hpx/lcos/future_wait.hpp
Expand Up @@ -14,9 +14,9 @@
#include <hpx/traits/future_access.hpp>
#include <hpx/traits/future_traits.hpp>

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

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <utility>
Expand Down Expand Up @@ -109,7 +109,7 @@ namespace hpx { namespace lcos

template <typename F_>
wait_each(argument_type const& lazy_values, F_ && f,
boost::atomic<std::size_t>* success_counter)
std::atomic<std::size_t>* success_counter)
: lazy_values_(lazy_values),
ready_count_(0),
f_(std::forward<F>(f)),
Expand All @@ -118,7 +118,7 @@ namespace hpx { namespace lcos

template <typename F_>
wait_each(argument_type && lazy_values, F_ && f,
boost::atomic<std::size_t>* success_counter)
std::atomic<std::size_t>* success_counter)
: lazy_values_(std::move(lazy_values)),
ready_count_(0),
f_(std::forward<F>(f)),
Expand Down Expand Up @@ -185,9 +185,9 @@ namespace hpx { namespace lcos
}

std::vector<Future> lazy_values_;
boost::atomic<std::size_t> ready_count_;
std::atomic<std::size_t> ready_count_;
typename std::remove_reference<F>::type f_;
boost::atomic<std::size_t>* success_counter_;
std::atomic<std::size_t>* success_counter_;
bool goal_reached_on_calling_thread_;
};
}
Expand Down Expand Up @@ -240,7 +240,7 @@ namespace hpx { namespace lcos
std::back_inserter(lazy_values_),
detail::wait_acquire_future<Future>());

boost::atomic<std::size_t> success_counter(0);
std::atomic<std::size_t> success_counter(0);
lcos::local::futures_factory<return_type()> p(
detail::wait_each<Future, F>(std::move(lazy_values_),
std::forward<F>(f), &success_counter));
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace hpx { namespace lcos
std::back_inserter(lazy_values_),
detail::wait_acquire_future<Future>());

boost::atomic<std::size_t> success_counter(0);
std::atomic<std::size_t> success_counter(0);
lcos::local::futures_factory<return_type()> p(
detail::wait_each<Future, F>(std::move(lazy_values_),
std::forward<F>(f), &success_counter));
Expand Down
5 changes: 2 additions & 3 deletions hpx/lcos/local/composable_guard.hpp
Expand Up @@ -87,8 +87,7 @@
#include <hpx/util_fwd.hpp>
#include <hpx/lcos/local/packaged_task.hpp>

#include <boost/atomic.hpp>

#include <atomic>
#include <cstddef>
#include <memory>
#include <utility>
Expand Down Expand Up @@ -125,7 +124,7 @@ namespace hpx { namespace lcos { namespace local

struct guard_task;

typedef boost::atomic<guard_task*> guard_atomic;
typedef std::atomic<guard_task*> guard_atomic;

HPX_API_EXPORT void free(guard_task* task);

Expand Down
15 changes: 7 additions & 8 deletions hpx/lcos/local/event.hpp
Expand Up @@ -12,8 +12,7 @@
#include <hpx/lcos/local/spinlock.hpp>
#include <hpx/util/assert.hpp>

#include <boost/atomic.hpp>

#include <atomic>
#include <mutex>
#include <utility>

Expand All @@ -37,13 +36,13 @@ namespace hpx { namespace lcos { namespace local
/// \brief Check if the event has occurred.
bool occurred()
{
return event_.load(boost::memory_order_acquire);
return event_.load(std::memory_order_acquire);
}

/// \brief Wait for the event to occur.
void wait()
{
if (event_.load(boost::memory_order_acquire))
if (event_.load(std::memory_order_acquire))
return;

std::unique_lock<mutex_type> l(mtx_);
Expand All @@ -53,7 +52,7 @@ namespace hpx { namespace lcos { namespace local
/// \brief Release all threads waiting on this semaphore.
void set()
{
event_.store(true, boost::memory_order_release);
event_.store(true, std::memory_order_release);

std::unique_lock<mutex_type> l(mtx_);
set_locked(std::move(l));
Expand All @@ -62,15 +61,15 @@ namespace hpx { namespace lcos { namespace local
/// \brief Reset the event
void reset()
{
event_.store(false, boost::memory_order_release);
event_.store(false, std::memory_order_release);
}

private:
void wait_locked(std::unique_lock<mutex_type>& l)
{
HPX_ASSERT(l.owns_lock());

while (!event_.load(boost::memory_order_acquire))
while (!event_.load(std::memory_order_acquire))
{
cond_.wait(l, "event::wait_locked");
}
Expand All @@ -87,7 +86,7 @@ namespace hpx { namespace lcos { namespace local
mutex_type mtx_; ///< This mutex protects the queue.
local::detail::condition_variable cond_;

boost::atomic<bool> event_;
std::atomic<bool> event_;
};
}}}

Expand Down

0 comments on commit b80d1e2

Please sign in to comment.