]> granicus.if.org Git - pdns/commitdiff
Hack in compatibility for Boost <= 1.55
authorAndrew Nelless <andrew@nelless.net>
Tue, 23 Feb 2016 15:15:56 +0000 (15:15 +0000)
committerAndrew Nelless <andrew@nelless.net>
Tue, 23 Feb 2016 16:51:09 +0000 (16:51 +0000)
pdns/mtasker_fcontext.cc

index dfe3455299cba6ccbe5f956529f4977470210581..77f473cf1d961f2d18f426a2f0e4900212c2d7f8 100644 (file)
@@ -1,11 +1,35 @@
 #include "mtasker_context.hh"
 #include <exception>
 #include <cassert>
+#include <type_traits>
 #include <boost/context/fcontext.hpp>
+#include <boost/version.hpp>
 
+using boost::context::make_fcontext;
+
+#if BOOST_VERSION < 105600
+using fcontext_t = boost::context::fcontext_t*;
+
+static inline intptr_t
+jump_fcontext (fcontext_t* const ofc, fcontext_t const nfc, 
+               intptr_t const arg) {
+    if (*ofc) {
+        return boost::context::jump_fcontext (*ofc, nfc, arg);
+    } else {
+        boost::context::fcontext_t self;
+        *ofc = &self;
+        auto ret = boost::context::jump_fcontext (*ofc, nfc, arg);
+        *ofc = nullptr;
+        return ret;
+    }
+}
+#else
 using boost::context::fcontext_t;
 using boost::context::jump_fcontext;
-using boost::context::make_fcontext;
+
+static_assert (std::is_pointer<fcontext_t>::value,
+               "Boost Context has changed the fcontext_t type again :-(");
+#endif
 
 struct args_t {
     fcontext_t prev_ctx = nullptr;
@@ -20,7 +44,8 @@ threadWrapper (intptr_t const xargs) {
     auto args = reinterpret_cast<args_t*>(xargs);
     auto ctx = args->self;
     auto work = args->work;
-    jump_fcontext (&ctx->uc_mcontext, args->prev_ctx, 0);
+    jump_fcontext (reinterpret_cast<fcontext_t*>(&ctx->uc_mcontext),
+                   static_cast<fcontext_t>(args->prev_ctx), 0);
     args = nullptr;
 
     try {
@@ -31,7 +56,8 @@ threadWrapper (intptr_t const xargs) {
     }
 
     auto const next_ctx = ctx->uc_link->uc_mcontext;
-    jump_fcontext (&ctx->uc_mcontext, next_ctx,
+    jump_fcontext (reinterpret_cast<fcontext_t*>(&ctx->uc_mcontext),
+                   static_cast<fcontext_t>(next_ctx),
                    static_cast<bool>(ctx->exception));
 #ifdef NDEBUG
     __builtin_unreachable();
@@ -50,7 +76,8 @@ pdns_ucontext_t::~pdns_ucontext_t
 void
 pdns_swapcontext
 (pdns_ucontext_t& __restrict octx, pdns_ucontext_t const& __restrict ctx) {
-    if (jump_fcontext (&octx.uc_mcontext, ctx.uc_mcontext, 0)) {
+    if (jump_fcontext (reinterpret_cast<fcontext_t*>(&octx.uc_mcontext),
+                       static_cast<fcontext_t>(ctx.uc_mcontext), 0)) {
         std::rethrow_exception (ctx.exception);
     }
 }
@@ -66,6 +93,7 @@ pdns_makecontext
     args_t args;
     args.self = &ctx;
     args.work = &start;
-    jump_fcontext (&args.prev_ctx, ctx.uc_mcontext,
+    jump_fcontext (reinterpret_cast<fcontext_t*>(&args.prev_ctx),
+                   static_cast<fcontext_t>(ctx.uc_mcontext),
                    reinterpret_cast<intptr_t>(&args));
 }