openharmony 鸿蒙 capi-loop-h

2026-08-25 浏览 (1)

loop.h

Overview

The loop.h file declares the loop APIs in C.

File to include: <ffrt/loop.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 12

Related module: FFRT

Summary

Structs

NameDescription
ffrt_loop_tDefines the handle to a loop.

Function

NameDescription
FFRT_C_API ffrt_loop_t ffrt_loop_create(ffrt_queue_t queue)Creates a loop.
FFRT_C_API int ffrt_loop_destroy(ffrt_loop_t loop)Destroys a loop.
FFRT_C_API int ffrt_loop_run(ffrt_loop_t loop)Runs a loop.
FFRT_C_API void ffrt_loop_stop(ffrt_loop_t loop)Stops a loop.
FFRT_C_API int ffrt_loop_epoll_ctl(ffrt_loop_t loop, int op, int fd, uint32_t events, void *data, ffrt_poller_cb cb)Manages listening events on a loop.
You are not advised to call the exit function in cb. Otherwise, undefined behavior may occur.
FFRT_C_API ffrt_timer_t ffrt_loop_timer_start(ffrt_loop_t loop, uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat)Starts the timer on a loop.
You are not advised to call the exit function in cb. Otherwise, undefined behavior may occur.
FFRT_C_API int ffrt_loop_timer_stop(ffrt_loop_t loop, ffrt_timer_t handle)Stops the timer on a loop.

Function Description

ffrt_loop_create()

FFRT_C_API ffrt_loop_t ffrt_loop_create(ffrt_queue_t queue)

Description

Creates a loop.

Since: 12

Parameters

NameDescription
ffrt_queue_t queueConcurrent queue.

Returns

TypeDescription
FFRT_C_API ffrt_loop_tReturns the ffrt_loop_t object if the loop is created;
returns a null pointer otherwise.

ffrt_loop_destroy()

FFRT_C_API int ffrt_loop_destroy(ffrt_loop_t loop)

Description

Destroys a loop.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the loop is destroyed;
returns -1 otherwise.

ffrt_loop_run()

FFRT_C_API int ffrt_loop_run(ffrt_loop_t loop)

Description

Runs a loop.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the loop runs successfully;
returns -1 otherwise.

ffrt_loop_stop()

FFRT_C_API void ffrt_loop_stop(ffrt_loop_t loop)

Description

Stops a loop.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.

ffrt_loop_epoll_ctl()

FFRT_C_API int ffrt_loop_epoll_ctl(ffrt_loop_t loop, int op, int fd, uint32_t events, void *data, ffrt_poller_cb cb)

Description

Manages listening events on a loop.

You are not advised to call the exit function in cb. Otherwise, undefined behavior may occur.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.
int opOperation to be performed.
int fdFile descriptor.
uint32_t eventsEvent.
void *dataPointer to the input parameter in the callback function invoked upon event changes.
ffrt_poller_cb cbCallback function invoked upon event changes.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the operation is successful;
returns -1 otherwise.

ffrt_loop_timer_start()

FFRT_C_API ffrt_timer_t ffrt_loop_timer_start(ffrt_loop_t loop, uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat)

Description

Starts the timer on a loop.

You are not advised to call the exit function in cb. Otherwise, undefined behavior may occur.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.
uint64_t timeoutTimeout, in milliseconds.
void* dataPointer to the input parameter in the callback function invoked upon event changes.
ffrt_timer_cb cbCallback function invoked upon event changes.
bool repeatWhether to repeat the timer.

Returns

TypeDescription
FFRT_C_API ffrt_timer_tReturns the timer handle.

ffrt_loop_timer_stop()

FFRT_C_API int ffrt_loop_timer_stop(ffrt_loop_t loop, ffrt_timer_t handle)

Description

Stops the timer on a loop.

Since: 12

Parameters

NameDescription
ffrt_loop_t loopLoop object.
ffrt_timer_t handleTimer handle.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the operation is successful;
returns -1 otherwise.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-fiber-h

openharmony 鸿蒙 capi-ffrt-ffrt-mutex-t

openharmony 鸿蒙 capi-ffrt-ffrt-rwlockattr-t

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 capi-ffrt-ffrt-rwlock-t

openharmony 鸿蒙 capi-shared-mutex-h

openharmony 鸿蒙 capi-ffrt-ffrt-queue-attr-t

openharmony 鸿蒙 capi-ffrt

openharmony 鸿蒙 capi-ffrt-ffrt-fiber-t

openharmony 鸿蒙 capi-ffrt-ffrt-task-handle-t

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/z5EWOgjs