• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_COROUTINES_STACKFUL_COMMON_H
17 #define PANDA_RUNTIME_COROUTINES_STACKFUL_COMMON_H
18 
19 #include "libpandabase/globals.h"
20 
21 namespace ark::stackful_coroutines {
22 
23 // every bit means that the corresponding worker is allowed
24 using AffinityMask = size_t;
25 // all ones
26 inline constexpr AffinityMask AFFINITY_MASK_FULL = std::numeric_limits<AffinityMask>::max();
27 // all zeros
28 inline constexpr AffinityMask AFFINITY_MASK_NONE = 0U;
29 
30 // maximum workers count should conform to number of bits in the affinity mask
31 inline constexpr size_t MAX_WORKERS_COUNT = sizeof(AffinityMask) * BITS_PER_BYTE;
32 // maximum worker id is bound by the number of bits in the affinity mask
33 inline constexpr size_t MAX_WORKER_ID = MAX_WORKERS_COUNT - 1U;
34 // ID's type must be capable of holding values from [0 to MAX_WORKER_ID]
35 using WorkerId = size_t;
36 // must be something obviously erroneous (> MAX_WORKER_ID)
37 inline constexpr WorkerId INVALID_WORKER_ID = std::numeric_limits<WorkerId>::max();
38 // must be something easy to assign and comprehend
39 inline constexpr WorkerId MAIN_WORKER_ID = 0U;
40 
41 }  // namespace ark::stackful_coroutines
42 
43 #endif /* PANDA_RUNTIME_COROUTINES_STACKFUL_COMMON_H */
44