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 #ifndef THREAD_POOL_TEST_STUB_H
16 #define THREAD_POOL_TEST_STUB_H
17 #include <atomic>
18 #include <condition_variable>
19 #include <mutex>
20 #include <queue>
21 #include "ithread_pool.h"
22 #include "task_pool.h"
23 
24 namespace DistributedDB {
25 class ThreadPoolTestStub : public IThreadPool {
26 public:
27     ThreadPoolTestStub() = default;
28     ~ThreadPoolTestStub();
29 
30     TaskId Execute(const Task &task) override;
31 
32     TaskId Execute(const Task &task, Duration delay) override;
33 
34     TaskId Schedule(const Task &task, Duration interval) override;
35 
36     TaskId Schedule(const Task &task, Duration delay, Duration interval) override;
37 
38     TaskId Schedule(const Task &task, Duration delay, Duration interval, uint64_t times) override;
39 
40     bool Remove(const TaskId &taskId, bool wait) override;
41 
42     TaskId Reset(const TaskId &taskId, Duration interval) override;
43 private:
44     void StartThreadIfNeed();
45 
46     std::mutex taskPoolLock_;
47     TaskPool *taskPool_ = nullptr;
48 };
49 }
50 #endif // THREAD_POOL_TEST_STUB_H
51