preallocated_stack_allocator.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright Oliver Kowalke 2009.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_FIBER_PREALLOCATED_STACK_ALLOCATOR_H
  6. #define BOOST_FIBER_PREALLOCATED_STACK_ALLOCATOR_H
  7. #include <cstddef>
  8. #include <cstdlib>
  9. #include <stdexcept>
  10. #include <vector>
  11. #include <boost/assert.hpp>
  12. #include <boost/config.hpp>
  13. #include <boost/coroutine/standard_stack_allocator.hpp>
  14. #include <boost/coroutine/stack_context.hpp>
  15. #include <boost/shared_ptr.hpp>
  16. #include <boost/utility.hpp>
  17. #ifdef BOOST_HAS_ABI_HEADERS
  18. # include BOOST_ABI_PREFIX
  19. #endif
  20. class preallocated_stack_allocator
  21. {
  22. private:
  23. boost::coroutines::stack_context stack_ctx_;
  24. public:
  25. preallocated_stack_allocator() :
  26. stack_ctx_()
  27. {
  28. boost::coroutines::standard_stack_allocator allocator;
  29. allocator.allocate(
  30. stack_ctx_,
  31. boost::coroutines::standard_stack_allocator::traits_type::default_size() );
  32. }
  33. void allocate( boost::coroutines::stack_context & ctx, std::size_t size)
  34. {
  35. ctx.sp = stack_ctx_.sp;
  36. ctx.size = stack_ctx_.size;
  37. }
  38. void deallocate( boost::coroutines::stack_context & ctx)
  39. {
  40. }
  41. };
  42. #ifdef BOOST_HAS_ABI_HEADERS
  43. # include BOOST_ABI_SUFFIX
  44. #endif
  45. #endif // BOOST_FIBER_PREALLOCATED_STACK_ALLOCATOR_H