openharmony 鸿蒙 capi-timer-h

2026-08-25 浏览 (1)

timer.h

Overview

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

File to include: <ffrt/timer.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 12

Related module: FFRT

Summary

Function

NameDescription
FFRT_C_API ffrt_timer_t ffrt_timer_start(ffrt_qos_t qos, uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat)Starts the timer.
FFRT_C_API int ffrt_timer_stop(ffrt_qos_t qos, ffrt_timer_t handle)Stops the timer.

Function Description

ffrt_timer_start()

FFRT_C_API ffrt_timer_t ffrt_timer_start(ffrt_qos_t qos, uint64_t timeout, void* data, ffrt_timer_cb cb, bool repeat)

Description

Starts the timer.

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

Since: 12

Parameters

NameDescription
ffrt_qos_t qosQoS.
uint64_t timeoutTimeout, in milliseconds.
void* dataPointer to the input parameter in the callback function invoked upon a timeout.
ffrt_timer_cb cbCallback function invoked upon a timeout.
bool repeatWhether to repeat the timer (not supported yet).

Returns

TypeDescription
FFRT_C_API ffrt_timer_tReturns the timer handle.

ffrt_timer_stop()

FFRT_C_API int ffrt_timer_stop(ffrt_qos_t qos, ffrt_timer_t handle)

Description

Stops the timer.

NOTE

  • This is a blocking API and must not be used inside callback functions to prevent deadlocks or synchronization issues.

  • If the callback corresponding to the passed handle is being executed, this function will wait for the callback to complete before resuming its own execution.

Since: 12

Parameters

NameDescription
ffrt_qos_t qosQoS.
ffrt_timer_t handleHandle to the timer.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the timer is stopped successfully; returns -1 otherwise.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-fiber-h

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

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