summaryrefslogtreecommitdiffstats
path: root/src/mgr/PyModuleRunner.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/mgr/PyModuleRunner.h
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/mgr/PyModuleRunner.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/mgr/PyModuleRunner.h b/src/mgr/PyModuleRunner.h
new file mode 100644
index 000000000..88d9f755a
--- /dev/null
+++ b/src/mgr/PyModuleRunner.h
@@ -0,0 +1,89 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2016 John Spray <john.spray@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ */
+
+
+#pragma once
+
+#include "common/Thread.h"
+#include "common/LogClient.h"
+#include "mgr/Gil.h"
+
+#include "PyModule.h"
+
+/**
+ * Implement the pattern of calling serve() on a module in a thread,
+ * until shutdown() is called.
+ */
+class PyModuleRunner
+{
+public:
+ // Info about the module we're going to run
+ PyModuleRef py_module;
+
+protected:
+ // Populated by descendent class
+ PyObject *pClassInstance = nullptr;
+
+ LogChannelRef clog;
+
+ class PyModuleRunnerThread : public Thread
+ {
+ PyModuleRunner *mod;
+
+ public:
+ explicit PyModuleRunnerThread(PyModuleRunner *mod_)
+ : mod(mod_) {}
+
+ void *entry() override;
+ };
+
+ bool is_dead() const { return dead; }
+
+ std::string thread_name;
+
+public:
+ int serve();
+ void shutdown();
+ void log(const std::string &record);
+
+ const char *get_thread_name() const
+ {
+ return thread_name.c_str();
+ }
+
+ PyModuleRunner(
+ const PyModuleRef &py_module_,
+ LogChannelRef clog_)
+ :
+ py_module(py_module_),
+ clog(clog_),
+ thread(this)
+ {
+ // Shortened name for use as thread name, because thread names
+ // required to be <16 chars
+ thread_name = py_module->get_name().substr(0, 15);
+
+ ceph_assert(py_module != nullptr);
+ }
+
+ ~PyModuleRunner();
+
+ PyModuleRunnerThread thread;
+
+ std::string const &get_name() const { return py_module->get_name(); }
+
+private:
+ bool dead = false;
+};
+
+