]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/threadpool.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / include / rocksdb / threadpool.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
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 <functional>
12
13 namespace rocksdb {
14
15 /*
16 * ThreadPool is a component that will spawn N background threads that will
17 * be used to execute scheduled work, The number of background threads could
18 * be modified by calling SetBackgroundThreads().
19 * */
20 class ThreadPool {
21 public:
22 virtual ~ThreadPool() {}
23
24 // Wait for all threads to finish.
25 // Discard those threads that did not start
26 // executing
27 virtual void JoinAllThreads() = 0;
28
29 // Set the number of background threads that will be executing the
30 // scheduled jobs.
31 virtual void SetBackgroundThreads(int num) = 0;
32
33 // Get the number of jobs scheduled in the ThreadPool queue.
34 virtual unsigned int GetQueueLen() const = 0;
35
36 // Waits for all jobs to complete those
37 // that already started running and those that did not
38 // start yet. This ensures that everything that was thrown
39 // on the TP runs even though
40 // we may not have specified enough threads for the amount
41 // of jobs
42 virtual void WaitForJobsAndJoinAllThreads() = 0;
43
44 // Submit a fire and forget jobs
45 // This allows to submit the same job multiple times
46 virtual void SubmitJob(const std::function<void()>&) = 0;
47 // This moves the function in for efficiency
48 virtual void SubmitJob(std::function<void()>&&) = 0;
49
50 };
51
52 // NewThreadPool() is a function that could be used to create a ThreadPool
53 // with `num_threads` background threads.
54 extern ThreadPool* NewThreadPool(int num_threads);
55
56 } // namespace rocksdb