Commit graph

15 commits

Author SHA1 Message Date
wangchengdong
522f32f7ef sched/event: Fix uninitialized need_switch flag issue in event_post()
The `need_switch` flag was not initialized in `event_post()`. Since it is
    a local variable, it could contain a random non-zero value, leading to
    incorrect behavior.
    In addition, this patch also fixes an issue where the event clearing
    operation in `event_post()` was not performed correctly.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-04 21:43:59 +08:00
wangchengdong
de5973268b [!] sched/event: Remove wait object dependency from event implementation
The current event implementation relies on a dedicated wait object,
    which introduces several issues:
        1. Increases memory usage
        2. Complicates the event logic
        3. Makes the API design less clean, as it requires a separate
                nxevent_tickwait_wait() function

    This patch removes the event’s dependency on the wait object
    and eliminates the nxevent_tickwait_wait() API accordingly.

    BREAKING CHANGE: this commit removed the nxevent_tickwait_wait function
    so the related docs should be updated accordingly

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
94cfb1180b sched/event: Implement nxevent_timeout with nxevent_wait_irq
Implement nxevent_timeout with nxevent_wait_irq to remove
   code duplication

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
39f54c1524 sched/event: Add nxevent_wait_irq() to handle the task cancel
If the thread is blocked waiting on a event, then the
    thread must be unblocked from the evnet to handle
    the task cancellation.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
735e489070 [!] sched/event: Replace semaphore with direct scheduler operations in event
The current event implementation uses semaphores for wait and post
    operations. Since semaphores are relatively heavy-weight and intended
    for resource-based synchronization, this is suboptimal.

    So this patch replaced the semaphore-based mechanism with direct
    scheduler operations to improve performance and reduce memory footprint.

    This patch also introduce a new task state TSTATE_WAIT_EVENT to indicate
    the task is waiting for a event.

    BREAKING CHANGE:  This commit introduced a new task state TSTATE_WAIT_EVENT
    so apps/nshlib/, procfs/ and tools/pynuttx/nxgdb/ are needed to be updated accordingly.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
5fa8634ce7 sched/event: Restore critical section protection for event wait and post
Restore the use of critical sections to provide mutual exclusion
    between event wait and post operations. This allows replacing the
    heavier semaphore-based mechanism with direct scheduler operations
    for synchronization.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
fc09640b28 sched/event: add nxevent_getmask api
In certain cases, when the event-wait thread is awakened,
  it needs to know the specific mask bit that triggered it,
  so that it can branch to different paths accordingly.
  This patch introduces the nxevent_getmask function to address this requirement.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-09 11:07:49 -03:00
wangchengdong
c0d7269840 sched/event: fix event bug after csection was removed
Change:
    Replace list_delete_init() with list_delete() in nxevent_post.
  Reason:
    PR 16933 removed list_delete() in nxevent_wait() and  allow other task
    to preempt event-wait thread after list_add_tail() option,  the even-post thread
    can preempt it at this time and do  list_delete_init().

    The problem is that list_delete_init() will make  list_in_list() return true, so
    DEBUGASSERT(!list_in_list(&(wait->node))); will fail in nxevent_wait() after the event-wait thread
    returns.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-09 15:45:48 +08:00
wangchengdong
cac1cc896a sched/event: add nxevent_clear api
Add nxevent_clear to clear event mask to an event object.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-08 19:48:35 +08:00
hujun5
4cea148088 sched: remove csection in event
We hope to replace the large lock with a small lock to improve concurrency performance.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-09-05 14:20:04 +08:00
wangchengdong
5676bf8227 sched/event: add a new event function nxevent_tickwait_wait
There are cases that users do not want the event wait object to be allocated automatically
  in the stack as a temporary varialbe in nxevent_tickwait, since multiple threads will
  access the varialbe, they want to allocate the object as a global variable for safety
  control or easy debug. To solve this problem, this patch add a new function nxevent_tickwait_wait
  implementation to give user the chance to  pass the global wait object to it.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-04 09:47:50 +08:00
chao an
54e85075c4 sched/event: init deleted node to avoid null pointer reference
nxevent_tickwait() will remove the node in failure case(EINTR). If the node
has been deleted in the nxevent_post(), NULL pointer reference will
be triggered after semaphore wait.

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-26 23:28:37 +08:00
Alin Jerpelea
eb9030c891 sched: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-12 01:10:14 +08:00
chao an
f084685da8 sched/event: clear pending events before enable the scheduler
enable the scheduler may cause the context to switch to a high-priority task,
which will failure to clear pending events correctly.

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-02 18:24:28 +08:00
chao an
75fac7dbc6 sched/nxevent: add support of kernel event group
Events groups are synchronization primitives that allow tasks to wait
for multiple conditions to be met before proceeding. They are particularly
useful in scenarios where a task needs to wait for several events to occur
simultaneously.

Signed-off-by: chao an <anchao@lixiang.com>
2024-08-23 17:00:35 +08:00