policies.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // boost lockfree
  2. //
  3. // Copyright (C) 2011 Tim Blechmann
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_LOCKFREE_POLICIES_HPP_INCLUDED
  9. #define BOOST_LOCKFREE_POLICIES_HPP_INCLUDED
  10. #include <boost/config.hpp>
  11. #ifdef BOOST_HAS_PRAGMA_ONCE
  12. # pragma once
  13. #endif
  14. #include <boost/parameter/template_keyword.hpp>
  15. #include <type_traits>
  16. namespace boost { namespace lockfree {
  17. #ifndef BOOST_DOXYGEN_INVOKED
  18. namespace tag {
  19. struct allocator;
  20. struct fixed_sized;
  21. struct capacity;
  22. struct allow_multiple_reads;
  23. } // namespace tag
  24. template < bool IsFixedSized >
  25. struct fixed_sized : boost::parameter::template_keyword< tag::fixed_sized, std::integral_constant< bool, IsFixedSized > >
  26. {};
  27. template < size_t Size >
  28. struct capacity : boost::parameter::template_keyword< tag::capacity, std::integral_constant< size_t, Size > >
  29. {};
  30. template < class Alloc >
  31. struct allocator : boost::parameter::template_keyword< tag::allocator, Alloc >
  32. {};
  33. template < bool AllowMultipleReads >
  34. struct allow_multiple_reads :
  35. boost::parameter::template_keyword< tag::allow_multiple_reads, std::integral_constant< bool, AllowMultipleReads > >
  36. {};
  37. #else
  38. /** Configures a data structure as \b fixed-sized.
  39. *
  40. * The internal nodes are stored inside an array and they are addressed by array indexing. This limits the possible
  41. * size of the queue to the number of elements that can be addressed by the index type (usually 2**16-2), but on
  42. * platforms that lack double-width compare-and-exchange instructions, this is the best way to achieve lock-freedom.
  43. * This implies that a data structure is bounded.
  44. * */
  45. template < bool IsFixedSized >
  46. struct fixed_sized;
  47. /** Sets the \b capacity of a data structure at compile-time.
  48. *
  49. * This implies that a data structure is bounded and fixed-sized.
  50. * */
  51. template < size_t Size >
  52. struct capacity;
  53. /** Defines the \b allocator type of a data structure.
  54. * */
  55. template < class Alloc >
  56. struct allocator;
  57. /** Configures the spsc_value to consume the value multiple times
  58. *
  59. * Caveats:
  60. * * one cannot move the value out
  61. * */
  62. template < bool AllowMultipleReads >
  63. struct allow_multiple_reads;
  64. #endif
  65. }} // namespace boost::lockfree
  66. #endif /* BOOST_LOCKFREE_POLICIES_HPP_INCLUDED */