summaryrefslogtreecommitdiff
path: root/src/mongo/util/exit.h
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2016-03-11 14:34:47 -0500
committerAndrew Morrow <acm@mongodb.com>2016-03-21 22:55:32 -0400
commit4d6dd3b4359dc3cc8145beb10e54f84353689351 (patch)
treed2ca8c518ef2064854d5e9c1584fd89eab31d9e6 /src/mongo/util/exit.h
parent20ca6518797b67206d1f23d097c61c78a3ad8810 (diff)
downloadmongo-4d6dd3b4359dc3cc8145beb10e54f84353689351.tar.gz
SERVER-23103 Unify exit handling
Diffstat (limited to 'src/mongo/util/exit.h')
-rw-r--r--src/mongo/util/exit.h37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/mongo/util/exit.h b/src/mongo/util/exit.h
index bb7c2de9adb..fa6a8bbb85b 100644
--- a/src/mongo/util/exit.h
+++ b/src/mongo/util/exit.h
@@ -28,13 +28,12 @@
#pragma once
+#include "mongo/platform/compiler.h"
+#include "mongo/stdx/functional.h"
#include "mongo/util/exit_code.h"
namespace mongo {
-// Note: whyMsg can never be NULL.
-void dbexit(ExitCode returnCode, const char* whyMsg = "");
-
/**
* Quickly determines if the shutdown flag is set. May not be definitive.
*/
@@ -45,4 +44,36 @@ bool inShutdown();
* than inShutdown().
*/
bool inShutdownStrict();
+
+/**
+ * Registers a new shutdown task to be called when shutdown or
+ * shutdownNoTerminate is called. If this function is invoked after
+ * shutdown or shutdownNoTerminate has been called, std::terminate is
+ * called.
+ */
+void registerShutdownTask(stdx::function<void()>);
+
+/**
+ * Toggles the shutdown flag to 'true', runs registered shutdown
+ * tasks, and then exits with the given code. It is safe to call this
+ * function from multiple threads, only the first caller executes
+ * shutdown tasks. It is illegal to reenter this function from a
+ * registered shutdown task. The function does not return.
+ */
+MONGO_COMPILER_NORETURN void shutdown(ExitCode code);
+
+/**
+ * Toggles the shutdown flag to 'true' and runs the registered
+ * shutdown tasks. It is safe to call this function from multiple
+ * threads, only the first caller executes shutdown tasks, subsequent
+ * callers return immediately. It is legal to call shutdownNoTerminate
+ * from a shutdown task.
+ */
+void shutdownNoTerminate();
+
+/** An alias for 'shutdown'. */
+MONGO_COMPILER_NORETURN inline void exitCleanly(ExitCode code) {
+ shutdown(code);
}
+
+} // namespace mongo