Apollo 10.0
自动驾驶开放平台
play_task_consumer.h
浏览该文件的文档.
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
17#ifndef CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_CONSUMER_H_
18#define CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_CONSUMER_H_
19
20#include <atomic>
21#include <cstdint>
22#include <memory>
23#include <thread>
24
26
27namespace apollo {
28namespace cyber {
29namespace record {
30
32 public:
33 using ThreadPtr = std::unique_ptr<std::thread>;
34 using TaskBufferPtr = std::shared_ptr<PlayTaskBuffer>;
35
36 explicit PlayTaskConsumer(const TaskBufferPtr& task_buffer,
37 double play_rate = 1.0);
38 virtual ~PlayTaskConsumer();
39
40 void Start(uint64_t begin_time_ns);
41 void Stop();
42 void Pause() { is_paused_.exchange(true); }
43 void PlayOnce() { is_playonce_.exchange(true); }
44 void Continue() { is_paused_.exchange(false); }
45
46 uint64_t base_msg_play_time_ns() const { return base_msg_play_time_ns_; }
47 uint64_t base_msg_real_time_ns() const { return base_msg_real_time_ns_; }
49 return last_played_msg_real_time_ns_;
50 }
51
52 private:
53 void ThreadFunc();
54
55 double play_rate_;
56 ThreadPtr consume_th_;
57 TaskBufferPtr task_buffer_;
58 std::atomic<bool> is_stopped_;
59 std::atomic<bool> is_paused_;
60 std::atomic<bool> is_playonce_;
61 uint64_t begin_time_ns_;
62 uint64_t base_msg_play_time_ns_;
63 uint64_t base_msg_real_time_ns_;
64 uint64_t last_played_msg_real_time_ns_;
65 static const uint64_t kPauseSleepNanoSec;
66 static const uint64_t kWaitProduceSleepNanoSec;
67 static const uint64_t MIN_SLEEP_DURATION_NS;
68};
69
70} // namespace record
71} // namespace cyber
72} // namespace apollo
73
74#endif // CYBER_TOOLS_CYBER_RECORDER_PLAYER_PLAY_TASK_CONSUMER_H_
std::shared_ptr< PlayTaskBuffer > TaskBufferPtr
std::unique_ptr< std::thread > ThreadPtr
class register implement
Definition arena_queue.h:37