thread_pool_for_testing.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_COMMON_INTERNAL_TESTING_THREAD_POOL_FOR_TESTING_H_
18 #define CARTOGRAPHER_COMMON_INTERNAL_TESTING_THREAD_POOL_FOR_TESTING_H_
19 
20 #include <deque>
21 #include <functional>
22 #include <map>
23 #include <thread>
24 
27 
28 namespace cartographer {
29 namespace common {
30 namespace testing {
31 
33  public:
36 
37  std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
38  EXCLUDES(mutex_) override;
39 
40  void WaitUntilIdle();
41 
42  private:
43  friend class Task;
44 
45  void DoWork();
46 
47  void NotifyDependenciesCompleted(Task* task) EXCLUDES(mutex_) override;
48 
49  Mutex mutex_;
50  bool running_ GUARDED_BY(mutex_) = true;
51  bool idle_ GUARDED_BY(mutex_) = true;
52  std::deque<std::shared_ptr<Task>> task_queue_ GUARDED_BY(mutex_);
53  std::map<Task*, std::shared_ptr<Task>> tasks_not_ready_ GUARDED_BY(mutex_);
54  std::thread thread_ GUARDED_BY(mutex_);
55 };
56 
57 } // namespace testing
58 } // namespace common
59 } // namespace cartographer
60 
61 #endif // CARTOGRAPHER_COMMON_INTERNAL_TESTING_THREAD_POOL_FOR_TESTING_H_
#define EXCLUDES(...)
Definition: mutex.h:53
void NotifyDependenciesCompleted(Task *task) EXCLUDES(mutex_) override
std::map< Task *, std::shared_ptr< Task > > tasks_not_ready_
Definition: task_test.cc:64
std::weak_ptr< Task > Schedule(std::unique_ptr< Task > task) EXCLUDES(mutex_) override
std::deque< std::shared_ptr< Task > > task_queue_
Definition: task_test.cc:63


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58