From 645e32b19e73c519a807362a21aa29045b826101 Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Tue, 28 Jul 2015 16:16:06 -0400 Subject: [PATCH] Fix coroutine suspend --- src/ripple/rpc/Context.h | 9 +++++++++ src/ripple/rpc/Yield.h | 5 +++-- src/ripple/rpc/handlers/RipplePathFind.cpp | 12 +++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/ripple/rpc/Context.h b/src/ripple/rpc/Context.h index 4660096c9c..0d4feeb15a 100644 --- a/src/ripple/rpc/Context.h +++ b/src/ripple/rpc/Context.h @@ -47,6 +47,15 @@ struct Context NodeStore::ScopedMetrics metrics; }; +inline +void suspend(Context const& context, Continuation const& continuation) +{ + if (context.suspend) + context.suspend(continuation); + else + continuation(doNothingCallback); +} + } // RPC } // ripple diff --git a/src/ripple/rpc/Yield.h b/src/ripple/rpc/Yield.h index 73dffafbc0..1c700e2974 100644 --- a/src/ripple/rpc/Yield.h +++ b/src/ripple/rpc/Yield.h @@ -40,8 +40,9 @@ namespace RPC { /** Callback: do something and eventually return. */ using Callback = std::function ; +/** A non-empty callback that does nothing. */ static -Callback const emptyCallback ([] () {}); +Callback const doNothingCallback ([] () {}); /** Continuation: do something, guarantee to eventually call Callback. */ using Continuation = std::function ; @@ -115,7 +116,7 @@ Callback suspendForContinuation ( { return suspend ? Callback ([=] () { suspend (continuation); }) - : emptyCallback; + : Callback ([=] () { continuation (doNothingCallback); }); } } // RPC diff --git a/src/ripple/rpc/handlers/RipplePathFind.cpp b/src/ripple/rpc/handlers/RipplePathFind.cpp index 6b2a012a0e..ca651fb743 100644 --- a/src/ripple/rpc/handlers/RipplePathFind.cpp +++ b/src/ripple/rpc/handlers/RipplePathFind.cpp @@ -104,13 +104,15 @@ Json::Value doRipplePathFind (RPC::Context& context) lpLedger = context.ledgerMaster.getClosedLedger(); PathRequest::pointer request; - context.suspend ([&request, &context, &jvResult, &lpLedger] - (RPC::Callback const& c) + suspend(context, + [&request, &context, &jvResult, &lpLedger] + (RPC::Callback const& callback) { jvResult = getApp().getPathRequests().makeLegacyPathRequest ( - request, c, lpLedger, context.params); - if (! request) - c(); + request, callback, lpLedger, context.params); + assert(callback); + if (! request && callback) + callback(); }); if (request)