Apollo 10.0
自动驾驶开放平台
scheduler.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_SCHEDULER_SCHEDULER_H_
18#define CYBER_SCHEDULER_SCHEDULER_H_
19
20#include <unistd.h>
21
22#include <atomic>
23#include <map>
24#include <memory>
25#include <mutex>
26#include <string>
27#include <thread>
28#include <unordered_map>
29#include <vector>
30
31#include "cyber/proto/choreography_conf.pb.h"
32
35#include "cyber/common/log.h"
36#include "cyber/common/macros.h"
37#include "cyber/common/types.h"
42
43namespace apollo {
44namespace cyber {
45namespace scheduler {
46
54
55class Processor;
56class ProcessorContext;
57
58class Scheduler {
59 public:
60 virtual ~Scheduler() {}
62
63 bool CreateTask(const RoutineFactory& factory, const std::string& name);
64 bool CreateTask(std::function<void()>&& func, const std::string& name,
65 std::shared_ptr<DataVisitorBase> visitor = nullptr);
66 bool NotifyTask(uint64_t crid);
67
68 void Shutdown();
69 uint32_t TaskPoolSize() { return task_pool_size_; }
70
71 virtual bool RemoveTask(const std::string& name) = 0;
72
74 void SetInnerThreadAttr(const std::string& name, std::thread* thr);
75
76 virtual bool DispatchTask(const std::shared_ptr<CRoutine>&) = 0;
77 virtual bool NotifyProcessor(uint64_t crid) = 0;
78 virtual bool RemoveCRoutine(uint64_t crid) = 0;
79
80 void CheckSchedStatus();
81
83 const std::unordered_map<std::string, InnerThread>& confs) {
84 inner_thr_confs_ = confs;
85 }
86
87 protected:
88 Scheduler() : stop_(false) {}
89
92 std::mutex cr_wl_mtx_;
93
94 std::unordered_map<uint64_t, std::shared_ptr<CRoutine>> id_cr_;
95 std::vector<std::shared_ptr<ProcessorContext>> pctxs_;
96 std::vector<std::shared_ptr<Processor>> processors_;
97
98 std::unordered_map<std::string, InnerThread> inner_thr_confs_;
99
101 uint32_t proc_num_ = 0;
102 uint32_t task_pool_size_ = 0;
103 std::atomic<bool> stop_;
104};
105
106} // namespace scheduler
107} // namespace cyber
108} // namespace apollo
109
110#endif // CYBER_SCHEDULER_SCHEDULER_H_
A implementation of lock-free fixed size hash map
std::vector< std::shared_ptr< Processor > > processors_
Definition scheduler.h:96
AtomicHashMap< uint64_t, MutexWrapper * > id_map_mutex_
Definition scheduler.h:91
virtual bool DispatchTask(const std::shared_ptr< CRoutine > &)=0
void SetInnerThreadConfs(const std::unordered_map< std::string, InnerThread > &confs)
Definition scheduler.h:82
std::unordered_map< uint64_t, std::shared_ptr< CRoutine > > id_cr_
Definition scheduler.h:94
std::unordered_map< std::string, InnerThread > inner_thr_confs_
Definition scheduler.h:98
std::vector< std::shared_ptr< ProcessorContext > > pctxs_
Definition scheduler.h:95
void SetInnerThreadAttr(const std::string &name, std::thread *thr)
Definition scheduler.cc:90
virtual bool NotifyProcessor(uint64_t crid)=0
virtual bool RemoveTask(const std::string &name)=0
bool CreateTask(const RoutineFactory &factory, const std::string &name)
Definition scheduler.cc:37
virtual bool RemoveCRoutine(uint64_t crid)=0
class register implement
Definition arena_queue.h:37