1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 #include "common/Thread.h"
21 * Implement the pattern of calling serve() on a module in a thread,
22 * until shutdown() is called.
27 const std::string module_name
;
29 // Passed in by whoever loaded our python module and looked up
31 PyObject
*pClass
= nullptr;
33 // Passed in by whoever created our subinterpreter for us
34 SafeThreadState pMyThreadState
= nullptr;
36 // Populated when we construct our instance of pClass in load()
37 PyObject
*pClassInstance
= nullptr;
39 class PyModuleRunnerThread
: public Thread
44 PyModuleRunnerThread(PyModuleRunner
*mod_
)
47 void *entry() override
;
53 void log(int level
, const std::string
&record
);
56 const std::string
&module_name_
,
58 const SafeThreadState
&pMyThreadState_
)
60 module_name(module_name_
),
61 pClass(pClass_
), pMyThreadState(pMyThreadState_
),
64 assert(pClass
!= nullptr);
65 assert(pMyThreadState
.ts
!= nullptr);
66 assert(!module_name
.empty());
71 PyModuleRunnerThread thread
;
73 std::string
const &get_name() const { return module_name
; }