Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
5ef898c1
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5ef898c1
编写于
8月 26, 2023
作者:
W
wangyulie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code warning
Signed-off-by:
N
wangyulie
<
wanglieyu@126.com
>
上级
16d27f67
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
127 addition
and
52 deletion
+127
-52
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/BUILD.gn
...esourceschedule_standard/ffrt/entry/src/main/cpp/BUILD.gn
+4
-6
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/ffrtndk.cpp
...urceschedule_standard/ffrt/entry/src/main/cpp/ffrtndk.cpp
+98
-39
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/types/libffrtndk/index.d.ts
...ndard/ffrt/entry/src/main/cpp/types/libffrtndk/index.d.ts
+3
-1
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/ets/test/Ffrt.test.ets
...edule_standard/ffrt/entry/src/main/ets/test/Ffrt.test.ets
+22
-6
未找到文件。
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/BUILD.gn
浏览文件 @
5ef898c1
...
@@ -31,13 +31,11 @@ config("public_config") {
...
@@ -31,13 +31,11 @@ config("public_config") {
ohos_shared_library("ffrtndk") {
ohos_shared_library("ffrtndk") {
sources = [ "./ffrtndk.cpp" ]
sources = [ "./ffrtndk.cpp" ]
if (!(product_name == "m40")) {
libs = [ rebase_path(libcxx_ndk_shared_file) ]
libs = [ rebase_path(libcxx_ndk_shared_file) ]
}
include_dirs = [
include_dirs = [
"./",
"./",
"
/
/foundation/resourceschedule/ffrt/interfaces/kits",
"
../../../../../../../../../..
/foundation/resourceschedule/ffrt/interfaces/kits",
]
]
configs = [ ":config" ]
configs = [ ":config" ]
...
@@ -50,7 +48,7 @@ ohos_shared_library("ffrtndk") {
...
@@ -50,7 +48,7 @@ ohos_shared_library("ffrtndk") {
]
]
deps = [
deps = [
"
/
/foundation/resourceschedule/ffrt:ffrt_ndk",
"
../../../../../../../../../..
/foundation/resourceschedule/ffrt:ffrt_ndk",
]
]
output_extension = "so"
output_extension = "so"
...
...
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/ffrtndk.cpp
浏览文件 @
5ef898c1
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#include <string>
#include <string>
#include <unistd.h>
#include <unistd.h>
void
my_p
rint
(
void
*
arg
)
void
MyP
rint
(
void
*
arg
)
{
{
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"%{public}s"
,
"hello ffrt
\n
"
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"%{public}s"
,
"hello ffrt
\n
"
);
}
}
...
@@ -48,17 +48,17 @@ typedef struct {
...
@@ -48,17 +48,17 @@ typedef struct {
ffrt_function_t
func
;
ffrt_function_t
func
;
ffrt_function_t
after_func
;
ffrt_function_t
after_func
;
void
*
arg
;
void
*
arg
;
}
c_f
unction
;
}
CF
unction
;
typedef
struct
{
typedef
struct
{
ffrt_cond_t
*
cond
;
ffrt_cond_t
*
cond
;
int
*
a
;
int
*
a
;
ffrt_mutex_t
*
lock_
;
ffrt_mutex_t
*
lock_
;
}
t
uple
;
}
FfrtT
uple
;
void
f
unc1
(
void
*
arg
)
void
F
unc1
(
void
*
arg
)
{
{
tuple
*
t
=
(
t
uple
*
)
arg
;
FfrtTuple
*
t
=
(
FfrtT
uple
*
)
arg
;
int
ret
=
ffrt_mutex_lock
(
t
->
lock_
);
int
ret
=
ffrt_mutex_lock
(
t
->
lock_
);
if
(
ret
!=
ffrt_success
)
{
if
(
ret
!=
ffrt_success
)
{
printf
(
"error
\n
"
);
printf
(
"error
\n
"
);
...
@@ -81,9 +81,9 @@ void func1(void* arg)
...
@@ -81,9 +81,9 @@ void func1(void* arg)
printf
(
"a = %d"
,
*
(
t
->
a
));
printf
(
"a = %d"
,
*
(
t
->
a
));
}
}
void
f
unc2
(
void
*
arg
)
void
F
unc2
(
void
*
arg
)
{
{
tuple
*
t
=
(
t
uple
*
)
arg
;
FfrtTuple
*
t
=
(
FfrtT
uple
*
)
arg
;
int
ret
=
ffrt_mutex_lock
(
t
->
lock_
);
int
ret
=
ffrt_mutex_lock
(
t
->
lock_
);
if
(
ret
!=
ffrt_success
)
{
if
(
ret
!=
ffrt_success
)
{
printf
(
"error
\n
"
);
printf
(
"error
\n
"
);
...
@@ -99,9 +99,9 @@ void func2(void* arg)
...
@@ -99,9 +99,9 @@ void func2(void* arg)
}
}
}
}
void
f
unc3
(
void
*
arg
)
void
F
unc3
(
void
*
arg
)
{
{
tuple
*
t
=
(
t
uple
*
)
arg
;
FfrtTuple
*
t
=
(
FfrtT
uple
*
)
arg
;
int
ret
=
ffrt_mutex_trylock
(
t
->
lock_
);
int
ret
=
ffrt_mutex_trylock
(
t
->
lock_
);
if
(
ret
!=
ffrt_success
)
{
if
(
ret
!=
ffrt_success
)
{
printf
(
"error
\n
"
);
printf
(
"error
\n
"
);
...
@@ -127,17 +127,17 @@ void func3(void* arg)
...
@@ -127,17 +127,17 @@ void func3(void* arg)
printf
(
"a = %d"
,
*
(
t
->
a
));
printf
(
"a = %d"
,
*
(
t
->
a
));
}
}
static
void
ffrt_exec_function_w
rapper
(
void
*
t
)
static
void
FfrtExecFunctionW
rapper
(
void
*
t
)
{
{
c_function
*
f
=
(
c_f
unction
*
)
t
;
CFunction
*
f
=
(
CF
unction
*
)
t
;
if
(
f
->
func
)
{
if
(
f
->
func
)
{
f
->
func
(
f
->
arg
);
f
->
func
(
f
->
arg
);
}
}
}
}
static
void
ffrt_destroy_function_w
rapper
(
void
*
t
)
static
void
FfrtDestroyFunctionW
rapper
(
void
*
t
)
{
{
c_function
*
f
=
(
c_f
unction
*
)
t
;
CFunction
*
f
=
(
CF
unction
*
)
t
;
if
(
f
->
after_func
)
{
if
(
f
->
after_func
)
{
f
->
after_func
(
f
->
arg
);
f
->
after_func
(
f
->
arg
);
}
}
...
@@ -147,30 +147,30 @@ static void ffrt_destroy_function_wrapper(void* t)
...
@@ -147,30 +147,30 @@ static void ffrt_destroy_function_wrapper(void* t)
static
inline
ffrt_function_header_t
*
ffrt_create_function_wrapper
(
const
ffrt_function_t
func
,
static
inline
ffrt_function_header_t
*
ffrt_create_function_wrapper
(
const
ffrt_function_t
func
,
const
ffrt_function_t
after_func
,
void
*
arg
,
ffrt_function_kind_t
kind_t
=
ffrt_function_kind_general
)
const
ffrt_function_t
after_func
,
void
*
arg
,
ffrt_function_kind_t
kind_t
=
ffrt_function_kind_general
)
{
{
FFRT_STATIC_ASSERT
(
sizeof
(
c_f
unction
)
<=
ffrt_auto_managed_function_storage_size
,
FFRT_STATIC_ASSERT
(
sizeof
(
CF
unction
)
<=
ffrt_auto_managed_function_storage_size
,
size_of_function_must_be_less_than_ffrt_auto_managed_function_storage_size
);
size_of_function_must_be_less_than_ffrt_auto_managed_function_storage_size
);
c_function
*
f
=
(
c_f
unction
*
)
ffrt_alloc_auto_managed_function_storage_base
(
kind_t
);
CFunction
*
f
=
(
CF
unction
*
)
ffrt_alloc_auto_managed_function_storage_base
(
kind_t
);
f
->
header
.
exec
=
ffrt_exec_function_w
rapper
;
f
->
header
.
exec
=
FfrtExecFunctionW
rapper
;
f
->
header
.
destroy
=
ffrt_destroy_function_w
rapper
;
f
->
header
.
destroy
=
FfrtDestroyFunctionW
rapper
;
f
->
func
=
func
;
f
->
func
=
func
;
f
->
after_func
=
after_func
;
f
->
after_func
=
after_func
;
f
->
arg
=
arg
;
f
->
arg
=
arg
;
return
(
ffrt_function_header_t
*
)
f
;
return
(
ffrt_function_header_t
*
)
f
;
}
}
static
inline
void
ffrt_submit_c
(
ffrt_function_t
func
,
const
ffrt_function_t
after_func
,
static
inline
void
ffrt_submit_c
(
ffrt_function_t
func
,
void
*
arg
,
void
*
arg
,
const
ffrt_deps_t
*
in_deps
,
const
ffrt_deps_t
*
out_deps
,
const
ffrt_task_attr_t
*
attr
)
const
ffrt_deps_t
*
in_deps
,
const
ffrt_deps_t
*
out_deps
,
const
ffrt_task_attr_t
*
attr
)
{
{
ffrt_submit_base
(
ffrt_create_function_wrapper
(
func
,
after_func
,
arg
),
in_deps
,
out_deps
,
attr
);
ffrt_submit_base
(
ffrt_create_function_wrapper
(
func
,
NULL
,
arg
),
in_deps
,
out_deps
,
attr
);
}
}
static
inline
ffrt_task_handle_t
ffrt_submit_h_c
(
ffrt_function_t
func
,
const
ffrt_function_t
after_func
,
static
inline
ffrt_task_handle_t
ffrt_submit_h_c
(
ffrt_function_t
func
,
void
*
arg
,
void
*
arg
,
const
ffrt_deps_t
*
in_deps
,
const
ffrt_deps_t
*
out_deps
,
const
ffrt_task_attr_t
*
attr
)
const
ffrt_deps_t
*
in_deps
,
const
ffrt_deps_t
*
out_deps
,
const
ffrt_task_attr_t
*
attr
)
{
{
return
ffrt_submit_h_base
(
ffrt_create_function_wrapper
(
func
,
after_func
,
arg
),
in_deps
,
out_deps
,
attr
);
return
ffrt_submit_h_base
(
ffrt_create_function_wrapper
(
func
,
NULL
,
arg
),
in_deps
,
out_deps
,
attr
);
}
}
void
ffrt_cv_t
ask
(
void
*
arg
)
void
FfrtCvT
ask
(
void
*
arg
)
{
{
int
*
a
=
(
int
*
)
arg
;
int
*
a
=
(
int
*
)
arg
;
ffrt_cond_t
cond
;
ffrt_cond_t
cond
;
...
@@ -179,19 +179,22 @@ void ffrt_cv_task(void* arg)
...
@@ -179,19 +179,22 @@ void ffrt_cv_task(void* arg)
printf
(
"error
\n
"
);
printf
(
"error
\n
"
);
}
}
ffrt_mutex_t
lock_
;
ffrt_mutex_t
lock_
;
t
uple
t
=
{
&
cond
,
a
,
&
lock_
};
FfrtT
uple
t
=
{
&
cond
,
a
,
&
lock_
};
ret
=
ffrt_mutex_init
(
&
lock_
,
NULL
);
ret
=
ffrt_mutex_init
(
&
lock_
,
NULL
);
if
(
ret
!=
ffrt_success
)
{
if
(
ret
!=
ffrt_success
)
{
printf
(
"error
\n
"
);
printf
(
"error
\n
"
);
}
}
ffrt_submit_c
(
func1
,
NULL
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
Func1
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
func2
,
NULL
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
Func2
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
func3
,
NULL
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
Func3
,
&
t
,
NULL
,
NULL
,
NULL
);
ffrt_wait
();
ffrt_wait
();
ffrt_cond_destroy
(
&
cond
);
ffrt_cond_destroy
(
&
cond
);
ffrt_mutex_destroy
(
&
lock_
);
ffrt_mutex_destroy
(
&
lock_
);
}
}
/**
* add simple ffrt task submit example
*/
static
napi_value
SubmitSimpleFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
static
napi_value
SubmitSimpleFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
{
{
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"%{public}s"
,
"ffrt start
\n
"
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"%{public}s"
,
"ffrt start
\n
"
);
...
@@ -206,7 +209,7 @@ static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
...
@@ -206,7 +209,7 @@ static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
ffrt_task_attr_set_qos
(
&
attr
,
static_cast
<
ffrt_qos_t
>
(
ffrt_qos_user_initiated
));
ffrt_task_attr_set_qos
(
&
attr
,
static_cast
<
ffrt_qos_t
>
(
ffrt_qos_user_initiated
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos2 is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos2 is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
ffrt_submit_c
(
my_print
,
NULL
,
NULL
,
NULL
,
NULL
,
&
attr
);
ffrt_submit_c
(
MyPrint
,
NULL
,
NULL
,
NULL
,
&
attr
);
int
result
=
ffrt_this_task_update_qos
(
static_cast
<
ffrt_qos_t
>
(
ffrt_qos_default
));
int
result
=
ffrt_this_task_update_qos
(
static_cast
<
ffrt_qos_t
>
(
ffrt_qos_default
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"update_qos result is %{public}d"
,
result
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"update_qos result is %{public}d"
,
result
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos3 is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"qos3 is %{public}d"
,
ffrt_task_attr_get_qos
(
&
attr
));
...
@@ -223,8 +226,8 @@ static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
...
@@ -223,8 +226,8 @@ static napi_value SubmitSimpleFfrtTask(napi_env env, napi_callback_info info)
static
napi_value
SubmitCondFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
static
napi_value
SubmitCondFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
{
{
int
a
=
0
;
int
a
=
0
;
ffrt_submit_c
(
ffrt_cv_task
,
NULL
,
&
a
,
NULL
,
NULL
,
NULL
);
ffrt_submit_c
(
FfrtCvTask
,
&
a
,
NULL
,
NULL
,
NULL
);
ffrt_task_handle_t
task1
=
ffrt_submit_h_c
(
my_print
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
ffrt_task_handle_t
task1
=
ffrt_submit_h_c
(
MyPrint
,
NULL
,
NULL
,
NULL
,
NULL
);
ffrt_wait_deps
(
nullptr
);
ffrt_wait_deps
(
nullptr
);
ffrt_wait
();
ffrt_wait
();
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"cond task a is %{public}d"
,
a
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"cond task a is %{public}d"
,
a
);
...
@@ -234,6 +237,9 @@ static napi_value SubmitCondFfrtTask(napi_env env, napi_callback_info info)
...
@@ -234,6 +237,9 @@ static napi_value SubmitCondFfrtTask(napi_env env, napi_callback_info info)
return
flag
;
return
flag
;
}
}
/**
* add simple ffrt queue task submit example
*/
static
napi_value
SubmitQueueFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
static
napi_value
SubmitQueueFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
{
{
int
a
=
0
;
int
a
=
0
;
...
@@ -241,17 +247,20 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
...
@@ -241,17 +247,20 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
ffrt_queue_attr_t
queue_attr
;
ffrt_queue_attr_t
queue_attr
;
(
void
)
ffrt_queue_attr_init
(
&
queue_attr
);
(
void
)
ffrt_queue_attr_init
(
&
queue_attr
);
ffrt_queue_attr_set_qos
(
&
queue_attr
,
ffrt_qos_default
);
ffrt_queue_attr_set_qos
(
&
queue_attr
,
ffrt_qos_default
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task qos is %{public}d"
,
ffrt_queue_attr_get_qos
(
&
queue_attr
));
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task qos is %{public}d"
,
ffrt_queue_attr_get_qos
(
&
queue_attr
));
ffrt_queue_attr_set_timeout
(
&
queue_attr
,
10000
);
ffrt_queue_attr_set_timeout
(
&
queue_attr
,
10000
);
ffrt_queue_attr_get_timeout
(
&
queue_attr
);
ffrt_queue_attr_get_timeout
(
&
queue_attr
);
ffrt_queue_attr_set_callback
(
&
queue_attr
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
b
,
ffrt_function_kind_queue
));
ffrt_queue_attr_set_callback
(
&
queue_attr
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
b
,
ffrt_function_kind_queue
));
ffrt_queue_attr_get_callback
(
&
queue_attr
);
ffrt_queue_attr_get_callback
(
&
queue_attr
);
ffrt_queue_t
queue_handle
=
ffrt_queue_create
(
ffrt_queue_serial
,
"test_queue"
,
&
queue_attr
);
ffrt_queue_t
queue_handle
=
ffrt_queue_create
(
ffrt_queue_serial
,
"test_queue"
,
&
queue_attr
);
ffrt_task_handle_t
task1
=
ffrt_queue_submit_h
(
queue_handle
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_task_handle_t
task1
=
ffrt_queue_submit_h
(
queue_handle
,
ffrt_queue_cancel
(
task1
);
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_queue_wait
(
task1
);
ffrt_queue_submit
(
queue_handle
,
ffrt_queue_submit
(
queue_handle
,
ffrt_create_function_wrapper
(
MulipleForTest
,
nullptr
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_create_function_wrapper
(
MulipleForTest
,
nullptr
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_queue_submit
(
queue_handle
,
ffrt_create_function_wrapper
(
SubForTest
,
nullptr
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_queue_submit
(
queue_handle
,
ffrt_create_function_wrapper
(
SubForTest
,
nullptr
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
sleep
(
2
);
sleep
(
2
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task a is %{public}d"
,
a
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task a is %{public}d"
,
a
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task b is %{public}d"
,
b
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"queue task b is %{public}d"
,
b
);
...
@@ -263,13 +272,63 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
...
@@ -263,13 +272,63 @@ static napi_value SubmitQueueFfrtTask(napi_env env, napi_callback_info info)
return
flag
;
return
flag
;
}
}
static
napi_value
CancelQueueFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
{
int
a
=
0
;
int
b
=
0
;
ffrt_queue_attr_t
queue_attr
;
(
void
)
ffrt_queue_attr_init
(
&
queue_attr
);
ffrt_queue_attr_set_qos
(
&
queue_attr
,
ffrt_qos_default
);
ffrt_queue_attr_set_callback
(
&
queue_attr
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
b
,
ffrt_function_kind_queue
));
ffrt_queue_t
queue_handle
=
ffrt_queue_create
(
ffrt_queue_serial
,
"test_queue"
,
&
queue_attr
);
ffrt_task_handle_t
task1
=
ffrt_queue_submit_h
(
queue_handle
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_queue_cancel
(
task1
);
sleep
(
2
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"cancel queue task a is %{public}d"
,
a
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"cancel queue task b is %{public}d"
,
b
);
napi_value
flag
=
nullptr
;
napi_create_double
(
env
,
a
,
&
flag
);
ffrt_task_handle_destroy
(
task1
);
ffrt_queue_attr_destroy
(
&
queue_attr
);
ffrt_queue_destroy
(
queue_handle
);
return
flag
;
}
static
napi_value
WaitQueueFfrtTask
(
napi_env
env
,
napi_callback_info
info
)
{
int
a
=
0
;
int
b
=
0
;
ffrt_queue_attr_t
queue_attr
;
(
void
)
ffrt_queue_attr_init
(
&
queue_attr
);
ffrt_queue_attr_set_qos
(
&
queue_attr
,
ffrt_qos_default
);
ffrt_queue_attr_set_callback
(
&
queue_attr
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
b
,
ffrt_function_kind_queue
));
ffrt_queue_t
queue_handle
=
ffrt_queue_create
(
ffrt_queue_serial
,
"test_queue"
,
&
queue_attr
);
ffrt_task_handle_t
task1
=
ffrt_queue_submit_h
(
queue_handle
,
ffrt_create_function_wrapper
(
OnePlusForTest
,
NULL
,
&
a
,
ffrt_function_kind_queue
),
nullptr
);
ffrt_queue_wait
(
task1
);
sleep
(
2
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"wait queue task a is %{public}d"
,
a
);
HiLogPrint
(
LOG_APP
,
LOG_INFO
,
1
,
"testFFRT"
,
"wait queue task b is %{public}d"
,
b
);
napi_value
flag
=
nullptr
;
napi_create_double
(
env
,
a
,
&
flag
);
ffrt_task_handle_destroy
(
task1
);
ffrt_queue_attr_destroy
(
&
queue_attr
);
ffrt_queue_destroy
(
queue_handle
);
return
flag
;
}
EXTERN_C_START
EXTERN_C_START
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
static
napi_value
Init
(
napi_env
env
,
napi_value
exports
)
{
{
napi_property_descriptor
desc
[]
=
{
napi_property_descriptor
desc
[]
=
{
{
"submitSimpleFfrtTask"
,
nullptr
,
SubmitSimpleFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"submitSimpleFfrtTask"
,
nullptr
,
SubmitSimpleFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"submitCondFfrtTask"
,
nullptr
,
SubmitCondFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"submitCondFfrtTask"
,
nullptr
,
SubmitCondFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"submitQueueFfrtTask"
,
nullptr
,
SubmitQueueFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
}
{
"submitQueueFfrtTask"
,
nullptr
,
SubmitQueueFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"cancelQueueFfrtTask"
,
nullptr
,
CancelQueueFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
},
{
"waitQueueFfrtTask"
,
nullptr
,
WaitQueueFfrtTask
,
nullptr
,
nullptr
,
nullptr
,
napi_default
,
nullptr
}
};
};
napi_define_properties
(
env
,
exports
,
sizeof
(
desc
)
/
sizeof
(
desc
[
0
]),
desc
);
napi_define_properties
(
env
,
exports
,
sizeof
(
desc
)
/
sizeof
(
desc
[
0
]),
desc
);
return
exports
;
return
exports
;
...
...
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/cpp/types/libffrtndk/index.d.ts
浏览文件 @
5ef898c1
export
const
submitSimpleFfrtTask
:
()
=>
number
;
export
const
submitSimpleFfrtTask
:
()
=>
number
;
export
const
submitCondFfrtTask
:
()
=>
number
;
export
const
submitCondFfrtTask
:
()
=>
number
;
export
const
submitQueueFfrtTask
:
()
=>
number
;
export
const
submitQueueFfrtTask
:
()
=>
number
;
export
const
cancelQueueFfrtTask
:
()
=>
number
;
export
const
waitQueueFfrtTask
:
()
=>
number
;
\ No newline at end of file
resourceschedule/resourceschedule_standard/ffrt/entry/src/main/ets/test/Ffrt.test.ets
浏览文件 @
5ef898c1
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "@ohos/hypium"
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "@ohos/hypium"
import ffrtndk from 'libffrtndk.so';
import ffrtndk from 'libffrtndk.so';
export default function ffrtTest() {
export default function ffrtTest() {
describe('Acts
Ability
Test', function () {
describe('Acts
Ffrt
Test', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
beforeAll(function () {
// Presets an action, which is performed only once before all test cases of the test suite start.
// Presets an action, which is performed only once before all test cases of the test suite start.
...
@@ -35,14 +35,30 @@ export default function ffrtTest() {
...
@@ -35,14 +35,30 @@ export default function ffrtTest() {
// Presets a clear action, which is performed after all test cases of the test suite end.
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
// This API supports only one parameter: clear action function.
})
})
it('
assertContain
',0, function () {
it('
submitSimpleFfrtTask
',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
var flag = ffrtndk.submitSimpleFfrtTask();
var flag = ffrtndk.submitSimpleFfrtTask();
var flag2 = ffrtndk.submitCondFfrtTask();
var flag3 = ffrtndk.submitQueueFfrtTask();
expect(flag).assertEqual(1);
expect(flag).assertEqual(1);
expect(flag2).assertEqual(3);
})
expect(flag3).assertEqual(-1);
it('submitCondFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
var flag = ffrtndk.submitCondFfrtTask();
expect(flag).assertEqual(3);
})
it('submitQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
var flag = ffrtndk.submitQueueFfrtTask();
expect(flag).assertEqual(9);
})
it('cancelQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
var flag = ffrtndk.cancelQueueFfrtTask();
expect(flag).assertEqual(0);
})
it('waitQueueFfrtTask',0, function () {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
var flag = ffrtndk.waitQueueFfrtTask();
expect(flag).assertEqual(1);
})
})
})
})
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录