Apollo 10.0
自动驾驶开放平台
play_task_buffer.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
18
19#include <utility>
20
21namespace apollo {
22namespace cyber {
23namespace record {
24
26
28
29size_t PlayTaskBuffer::Size() const {
30 std::lock_guard<std::mutex> lck(mutex_);
31 return tasks_.size();
32}
33
35 std::lock_guard<std::mutex> lck(mutex_);
36 return tasks_.empty();
37}
38
39void PlayTaskBuffer::Push(const TaskPtr& task) {
40 if (task == nullptr) {
41 return;
42 }
43 std::lock_guard<std::mutex> lck(mutex_);
44 tasks_.insert(std::make_pair(task->msg_play_time_ns(), task));
45}
46
48 std::lock_guard<std::mutex> lck(mutex_);
49 if (tasks_.empty()) {
50 return nullptr;
51 }
52 auto res = tasks_.begin()->second;
53 return res;
54}
55
57 std::lock_guard<std::mutex> lck(mutex_);
58 if (!tasks_.empty()) {
59 tasks_.erase(tasks_.begin());
60 }
61}
62
64 std::lock_guard<std::mutex> lck(mutex_);
65 while (!tasks_.empty()) {
66 tasks_.erase(tasks_.begin());
67 }
68}
69
70} // namespace record
71} // namespace cyber
72} // namespace apollo
std::shared_ptr< PlayTask > TaskPtr
class register implement
Definition arena_queue.h:37