Skip to content

Commit

Permalink
Cleanup header includes.
Browse files Browse the repository at this point in the history
1. Make inclusion of boost/bind/bind.hpp conditional in some cases, when the
   code actually conditionally uses boost::bind. Reduces compile-time overhead
   and fixes #307.

2. Remove some unnecessary uses of boost::ref. This allows to avoid including
   boost/core/ref.hpp in a few places, and avoids the associated template
   instantiation overhead in others.

3. Replace deprecated header includes with the more recent alternatives. For
   example: boost/detail/lightweight_test.hpp -> boost/core/lightweight_test.hpp,
   boost/ref.hpp -> boost/core/ref.hpp.

4. Replace some blanket includes with the more fine-grained ones. For example,
   boost/utility.hpp, boost/atomic.hpp. This reduces compile time overhead.

5. Add some missing includes, for example, boost/core/ref.hpp and
   boost/type_traits/is_same.hpp.

6. Replace uses of std::is_same with boost::is_same (with the corresponding
   included header) since the standard type_traits header presence and validity
   is not tested by the code. Using boost::is_same makes the code more portable.
  • Loading branch information
Lastique committed Apr 4, 2020
1 parent c13beec commit ee609e8
Show file tree
Hide file tree
Showing 362 changed files with 472 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//////////////////////////////////////////////////////////////////////////////

#include <boost/bind/bind.hpp>
#include <boost/core/ref.hpp>

#include <boost/thread/detail/config.hpp>
#include <boost/thread/condition_variable.hpp>
Expand Down Expand Up @@ -187,7 +188,7 @@ namespace detail
template <class ValueType, class Queue>
bool sync_deque_base<ValueType, Queue>::wait_until_not_empty_or_closed(unique_lock<mutex>& lk)
{
cond_.wait(lk, boost::bind(&sync_deque_base<ValueType, Queue>::not_empty_or_closed, boost::ref(*this), boost::ref(lk)));
cond_.wait(lk, boost::bind(&sync_deque_base<ValueType, Queue>::not_empty_or_closed, this, boost::ref(lk)));
if (! empty(lk)) return false; // success
return true; // closed
}
Expand All @@ -196,7 +197,7 @@ namespace detail
template <class WClock, class Duration>
queue_op_status sync_deque_base<ValueType, Queue>::wait_until_not_empty_or_closed_until(unique_lock<mutex>& lk, chrono::time_point<WClock,Duration> const&tp)
{
if (! cond_.wait_until(lk, tp, boost::bind(&sync_deque_base<ValueType, Queue>::not_empty_or_closed, boost::ref(*this), boost::ref(lk))))
if (! cond_.wait_until(lk, tp, boost::bind(&sync_deque_base<ValueType, Queue>::not_empty_or_closed, this, boost::ref(lk))))
return queue_op_status::timeout;
if (! empty(lk)) return queue_op_status::success;
return queue_op_status::closed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//////////////////////////////////////////////////////////////////////////////

#include <boost/bind/bind.hpp>
#include <boost/core/ref.hpp>

#include <boost/thread/detail/config.hpp>
#include <boost/thread/condition_variable.hpp>
Expand Down Expand Up @@ -187,7 +188,7 @@ namespace detail
template <class ValueType, class Queue>
bool sync_queue_base<ValueType, Queue>::wait_until_not_empty_or_closed(unique_lock<mutex>& lk)
{
cond_.wait(lk, boost::bind(&sync_queue_base<ValueType, Queue>::not_empty_or_closed, boost::ref(*this), boost::ref(lk)));
cond_.wait(lk, boost::bind(&sync_queue_base<ValueType, Queue>::not_empty_or_closed, this, boost::ref(lk)));
if (! empty(lk)) return false; // success
return true; // closed
}
Expand All @@ -196,7 +197,7 @@ namespace detail
template <class WClock, class Duration>
queue_op_status sync_queue_base<ValueType, Queue>::wait_until_not_empty_or_closed_until(unique_lock<mutex>& lk, chrono::time_point<WClock,Duration> const&tp)
{
if (! cond_.wait_until(lk, tp, boost::bind(&sync_queue_base<ValueType, Queue>::not_empty_or_closed, boost::ref(*this), boost::ref(lk))))
if (! cond_.wait_until(lk, tp, boost::bind(&sync_queue_base<ValueType, Queue>::not_empty_or_closed, this, boost::ref(lk))))
return queue_op_status::timeout;
if (! empty(lk)) return queue_op_status::success;
return queue_op_status::closed;
Expand Down
3 changes: 2 additions & 1 deletion include/boost/thread/detail/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <algorithm>
#include <boost/core/ref.hpp>
#include <boost/cstdint.hpp>
#include <boost/bind/bind.hpp>
#include <stdlib.h>
#include <memory>
#include <boost/core/enable_if.hpp>
Expand All @@ -47,6 +46,8 @@

#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#include <tuple>
#else
#include <boost/bind/bind.hpp>
#endif
#include <boost/config/abi_prefix.hpp>

Expand Down
10 changes: 5 additions & 5 deletions include/boost/thread/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ namespace boost
is_deferred_=false;
execute(lk);
}
waiters.wait(lk, boost::bind(&shared_state_base::is_done, boost::ref(*this)));
waiters.wait(lk, boost::bind(&shared_state_base::is_done, this));
if(rethrow && exception)
{
boost::rethrow_exception(exception);
Expand All @@ -420,7 +420,7 @@ namespace boost
return false;

do_callback(lock);
return waiters.timed_wait(lock, rel_time, boost::bind(&shared_state_base::is_done, boost::ref(*this)));
return waiters.timed_wait(lock, rel_time, boost::bind(&shared_state_base::is_done, this));
}

bool timed_wait_until(boost::system_time const& target_time)
Expand All @@ -430,7 +430,7 @@ namespace boost
return false;

do_callback(lock);
return waiters.timed_wait(lock, target_time, boost::bind(&shared_state_base::is_done, boost::ref(*this)));
return waiters.timed_wait(lock, target_time, boost::bind(&shared_state_base::is_done, this));
}
#endif
#ifdef BOOST_THREAD_USES_CHRONO
Expand All @@ -443,7 +443,7 @@ namespace boost
if (is_deferred_)
return future_status::deferred;
do_callback(lock);
if(!waiters.wait_until(lock, abs_time, boost::bind(&shared_state_base::is_done, boost::ref(*this))))
if(!waiters.wait_until(lock, abs_time, boost::bind(&shared_state_base::is_done, this)))
{
return future_status::timeout;
}
Expand Down Expand Up @@ -940,7 +940,7 @@ namespace boost
join();
#elif defined BOOST_THREAD_ASYNC_FUTURE_WAITS
unique_lock<boost::mutex> lk(this->mutex);
this->waiters.wait(lk, boost::bind(&shared_state_base::is_done, boost::ref(*this)));
this->waiters.wait(lk, boost::bind(&shared_state_base::is_done, this));
#endif
}

Expand Down
9 changes: 6 additions & 3 deletions include/boost/thread/pthread/once.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
#include <boost/thread/detail/delete.hpp>
#include <boost/core/no_exceptions_support.hpp>

#include <boost/bind/bind.hpp>
#include <boost/assert.hpp>
#include <boost/config/abi_prefix.hpp>

#include <boost/cstdint.hpp>
#include <pthread.h>
#include <csignal>

#if !defined(BOOST_THREAD_PROVIDES_INVOKE) && !defined(BOOST_THREAD_PROVIDES_INVOKE_RET)
#include <boost/bind/bind.hpp>
#endif

#include <boost/config/abi_prefix.hpp>

namespace boost
{

Expand Down
6 changes: 5 additions & 1 deletion include/boost/thread/pthread/once_atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
#include <boost/thread/detail/move.hpp>
#include <boost/thread/detail/invoke.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <boost/atomic/capabilities.hpp>
#include <boost/atomic/atomic.hpp>

#if !defined(BOOST_THREAD_PROVIDES_INVOKE) && !defined(BOOST_THREAD_PROVIDES_INVOKE_RET)
#include <boost/bind/bind.hpp>
#include <boost/atomic.hpp>
#endif

#include <boost/config/abi_prefix.hpp>

Expand Down
32 changes: 16 additions & 16 deletions include/boost/thread/pthread/shared_mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
shared_cond.wait(lk, boost::bind(&state_data::can_lock_shared, boost::ref(state)));
shared_cond.wait(lk, boost::bind(&state_data::can_lock_shared, &state));
state.lock_shared();
}

Expand All @@ -194,7 +194,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock_shared, boost::ref(state))))
if(!shared_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock_shared, &state)))
{
return false;
}
Expand All @@ -209,7 +209,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock_shared, boost::ref(state))))
if(!shared_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock_shared, &state)))
{
return false;
}
Expand All @@ -230,7 +230,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_shared, boost::ref(state))))
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_shared, &state)))
{
return false;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.exclusive_waiting_blocked=true;
exclusive_cond.wait(lk, boost::bind(&state_data::can_lock, boost::ref(state)));
exclusive_cond.wait(lk, boost::bind(&state_data::can_lock, &state));
state.exclusive=true;
}

Expand All @@ -282,7 +282,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.exclusive_waiting_blocked=true;
if(!exclusive_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock, boost::ref(state))))
if(!exclusive_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock, &state)))
{
state.exclusive_waiting_blocked=false;
release_waiters();
Expand All @@ -300,7 +300,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.exclusive_waiting_blocked=true;
if(!exclusive_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock, boost::ref(state))))
if(!exclusive_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock, &state)))
{
state.exclusive_waiting_blocked=false;
release_waiters();
Expand All @@ -324,7 +324,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.exclusive_waiting_blocked=true;
if(!exclusive_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock, boost::ref(state))))
if(!exclusive_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock, &state)))
{
state.exclusive_waiting_blocked=false;
release_waiters();
Expand Down Expand Up @@ -362,7 +362,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
shared_cond.wait(lk, boost::bind(&state_data::can_lock_upgrade, boost::ref(state)));
shared_cond.wait(lk, boost::bind(&state_data::can_lock_upgrade, &state));
state.lock_shared();
state.upgrade=true;
}
Expand All @@ -374,7 +374,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock_upgrade, boost::ref(state))))
if(!shared_cond.timed_wait(lk, timeout, boost::bind(&state_data::can_lock_upgrade, &state)))
{
return false;
}
Expand All @@ -390,7 +390,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock_upgrade, boost::ref(state))))
if(!shared_cond.timed_wait(lk, relative_time, boost::bind(&state_data::can_lock_upgrade, &state)))
{
return false;
}
Expand All @@ -412,7 +412,7 @@ namespace boost
boost::this_thread::disable_interruption do_not_disturb;
#endif
boost::unique_lock<boost::mutex> lk(state_change);
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_upgrade, boost::ref(state))))
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_upgrade, &state)))
{
return false;
}
Expand Down Expand Up @@ -457,7 +457,7 @@ namespace boost
boost::unique_lock<boost::mutex> lk(state_change);
state.assert_lock_upgraded();
state.unlock_shared();
upgrade_cond.wait(lk, boost::bind(&state_data::no_shared, boost::ref(state)));
upgrade_cond.wait(lk, boost::bind(&state_data::no_shared, &state));
state.upgrade=false;
state.exclusive=true;
state.assert_locked();
Expand Down Expand Up @@ -511,7 +511,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.assert_lock_upgraded();
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::one_shared, boost::ref(state))))
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::one_shared, &state)))
{
return false;
}
Expand Down Expand Up @@ -569,7 +569,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.assert_lock_shared();
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::one_shared, boost::ref(state))))
if(!shared_cond.wait_until(lk, abs_time, boost::bind(&state_data::one_shared, &state)))
{
return false;
}
Expand Down Expand Up @@ -623,7 +623,7 @@ namespace boost
#endif
boost::unique_lock<boost::mutex> lk(state_change);
state.assert_lock_shared();
if(!exclusive_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_upgrade, boost::ref(state))))
if(!exclusive_cond.wait_until(lk, abs_time, boost::bind(&state_data::can_lock_upgrade, &state)))
{
return false;
}
Expand Down
Loading

0 comments on commit ee609e8

Please sign in to comment.