openharmony 鸿蒙 capi-fiber-h

2026-08-25 浏览 (1)

fiber.h

Overview

A fiber is a lightweight user mode thread that enables efficient task scheduling and context switching within the user space. The fiber.h file declares the related APIs in C.

File to include: <ffrt/fiber.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 20

Related module: FFRT

Summary

Function

NameDescription
FFRT_C_API int ffrt_fiber_init(ffrt_fiber_t* fiber, void(*func)(void*), void* arg, void* stack, size_t stack_size)Initializes a fiber. The initialized fiber instance can store contexts.
FFRT_C_API void ffrt_fiber_switch(ffrt_fiber_t* from, ffrt_fiber_t* to)Switches between fibers. The thread that calls this function suspends the current task, saves the context to the from fiber, and restores the context of the to fiber.

Function Description

ffrt_fiber_init()

FFRT_C_API int ffrt_fiber_init(ffrt_fiber_t* fiber, void(*func)(void*), void* arg, void* stack, size_t stack_size)

Description

Initializes a fiber. The initialized fiber instance can store contexts.

Since: 20

Parameters

NameDescription
fiberPointer to the fiber to be initialized. For details, see ffrt_fiber_t.
funcMethod to be executed after fiber switching.
void* argPointer to the argument of the method.
void* stackPointer to the fiber stack memory.
size_t stack_sizeFiber stack size. For details, see ffrt_storage_size_t.

Returns

TypeDescription
FFRT_C_API intIf the initialization is successful, ffrt_success is returned. Otherwise, ffrt_error is returned.

ffrt_fiber_switch()

FFRT_C_API void ffrt_fiber_switch(ffrt_fiber_t* from, ffrt_fiber_t* to)

Description

Switches between fibers. The thread that calls this function suspends the current task, saves the context to the from fiber, and restores the context of the to fiber.

Since: 20

Parameters

NameDescription
ffrt_fiber_t* fromPointer to the fiber to be saved.
ffrt_fiber_t* toPointer to the fiber to be restored.

你可能感兴趣的鸿蒙文章

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

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

openharmony 鸿蒙 capi-loop-h

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/xSBrbn1Y