]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/threadpool.h
update sources to ceph Nautilus 14.2.1
[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 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).
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 virtual int GetBackgroundThreads() = 0;
33
34 // Get the number of jobs scheduled in the ThreadPool queue.
35 virtual unsigned int GetQueueLen() const = 0;
36
37 // Waits for all jobs to complete those
38 // that already started running and those that did not
39 // start yet. This ensures that everything that was thrown
40 // on the TP runs even though
41 // we may not have specified enough threads for the amount
42 // of jobs
43 virtual void WaitForJobsAndJoinAllThreads() = 0;
44
45 // Submit a fire and forget jobs
46 // This allows to submit the same job multiple times
47 virtual void SubmitJob(const std::function<void()>&) = 0;
48 // This moves the function in for efficiency
49 virtual void SubmitJob(std::function<void()>&&) = 0;
50
51 };
52
53 // NewThreadPool() is a function that could be used to create a ThreadPool
54 // with `num_threads` background threads.
55 extern ThreadPool* NewThreadPool(int num_threads);
56
57 } // namespace rocksdb