Apollo 10.0
自动驾驶开放平台
routine_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_CROUTINE_ROUTINE_CONTEXT_H_
18#define CYBER_CROUTINE_ROUTINE_CONTEXT_H_
19
20#include <cstdlib>
21#include <cstring>
22#include <iostream>
23
24#include "cyber/common/log.h"
25
26extern "C" {
27extern void ctx_swap(void**, void**) asm("ctx_swap");
28};
29
30namespace apollo {
31namespace cyber {
32namespace croutine {
33
34constexpr size_t STACK_SIZE = 2 * 1024 * 1024;
35#if defined __aarch64__
36constexpr size_t REGISTERS_SIZE = 160;
37#else
38constexpr size_t REGISTERS_SIZE = 56;
39#endif
40
41typedef void (*func)(void*);
44 char* sp = nullptr;
45#if defined __aarch64__
46} __attribute__((aligned(16)));
47#else
48};
49#endif
50
51void MakeContext(const func& f1, const void* arg, RoutineContext* ctx);
52
53inline void SwapContext(char** src_sp, char** dest_sp) {
54 ctx_swap(reinterpret_cast<void**>(src_sp), reinterpret_cast<void**>(dest_sp));
55}
56
57} // namespace croutine
58} // namespace cyber
59} // namespace apollo
60
61#endif // CYBER_CROUTINE_ROUTINE_CONTEXT_H_
void SwapContext(char **src_sp, char **dest_sp)
constexpr size_t REGISTERS_SIZE
constexpr size_t STACK_SIZE
class register implement
Definition arena_queue.h:37
void ctx_swap(void **, void **) asm("ctx_swap")