]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/threadpool_imp.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / util / threadpool_imp.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5//
6// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9#pragma once
10
11#include "rocksdb/threadpool.h"
12#include "rocksdb/env.h"
13
14#include <memory>
15#include <functional>
16
17namespace rocksdb {
18
19
20class ThreadPoolImpl : public ThreadPool {
21 public:
22 ThreadPoolImpl();
23 ~ThreadPoolImpl();
24
25 ThreadPoolImpl(ThreadPoolImpl&&) = delete;
26 ThreadPoolImpl& operator=(ThreadPoolImpl&&) = delete;
27
28 // Implement ThreadPool interfaces
29
30 // Wait for all threads to finish.
11fdf7f2 31 // Discards all the jobs that did not
7c673cae
FG
32 // start executing and waits for those running
33 // to complete
34 void JoinAllThreads() override;
35
36 // Set the number of background threads that will be executing the
37 // scheduled jobs.
38 void SetBackgroundThreads(int num) override;
11fdf7f2
TL
39 int GetBackgroundThreads() override;
40
7c673cae
FG
41 // Get the number of jobs scheduled in the ThreadPool queue.
42 unsigned int GetQueueLen() const override;
43
44 // Waits for all jobs to complete those
45 // that already started running and those that did not
46 // start yet
47 void WaitForJobsAndJoinAllThreads() override;
48
11fdf7f2 49 // Make threads to run at a lower kernel IO priority
7c673cae
FG
50 // Currently only has effect on Linux
51 void LowerIOPriority();
52
11fdf7f2
TL
53 // Make threads to run at a lower kernel CPU priority
54 // Currently only has effect on Linux
55 void LowerCPUPriority();
56
7c673cae
FG
57 // Ensure there is at aleast num threads in the pool
58 // but do not kill threads if there are more
59 void IncBackgroundThreadsIfNeeded(int num);
60
61 // Submit a fire and forget job
62 // These jobs can not be unscheduled
63
64 // This allows to submit the same job multiple times
65 void SubmitJob(const std::function<void()>&) override;
66 // This moves the function in for efficiency
67 void SubmitJob(std::function<void()>&&) override;
68
69 // Schedule a job with an unschedule tag and unschedule function
70 // Can be used to filter and unschedule jobs by a tag
71 // that are still in the queue and did not start running
72 void Schedule(void (*function)(void* arg1), void* arg, void* tag,
73 void (*unschedFunction)(void* arg));
74
75 // Filter jobs that are still in a queue and match
76 // the given tag. Remove them from a queue if any
77 // and for each such job execute an unschedule function
78 // if such was given at scheduling time.
79 int UnSchedule(void* tag);
80
81 void SetHostEnv(Env* env);
82
83 Env* GetHostEnv() const;
84
85 // Return the thread priority.
86 // This would allow its member-thread to know its priority.
87 Env::Priority GetThreadPriority() const;
88
89 // Set the thread priority.
90 void SetThreadPriority(Env::Priority priority);
91
92 static void PthreadCall(const char* label, int result);
93
94 struct Impl;
95
96 private:
97
98 // Current public virtual interface does not provide usable
99 // functionality and thus can not be used internally to
100 // facade different implementations.
101 //
102 // We propose a pimpl idiom in order to easily replace the thread pool impl
103 // w/o touching the header file but providing a different .cc potentially
104 // CMake option driven.
105 //
106 // Another option is to introduce a Env::MakeThreadPool() virtual interface
107 // and override the environment. This would require refactoring ThreadPool usage.
108 //
109 // We can also combine these two approaches
110 std::unique_ptr<Impl> impl_;
111};
112
113} // namespace rocksdb