Apollo  6.0
Open source self driving car software
processor.h
Go to the documentation of this file.
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_SCHEDULER_PROCESSOR_H_
18 #define CYBER_SCHEDULER_PROCESSOR_H_
19 
20 #include <atomic>
21 #include <condition_variable>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include <thread>
26 #include <vector>
27 
28 #include "cyber/proto/scheduler_conf.pb.h"
29 
32 
33 namespace apollo {
34 namespace cyber {
35 namespace scheduler {
36 
37 using croutine::CRoutine;
38 
39 struct Snapshot {
40  std::atomic<uint64_t> execute_start_time = {0};
41  std::atomic<pid_t> processor_id = {0};
42  std::string routine_name;
43 };
44 
45 class Processor {
46  public:
47  Processor();
48  virtual ~Processor();
49 
50  void Run();
51  void Stop();
52  void BindContext(const std::shared_ptr<ProcessorContext>& context);
53  std::thread* Thread() { return &thread_; }
54  std::atomic<pid_t>& Tid();
55 
56  std::shared_ptr<Snapshot> ProcSnapshot() { return snap_shot_; }
57 
58  private:
59  std::shared_ptr<ProcessorContext> context_;
60 
61  std::condition_variable cv_ctx_;
62  std::once_flag thread_flag_;
63  std::mutex mtx_ctx_;
64  std::thread thread_;
65 
66  std::atomic<pid_t> tid_{-1};
67  std::atomic<bool> running_{false};
68 
69  std::shared_ptr<Snapshot> snap_shot_ = std::make_shared<Snapshot>();
70 };
71 
72 } // namespace scheduler
73 } // namespace cyber
74 } // namespace apollo
75 
76 #endif // CYBER_SCHEDULER_PROCESSOR_H_
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: processor.h:39
std::shared_ptr< Snapshot > ProcSnapshot()
Definition: processor.h:56
std::string routine_name
Definition: processor.h:42
Definition: processor.h:45
std::atomic< uint64_t > execute_start_time
Definition: processor.h:40
std::atomic< pid_t > processor_id
Definition: processor.h:41
std::thread * Thread()
Definition: processor.h:53