• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FFRT_TASK_WRAPPER_H
17 #define FFRT_TASK_WRAPPER_H
18 
19 #include "c/type_def.h"
20 #include "c/task.h"
21 
22 typedef struct {
23     ffrt_function_header_t header;
24     ffrt_function_t func;
25     ffrt_function_t after_func;
26     void* arg;
27 } ffrt_function_wrapper_t;
28 
ffrt_exec_function_wrapper(void * t)29 static inline void ffrt_exec_function_wrapper(void* t)
30 {
31     ffrt_function_wrapper_t* f = (ffrt_function_wrapper_t *)t;
32     if (f->func) {
33         f->func(f->arg);
34     }
35 }
36 
ffrt_destroy_function_wrapper(void * t)37 static inline void ffrt_destroy_function_wrapper(void* t)
38 {
39     ffrt_function_wrapper_t* f = (ffrt_function_wrapper_t *)t;
40     if (f->after_func) {
41         f->after_func(f->arg);
42     }
43 }
44 
45 #define FFRT_STATIC_ASSERT(cond, msg) int x(int static_assertion_##msg[(cond) ? 1 : -1])
ffrt_create_function_wrapper(ffrt_function_t func,ffrt_function_t after_func,void * arg,ffrt_function_kind_t kind)46 static inline ffrt_function_header_t *ffrt_create_function_wrapper(ffrt_function_t func, ffrt_function_t after_func,
47     void* arg, ffrt_function_kind_t kind)
48 {
49     FFRT_STATIC_ASSERT(sizeof(ffrt_function_wrapper_t) <= ffrt_auto_managed_function_storage_size,
50         size_of_function_must_be_less_than_ffrt_auto_managed_function_storage_size);
51 
52     ffrt_function_wrapper_t* f = (ffrt_function_wrapper_t *)ffrt_alloc_auto_managed_function_storage_base(kind);
53     f->header.exec = ffrt_exec_function_wrapper;
54     f->header.destroy = ffrt_destroy_function_wrapper;
55     f->func = func;
56     f->after_func = after_func;
57     f->arg = arg;
58     return reinterpret_cast<ffrt_function_header_t *>(f);
59 }
60 
61 #endif