Apollo  6.0
Open source self driving car software
timer_bucket.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
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 CYBER_TIMER_TIMER_BUCKET_H_
18 #define CYBER_TIMER_TIMER_BUCKET_H_
19 
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 
24 #include "cyber/timer/timer_task.h"
25 
26 namespace apollo {
27 namespace cyber {
28 
29 class TimerBucket {
30  public:
31  void AddTask(const std::shared_ptr<TimerTask>& task) {
32  std::lock_guard<std::mutex> lock(mutex_);
33  task_list_.push_back(task);
34  }
35 
36  std::mutex& mutex() { return mutex_; }
37  std::list<std::weak_ptr<TimerTask>>& task_list() { return task_list_; }
38 
39  private:
40  std::mutex mutex_;
41  std::list<std::weak_ptr<TimerTask>> task_list_;
42 };
43 
44 } // namespace cyber
45 } // namespace apollo
46 
47 #endif // CYBER_TIMER_TIMER_BUCKET_H_
Definition: timer_bucket.h:29
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::list< std::weak_ptr< TimerTask > > & task_list()
Definition: timer_bucket.h:37
std::mutex & mutex()
Definition: timer_bucket.h:36
void AddTask(const std::shared_ptr< TimerTask > &task)
Definition: timer_bucket.h:31