nuttx/sched/event/event_clear.c
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

71 lines
2.4 KiB
C

/****************************************************************************
* sched/event/event_clear.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/sched.h>
#include "event.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxevent_clear
*
* Description:
* Clear specific bits from the event mask of the given event object.
*
* Input Parameters:
* event - Address of the event object
* mask - Bit mask specifying which event flags should be cleared
*
* Returned Value:
* Returns the previous event mask value of the event object before
* applying the clear operation.
*
* Notes:
* - This is an internal OS interface and must not be invoked directly
* by user applications.
* - This function is safe to call from an interrupt handler.
*
****************************************************************************/
nxevent_mask_t nxevent_clear(FAR nxevent_t *event, nxevent_mask_t mask)
{
nxevent_mask_t events;
irqstate_t flags;
DEBUGASSERT(event != NULL);
flags = enter_critical_section();
events = event->events;
event->events &= ~mask;
leave_critical_section(flags);
return events;
}