-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathProcessManagerImpl.h
More file actions
67 lines (55 loc) · 2.19 KB
/
Copy pathProcessManagerImpl.h
File metadata and controls
67 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2014 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#pragma once
#include "process/ProcessManager.h"
#include "util/ThreadAnnotations.h"
#include "util/TmpDir.h"
#include <atomic>
#include <deque>
#include <mutex>
#include <vector>
#include <map>
namespace stellar
{
class ProcessManagerImpl : public ProcessManager
{
// Subprocesses will be removed asynchronously, hence the lock on
// just the mProcesses member.
ANNOTATED_RECURSIVE_MUTEX(mProcessesMutex);
// Stores a map from pid to running-or-shutting-down processes.
// Any ProcessExitEvent should be stored either in mProcesses
// or in mPending (before it's launched).
std::map<int, std::shared_ptr<ProcessExitEvent>>
mProcesses GUARDED_BY(mProcessesMutex);
std::atomic<bool> mIsShutdown{false};
size_t const mMaxProcesses;
asio::io_context& mIOContext;
// These are only used on POSIX, but they're harmless here.
asio::signal_set mSigChild;
std::unique_ptr<TmpDir> mTmpDir;
uint64_t mTempFileCount{0};
std::deque<std::shared_ptr<ProcessExitEvent>>
mPending GUARDED_BY(mProcessesMutex);
void maybeRunPendingProcesses();
void checkInvariants();
void startWaitingForSignalChild();
void handleSignalChild();
void reapChildren();
asio::error_code handleProcessTermination(int pid, int status);
bool politeShutdown(std::shared_ptr<ProcessExitEvent> pe);
bool forcedShutdown(std::shared_ptr<ProcessExitEvent> pe);
void tryProcessShutdownAll();
friend class ProcessExitEvent::Impl;
public:
explicit ProcessManagerImpl(Application& app);
std::weak_ptr<ProcessExitEvent> runProcess(std::string const& cmdLine,
std::string outFile) override;
size_t getNumRunningProcesses() override;
size_t getNumRunningOrShuttingDownProcesses() override;
bool isShutdown() const override;
void shutdown() override;
bool tryProcessShutdown(std::shared_ptr<ProcessExitEvent> pe) override;
~ProcessManagerImpl() override;
};
}