1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ITHREAD_POOL_H
17 #define ITHREAD_POOL_H
18 
19 #include <thread>
20 #include "store_types.h"
21 
22 namespace DistributedDB {
23 using Task = std::function<void()>;
24 using TaskId = uint64_t;
25 using Duration = std::chrono::steady_clock::duration;
26 class IThreadPool {
27 public:
28     IThreadPool() = default;
29     virtual ~IThreadPool() = default;
30 
31     virtual TaskId Execute(const Task &task) = 0;
32 
33     virtual TaskId Execute(const Task &task, Duration delay) = 0;
34 
35     virtual TaskId Schedule(const Task &task, Duration interval) = 0;
36 
37     virtual TaskId Schedule(const Task &task, Duration delay, Duration interval) = 0;
38 
39     virtual TaskId Schedule(const Task &task, Duration delay, Duration interval, uint64_t times) = 0;
40 
41     virtual bool Remove(const TaskId &taskId, bool wait) = 0;
42 
43     virtual TaskId Reset(const TaskId &taskId, Duration interval) = 0;
44 };
45 }
46 #endif // ITHREAD_POOL_H
47