fls.qbk 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. [/
  2. (C) Copyright 2007-8 Anthony Williams.
  3. (C) Copyright 2013 Oliver Kowalke.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt).
  7. ]
  8. [section:fls Fiber local storage]
  9. [heading Synopsis]
  10. Fiber local storage allows a separate instance of a given data item for
  11. each fiber.
  12. [heading Cleanup at fiber exit]
  13. When a fiber exits, the objects associated with each __fsp__ instance are
  14. destroyed. By default, the object pointed to by a pointer `p` is destroyed by
  15. invoking `delete p`, but this can be overridden for a specific instance of
  16. __fsp__ by providing a cleanup routine `func` to the constructor. In this case, the
  17. object is destroyed by invoking `func(p)`. The cleanup functions are called in an unspecified
  18. order.
  19. [class_heading fiber_specific_ptr]
  20. #include <boost/fiber/fss.hpp>
  21. namespace boost {
  22. namespace fibers {
  23. template< typename T >
  24. class fiber_specific_ptr {
  25. public:
  26. typedef T element_type;
  27. fiber_specific_ptr();
  28. explicit fiber_specific_ptr( void(*fn)(T*) );
  29. ~fiber_specific_ptr();
  30. fiber_specific_ptr( fiber_specific_ptr const&) = delete;
  31. fiber_specific_ptr & operator=( fiber_specific_ptr const&) = delete;
  32. T * get() const noexcept;
  33. T * operator->() const noexcept;
  34. T & operator*() const noexcept;
  35. T * release();
  36. void reset( T *);
  37. };
  38. }}
  39. [heading Constructor]
  40. fiber_specific_ptr();
  41. explicit fiber_specific_ptr( void(*fn)(T*) );
  42. [variablelist
  43. [[Requires:] [`delete this->get()` is well-formed; `fn(this->get())` does not
  44. throw]]
  45. [[Effects:] [Construct a __fsp__ object for storing a pointer to an object of
  46. type `T` specific to each fiber. When `reset()` is called, or the
  47. fiber exits, __fsp__ calls `fn(this->get())`. If the no-arguments constructor
  48. is used, the default `delete`-based cleanup function
  49. will be used to destroy the fiber-local objects.]]
  50. [[Throws:] [__fiber_error__ if an error occurs.]]
  51. ]
  52. [heading Destructor]
  53. ~fiber_specific_ptr();
  54. [variablelist
  55. [[Requires:] [All the fiber specific instances associated to this __fsp__
  56. (except maybe the one associated to this fiber) must be nullptr.]]
  57. [[Effects:] [Calls `this->reset()` to clean up the associated value for the
  58. current fiber, and destroys `*this`.]]
  59. [[Remarks:] [The requirement is an implementation restriction. If the
  60. destructor promised to delete instances for all fibers, the implementation
  61. would be forced to maintain a list of all the fibers having an associated
  62. specific ptr, which is against the goal of fiber specific data. In general, a
  63. __fsp__ should outlive the fibers that use it.]]
  64. ]
  65. [note Care needs to be taken to ensure that any fibers still running after an
  66. instance of __fsp__ has been destroyed do not call any member functions on that
  67. instance.]
  68. [member_heading fiber_specific_ptr..get]
  69. T * get() const noexcept;
  70. [variablelist
  71. [[Returns:] [The pointer associated with the current fiber.]]
  72. [[Throws:] [Nothing.]]
  73. ]
  74. [note The initial value associated with an instance of __fsp__ is `nullptr` for
  75. each fiber.]
  76. [operator_heading fiber_specific_ptr..operator_arrow..operator->]
  77. T * operator->() const noexcept;
  78. [variablelist
  79. [[Requires:] [`this->get()` is not `nullptr`.]]
  80. [[Returns:] [`this->get()`]]
  81. [[Throws:] [Nothing.]]
  82. ]
  83. [operator_heading fiber_specific_ptr..operator_star..operator*]
  84. T & operator*() const noexcept;
  85. [variablelist
  86. [[Requires:] [`this->get()` is not `nullptr`.]]
  87. [[Returns:] [`*(this->get())`]]
  88. [[Throws:] [Nothing.]]
  89. ]
  90. [member_heading fiber_specific_ptr..release]
  91. T * release();
  92. [variablelist
  93. [[Effects:] [Return `this->get()` and store `nullptr` as the pointer associated
  94. with the current fiber without invoking the cleanup function.]]
  95. [[Postcondition:] [`this->get()==nullptr`]]
  96. [[Throws:] [Nothing.]]
  97. ]
  98. [member_heading fiber_specific_ptr..reset]
  99. void reset( T * new_value);
  100. [variablelist
  101. [[Effects:] [If `this->get()!=new_value` and `this->get()` is not `nullptr`,
  102. invoke `delete this->get()` or `fn(this->get())` as appropriate. Store
  103. `new_value` as the pointer associated with the current fiber.]]
  104. [[Postcondition:] [`this->get()==new_value`]]
  105. [[Throws:] [Exception raised during cleanup of previous value.]]
  106. ]
  107. [endsect]