Skip to content

Commit

Permalink
Merge pull request #281 from nat-goodspeed/nat/fsx-libstdc++
Browse files Browse the repository at this point in the history
On libstdc++, fiber_fcontext.hpp sets fiber-specific exception state.
  • Loading branch information
olk authored Jan 14, 2025
2 parents 160bfe0 + 53b1755 commit bf043e3
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion include/boost/context/fiber_fcontext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,51 @@
# pragma warning(disable: 4702)
#endif

#if ! (defined(__GLIBCPP__) || defined(__GLIBCXX__))
namespace boost {
namespace context {
namespace detail {

// manage_exception_state is a dummy struct unless we have specific support
struct manage_exception_state {};

} // namespace detail
} // namespace context
} // namespace boost

#else // libstdc++
#include <cxxabi.h>

namespace __cxxabiv1 {
struct __cxa_eh_globals {
void * caughtExceptions;
unsigned int uncaughtExceptions;
};

class manage_exception_state {
public:
manage_exception_state() {
exception_state_ = *__cxa_get_globals();
}
~manage_exception_state() {
*__cxa_get_globals() = exception_state_;
}
private:
__cxa_eh_globals exception_state_;
};
} // namespace __cxxabiv1

namespace boost {
namespace context {
namespace detail {

using __cxxabiv1::manage_exception_state;

} // namespace detail
} // namespace context
} // namespace boost
#endif // __GLIBCPP__ or __GLIBCXX__

namespace boost {
namespace context {
namespace detail {
Expand Down Expand Up @@ -251,7 +296,7 @@ fcontext_t create_fiber2( preallocated palloc, StackAlloc && salloc, Fn && fn) {
return jump_fcontext( fctx, record).fctx;
}

}
} // namespace detail

class fiber {
private:
Expand Down Expand Up @@ -326,6 +371,7 @@ class fiber {

fiber resume() && {
BOOST_ASSERT( nullptr != fctx_);
detail::manage_exception_state exstate;
return { detail::jump_fcontext(
#if defined(BOOST_NO_CXX14_STD_EXCHANGE)
detail::exchange( fctx_, nullptr),
Expand All @@ -338,6 +384,7 @@ class fiber {
template< typename Fn >
fiber resume_with( Fn && fn) && {
BOOST_ASSERT( nullptr != fctx_);
detail::manage_exception_state exstate;
auto p = std::forward< Fn >( fn);
return { detail::ontop_fcontext(
#if defined(BOOST_NO_CXX14_STD_EXCHANGE)
Expand Down

0 comments on commit bf043e3

Please sign in to comment.