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
| Name | Description |
|---|---|
| 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
| Name | Description |
|---|---|
| ffrt_qos_t qos | QoS. |
| uint64_t timeout | Timeout, in milliseconds. |
| void* data | Pointer to the input parameter in the callback function invoked upon a timeout. |
| ffrt_timer_cb cb | Callback function invoked upon a timeout. |
| bool repeat | Whether to repeat the timer (not supported yet). |
Returns
| Type | Description |
|---|---|
| FFRT_C_API ffrt_timer_t | Returns 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
| Name | Description |
|---|---|
| ffrt_qos_t qos | QoS. |
| ffrt_timer_t handle | Handle to the timer. |
Returns
| Type | Description |
|---|---|
| FFRT_C_API int | Returns 0 if the timer is stopped successfully; returns -1 otherwise. |