|
1 | 1 | /* |
2 | | - * Copyright (c) 2006-2023, RT-Thread Development Team |
| 2 | + * Copyright (c) 2006-2024 RT-Thread Development Team |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | * |
@@ -546,16 +546,100 @@ static int timerfd_do_gettime(int fd, struct itimerspec *cur) |
546 | 546 | return 0; |
547 | 547 | } |
548 | 548 |
|
| 549 | +/** |
| 550 | + * @brief Creates a file descriptor for a timer. |
| 551 | + * |
| 552 | + * The `timerfd_create` function creates a new timer object that generates |
| 553 | + * timer expiration notifications via a file descriptor. |
| 554 | + * |
| 555 | + * @param clockid The clock ID that specifies the clock to be used as the |
| 556 | + * timing base for the timer. Common values include: |
| 557 | + * - `CLOCK_REALTIME`: A system-wide clock representing |
| 558 | + * wall-clock time. |
| 559 | + * - `CLOCK_MONOTONIC`: A clock that cannot be set and |
| 560 | + * represents monotonic time since some unspecified |
| 561 | + * starting point. |
| 562 | + * @param flags A bitmask that can include the following flags: |
| 563 | + * - `TFD_CLOEXEC`: Close the file descriptor on `execve`. |
| 564 | + * - `TFD_NONBLOCK`: Set the file descriptor to non-blocking mode. |
| 565 | + * |
| 566 | + * @return On success, returns a file descriptor for the timer. On error, |
| 567 | + * returns -1 and sets `errno` appropriately. |
| 568 | + * |
| 569 | + * @note The file descriptor can be used with select, poll, or epoll to wait |
| 570 | + * for timer expirations. |
| 571 | + * |
| 572 | + * @warning The timerfd interface is Linux-specific and may not be available |
| 573 | + * on other operating systems. |
| 574 | + * |
| 575 | + * @see timerfd_settime, timerfd_gettime |
| 576 | + */ |
549 | 577 | int timerfd_create(int clockid, int flags) |
550 | 578 | { |
551 | 579 | return timerfd_do_create(clockid, flags); |
552 | 580 | } |
553 | 581 |
|
| 582 | +/** |
| 583 | + * @brief Sets the time for a timer file descriptor. |
| 584 | + * |
| 585 | + * The `timerfd_settime` function starts or modifies the timer associated |
| 586 | + * with the specified timer file descriptor. |
| 587 | + * |
| 588 | + * @param fd The file descriptor of the timer, obtained from |
| 589 | + * `timerfd_create`. |
| 590 | + * @param flags Flags that control the behavior of the timer. Possible |
| 591 | + * values include: |
| 592 | + * - `0`: Relative time is specified in `new`. |
| 593 | + * - `TFD_TIMER_ABSTIME`: Use absolute time instead of |
| 594 | + * relative time. |
| 595 | + * @param new A pointer to a `itimerspec` structure that specifies the |
| 596 | + * new timer settings: |
| 597 | + * - `it_value`: The initial expiration time. A zero value |
| 598 | + * means the timer is disabled. |
| 599 | + * - `it_interval`: The interval for periodic timers. A zero |
| 600 | + * value means the timer is not periodic. |
| 601 | + * @param old A pointer to a `itimerspec` structure to store the |
| 602 | + * previous timer settings. Can be `NULL` if this information |
| 603 | + * is not needed. |
| 604 | + * |
| 605 | + * @return On success, returns 0. On error, returns -1 and sets `errno` |
| 606 | + * appropriately. |
| 607 | + * |
| 608 | + * @note The timer starts counting down immediately after this call if |
| 609 | + * `it_value` is non-zero. |
| 610 | + * |
| 611 | + * @warning If the timer is set to a very short interval, high-frequency |
| 612 | + * events may impact system performance. |
| 613 | + * |
| 614 | + * @see timerfd_create, timerfd_gettime |
| 615 | + */ |
554 | 616 | int timerfd_settime(int fd, int flags, const struct itimerspec *new, struct itimerspec *old) |
555 | 617 | { |
556 | 618 | return timerfd_do_settime(fd, flags, new, old); |
557 | 619 | } |
558 | 620 |
|
| 621 | +/** |
| 622 | + * @brief Retrieves the current value and interval of a timer. |
| 623 | + * |
| 624 | + * The `timerfd_gettime` function queries the settings of the timer associated |
| 625 | + * with the specified timer file descriptor. |
| 626 | + * |
| 627 | + * @param fd The file descriptor of the timer, obtained from `timerfd_create`. |
| 628 | + * @param cur A pointer to a `itimerspec` structure where the current timer |
| 629 | + * settings will be stored: |
| 630 | + * - `it_value`: The time remaining until the next expiration. |
| 631 | + * If zero, the timer is disabled. |
| 632 | + * - `it_interval`: The interval for periodic timers. Zero if the |
| 633 | + * timer is not periodic. |
| 634 | + * |
| 635 | + * @return On success, returns 0. On error, returns -1 and sets `errno` |
| 636 | + * appropriately. |
| 637 | + * |
| 638 | + * @note This function does not reset or modify the timer; it only retrieves |
| 639 | + * the current settings. |
| 640 | + * |
| 641 | + * @see timerfd_create, timerfd_settime |
| 642 | + */ |
559 | 643 | int timerfd_gettime(int fd, struct itimerspec *cur) |
560 | 644 | { |
561 | 645 | return timerfd_do_gettime(fd, cur); |
|
0 commit comments