1 /*
2  * Copyright (c) 2023 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  /**
17  * @file type_def.h
18  *
19  * @brief Declares common types.
20  *
21  * @since 10
22  * @version 1.0
23  */
24 #ifndef FFRT_INNER_API_C_TYPE_DEF_H
25 #define FFRT_INNER_API_C_TYPE_DEF_H
26 #include <stdint.h>
27 #include "c/type_def.h"
28 
29 #ifdef __cplusplus
30 #define FFRT_C_API  extern "C"
31 #else
32 #define FFRT_C_API
33 #endif
34 
35 /**
36  * @brief Enumerates the task QoS types.
37  *
38  */
39 typedef enum {
40     ffrt_qos_deadline_request = 4,
41     ffrt_qos_user_interactive,
42     ffrt_qos_max = ffrt_qos_user_interactive,
43 } ffrt_inner_qos_default_t;
44 
45 typedef enum {
46     ffrt_stack_protect_weak,
47     ffrt_stack_protect_strong
48 } ffrt_stack_protect_t;
49 
50 typedef enum {
51     ffrt_thread_attr_storage_size = 64,
52     /* rwlock storage size. */
53     ffrt_rwlock_storage_size = 64,
54 } ffrt_inner_storage_size_t;
55 
56 typedef struct {
57     uint32_t storage[(ffrt_thread_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
58 } ffrt_thread_attr_t;
59 
60 #define MAX_CPUMAP_LENGTH 100 // this is in c and code style
61 typedef struct {
62     int shares;
63     int latency_nice;
64     int uclamp_min;
65     int uclamp_max;
66     int vip_prio;
67     char cpumap[MAX_CPUMAP_LENGTH];
68 } ffrt_os_sched_attr;
69 
70 typedef struct {
71     long storage;
72 } ffrt_rwlockattr_t;
73 
74 typedef void* ffrt_thread_t;
75 
76 typedef void* ffrt_interval_t;
77 
78 typedef enum {
79     ffrt_sys_event_type_read,
80 } ffrt_sys_event_type_t;
81 
82 typedef enum {
83     ffrt_sys_event_status_no_timeout,
84     ffrt_sys_event_status_timeout
85 } ffrt_sys_event_status_t;
86 
87 typedef void* ffrt_sys_event_handle_t;
88 
89 typedef void* ffrt_config_t;
90 
91 typedef enum {
92     ffrt_coroutine_stackless,
93     ffrt_coroutine_with_stack,
94 } ffrt_coroutine_t;
95 
96 typedef enum {
97     ffrt_coroutine_pending = 0,
98     ffrt_coroutine_ready = 1,
99 } ffrt_coroutine_ret_t;
100 
101 typedef ffrt_coroutine_ret_t(*ffrt_coroutine_ptr_t)(void*);
102 
103 typedef struct {
104     int fd;
105     void* data;
106     void(*cb)(void*, uint32_t);
107 } ffrt_poller_t;
108 
109 typedef enum {
110     ffrt_timer_notfound = -1,
111     ffrt_timer_not_executed = 0,
112     ffrt_timer_executed = 1,
113 } ffrt_timer_query_t;
114 
115 typedef struct {
116     uint32_t storage[(ffrt_rwlock_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
117 } ffrt_rwlock_t;
118 
119 #ifdef __cplusplus
120 namespace ffrt {
121 enum qos_inner_default {
122     qos_deadline_request = ffrt_qos_deadline_request,
123     qos_user_interactive = ffrt_qos_user_interactive,
124     qos_max = ffrt_qos_max,
125 };
126 
127 enum class stack_protect {
128     weak = ffrt_stack_protect_weak,
129     strong = ffrt_stack_protect_strong,
130 };
131 }
132 #endif
133 #endif
134