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
26
extern
"C"
{
27
extern
void
ctx_swap
(
void
**,
void
**)
asm
(
"ctx_swap"
);
28
};
29
30
namespace
apollo
{
31
namespace
cyber {
32
namespace
croutine {
33
34
constexpr
size_t
STACK_SIZE
= 2 * 1024 * 1024;
35
#if defined __aarch64__
36
constexpr
size_t
REGISTERS_SIZE
= 160;
37
#else
38
constexpr
size_t
REGISTERS_SIZE
= 56;
39
#endif
40
41
typedef
void (*
func
)(
void
*);
42
struct
RoutineContext
{
43
char
stack
[
STACK_SIZE
];
44
char
*
sp
=
nullptr
;
45
#if defined __aarch64__
46
} __attribute__((aligned(16)));
47
#else
48
};
49
#endif
50
51
void
MakeContext(
const
func& f1,
const
void
* arg, RoutineContext* ctx);
52
53
inline
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_
log.h
apollo::cyber::croutine::SwapContext
void SwapContext(char **src_sp, char **dest_sp)
Definition
routine_context.h:53
apollo::cyber::croutine::func
void(* func)(void *)
Definition
routine_context.h:41
apollo::cyber::croutine::REGISTERS_SIZE
constexpr size_t REGISTERS_SIZE
Definition
routine_context.h:38
apollo::cyber::croutine::STACK_SIZE
constexpr size_t STACK_SIZE
Definition
routine_context.h:34
apollo
class register implement
Definition
arena_queue.h:37
ctx_swap
void ctx_swap(void **, void **) asm("ctx_swap")
apollo::cyber::croutine::RoutineContext
Definition
routine_context.h:42
apollo::cyber::croutine::RoutineContext::stack
char stack[STACK_SIZE]
Definition
routine_context.h:43
apollo::cyber::croutine::RoutineContext::sp
char * sp
Definition
routine_context.h:44
cyber
croutine
detail
routine_context.h