branch_hints.hpp 857 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // branch hints
  2. // Copyright (C) 2007, 2008 Tim Blechmann
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_LOCKFREE_BRANCH_HINTS_HPP_INCLUDED
  8. #define BOOST_LOCKFREE_BRANCH_HINTS_HPP_INCLUDED
  9. namespace boost {
  10. namespace lockfree {
  11. namespace detail {
  12. /** \brief hint for the branch prediction */
  13. inline bool likely(bool expr)
  14. {
  15. #ifdef __GNUC__
  16. return __builtin_expect(expr, true);
  17. #else
  18. return expr;
  19. #endif
  20. }
  21. /** \brief hint for the branch prediction */
  22. inline bool unlikely(bool expr)
  23. {
  24. #ifdef __GNUC__
  25. return __builtin_expect(expr, false);
  26. #else
  27. return expr;
  28. #endif
  29. }
  30. } /* namespace detail */
  31. } /* namespace lockfree */
  32. } /* namespace boost */
  33. #endif /* BOOST_LOCKFREE_BRANCH_HINTS_HPP_INCLUDED */