From: Brian Watling Date: Thu, 3 Sep 2015 20:13:26 +0000 (-0700) Subject: Allow (read-only) access to a fiber's stack details X-Git-Tag: deprecate-dynamic-initializer~441 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5667a9704f154dfb68b4294f475d25e30ab6b0d7;p=folly.git Allow (read-only) access to a fiber's stack details Summary: Allow users to access the stack pointer and stack size Reviewed By: @alikhtarov Differential Revision: D2407252 --- diff --git a/folly/experimental/fibers/Fiber.h b/folly/experimental/fibers/Fiber.h index 78624882..0732dd71 100644 --- a/folly/experimental/fibers/Fiber.h +++ b/folly/experimental/fibers/Fiber.h @@ -54,6 +54,21 @@ class Fiber { Fiber& operator=(const Fiber&) = delete; ~Fiber(); + + /** + * Retrieve this fiber's base stack and stack size. + * + * @return This fiber's stack pointer and stack size. + */ + std::pair getStack() const { + void* const stack = + std::min(fcontext_.stackLimit(), fcontext_.stackBase()); + const size_t size = std::abs( + reinterpret_cast(fcontext_.stackBase()) - + reinterpret_cast(fcontext_.stackLimit())); + return { stack, size }; + } + private: enum State { INVALID, /**< Does't have task function */