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"
18 #include "common/LogClient.h"
22 * Implement the pattern of calling serve() on a module in a thread,
23 * until shutdown() is called.
28 const std::string module_name
;
30 // Passed in by whoever loaded our python module and looked up
32 PyObject
*pClass
= nullptr;
34 // Passed in by whoever created our subinterpreter for us
35 SafeThreadState pMyThreadState
= nullptr;
37 // Populated when we construct our instance of pClass in load()
38 PyObject
*pClassInstance
= nullptr;
42 class PyModuleRunnerThread
: public Thread
47 PyModuleRunnerThread(PyModuleRunner
*mod_
)
50 void *entry() override
;
56 void log(int level
, const std::string
&record
);
59 const std::string
&module_name_
,
61 const SafeThreadState
&pMyThreadState_
,
64 module_name(module_name_
),
65 pClass(pClass_
), pMyThreadState(pMyThreadState_
),
69 assert(pClass
!= nullptr);
70 assert(pMyThreadState
.ts
!= nullptr);
71 assert(!module_name
.empty());
76 PyModuleRunnerThread thread
;
78 std::string
const &get_name() const { return module_name
; }