Apollo 10.0
自动驾驶开放平台
classic_context.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_POLICY_CLASSIC_CONTEXT_H_
18#define CYBER_SCHEDULER_POLICY_CLASSIC_CONTEXT_H_
19
20#include <array>
21#include <functional>
22#include <memory>
23#include <mutex>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
33
34namespace apollo {
35namespace cyber {
36namespace scheduler {
37
38static constexpr uint32_t MAX_PRIO = 20;
39
40#define DEFAULT_GROUP_NAME "default_grp"
41
42using CROUTINE_QUEUE = std::vector<std::shared_ptr<CRoutine>>;
43using MULTI_PRIO_QUEUE = std::array<CROUTINE_QUEUE, MAX_PRIO>;
44using CR_GROUP = std::unordered_map<std::string, MULTI_PRIO_QUEUE>;
45using LOCK_QUEUE = std::array<base::AtomicRWLock, MAX_PRIO>;
46using RQ_LOCK_GROUP = std::unordered_map<std::string, LOCK_QUEUE>;
47
48using GRP_WQ_MUTEX = std::unordered_map<std::string, MutexWrapper>;
49using GRP_WQ_CV = std::unordered_map<std::string, CvWrapper>;
50using NOTIFY_GRP = std::unordered_map<std::string, int>;
51
53 public:
55 explicit ClassicContext(const std::string &group_name);
56
57 std::shared_ptr<CRoutine> NextRoutine() override;
58 void Wait() override;
59 void Shutdown() override;
60
61 static void Notify(const std::string &group_name);
62 static bool RemoveCRoutine(const std::shared_ptr<CRoutine> &cr);
63
69
70 private:
71 void InitGroup(const std::string &group_name);
72
73 std::chrono::steady_clock::time_point wake_time_;
74 bool need_sleep_ = false;
75
76 MULTI_PRIO_QUEUE *multi_pri_rq_ = nullptr;
77 LOCK_QUEUE *lq_ = nullptr;
78 MutexWrapper *mtx_wrapper_ = nullptr;
79 CvWrapper *cw_ = nullptr;
80
81 std::string current_grp;
82};
83
84} // namespace scheduler
85} // namespace cyber
86} // namespace apollo
87
88#endif // CYBER_SCHEDULER_POLICY_CLASSIC_CONTEXT_H_
static void Notify(const std::string &group_name)
static bool RemoveCRoutine(const std::shared_ptr< CRoutine > &cr)
std::shared_ptr< CRoutine > NextRoutine() override
#define CACHELINE_SIZE
Definition macros.h:33
std::unordered_map< std::string, MutexWrapper > GRP_WQ_MUTEX
std::array< base::AtomicRWLock, MAX_PRIO > LOCK_QUEUE
std::unordered_map< std::string, CvWrapper > GRP_WQ_CV
std::array< CROUTINE_QUEUE, MAX_PRIO > MULTI_PRIO_QUEUE
std::unordered_map< std::string, LOCK_QUEUE > RQ_LOCK_GROUP
std::vector< std::shared_ptr< CRoutine > > CROUTINE_QUEUE
std::unordered_map< std::string, MULTI_PRIO_QUEUE > CR_GROUP
std::unordered_map< std::string, int > NOTIFY_GRP
class register implement
Definition arena_queue.h:37