summaryrefslogtreecommitdiff
path: root/src/mongo/transport/baton.h
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2019-01-23 13:18:49 -0500
committerJason Carey <jcarey@argv.me>2019-02-05 22:41:49 -0500
commita23cdb1bd0f8fbe9cd79db08a24b8a89dc54ff81 (patch)
tree1adc2fdb36e6c8babaab134d53f84de3020c2404 /src/mongo/transport/baton.h
parent5fd66f15797c45c9bab7b59f9e55e0a2f7ad5cd0 (diff)
downloadmongo-a23cdb1bd0f8fbe9cd79db08a24b8a89dc54ff81.tar.gz
SERVER-39146 Refactor Baton
Refactor the baton into regular and networking batons while also cleaning up the basic baton implementation.
Diffstat (limited to 'src/mongo/transport/baton.h')
-rw-r--r--src/mongo/transport/baton.h61
1 files changed, 19 insertions, 42 deletions
diff --git a/src/mongo/transport/baton.h b/src/mongo/transport/baton.h
index 9dbf570ede2..de981ef6284 100644
--- a/src/mongo/transport/baton.h
+++ b/src/mongo/transport/baton.h
@@ -1,6 +1,6 @@
/**
- * Copyright (C) 2018-present MongoDB, Inc.
+ * Copyright (C) 2019-present MongoDB, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
@@ -32,9 +32,11 @@
#include <memory>
+#include "mongo/db/baton.h"
#include "mongo/transport/transport_layer.h"
#include "mongo/util/functional.h"
#include "mongo/util/future.h"
+#include "mongo/util/out_of_line_executor.h"
#include "mongo/util/time_support.h"
#include "mongo/util/waitable.h"
@@ -49,44 +51,17 @@ class Session;
class ReactorTimer;
/**
- * A Baton is basically a networking reactor, with limited functionality and no forward progress
- * guarantees. Rather than asynchronously running tasks through one, the baton records the intent
- * of those tasks and defers waiting and execution to a later call to run();
+ * A NetworkingBaton is basically a networking reactor, with limited functionality and parallel
+ * forward progress guarantees. Rather than asynchronously running tasks through one, the baton
+ * records the intent of those tasks and defers waiting and execution to a later call to run();
*
- * Baton's provide a mechanism to allow consumers of a transport layer to execute IO themselves,
- * rather than having this occur on another thread. This can improve performance by minimizing
- * context switches, as well as improving the readability of stack traces by grounding async
- * execution on top of a regular client call stack.
+ * NetworkingBaton's provide a mechanism to allow consumers of a transport layer to execute IO
+ * themselves, rather than having this occur on another thread. This can improve performance by
+ * minimizing context switches, as well as improving the readability of stack traces by grounding
+ * async execution on top of a regular client call stack.
*/
-class Baton : public Waitable {
+class NetworkingBaton : public Baton {
public:
- virtual ~Baton() = default;
-
- /**
- * Detaches a baton from an associated opCtx.
- */
- virtual void detach() = 0;
-
- /**
- * Executes a callback on the baton via schedule. Returns a future which will execute on the
- * baton runner.
- */
- template <typename Callback>
- Future<FutureContinuationResult<Callback>> execute(Callback&& cb) {
- auto pf = makePromiseFuture<FutureContinuationResult<Callback>>();
-
- schedule([ cb = std::forward<Callback>(cb), p = std::move(pf.promise) ]() mutable {
- p.setWith(std::move(cb));
- });
-
- return std::move(pf.future);
- }
-
- /**
- * Executes a callback on the baton.
- */
- virtual void schedule(unique_function<void()> func) = 0;
-
/**
* Adds a session, returning a future which activates on read/write-ability of the session.
*/
@@ -94,29 +69,31 @@ public:
In,
Out,
};
- virtual Future<void> addSession(Session& session, Type type) = 0;
+ virtual Future<void> addSession(Session& session, Type type) noexcept = 0;
/**
* Adds a timer, returning a future which activates after a deadline.
*/
- virtual Future<void> waitUntil(const ReactorTimer& timer, Date_t expiration) = 0;
+ virtual Future<void> waitUntil(const ReactorTimer& timer, Date_t expiration) noexcept = 0;
/**
* Cancels waiting on a session.
*
* Returns true if the session was in the baton to be cancelled.
*/
- virtual bool cancelSession(Session& session) = 0;
+ virtual bool cancelSession(Session& session) noexcept = 0;
/**
* Cancels waiting on a timer
*
* Returns true if the timer was in the baton to be cancelled.
*/
- virtual bool cancelTimer(const ReactorTimer& timer) = 0;
-};
+ virtual bool cancelTimer(const ReactorTimer& timer) noexcept = 0;
-using BatonHandle = std::shared_ptr<Baton>;
+ NetworkingBaton* networking() noexcept final {
+ return this;
+ }
+};
} // namespace transport
} // namespace mongo