File indexing completed on 2025-05-11 08:24:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifdef HAVE_CONFIG_H
0039 #include "config.h"
0040 #endif
0041
0042 #include <rtems/rtems/eventimpl.h>
0043 #include <rtems/rtems/optionsimpl.h>
0044 #include <rtems/score/threadimpl.h>
0045 #include <rtems/score/watchdogimpl.h>
0046
0047 static void _Event_Satisfy(
0048 Thread_Control *the_thread,
0049 Event_Control *event,
0050 rtems_event_set pending_events,
0051 rtems_event_set seized_events
0052 )
0053 {
0054 event->pending_events = _Event_sets_Clear( pending_events, seized_events );
0055 *(rtems_event_set *) the_thread->Wait.return_argument = seized_events;
0056 }
0057
0058 static bool _Event_Is_blocking_on_event(
0059 const Thread_Control *the_thread,
0060 Thread_Wait_flags wait_class
0061 )
0062 {
0063 Thread_Wait_flags wait_flags;
0064
0065 wait_flags = _Thread_Wait_flags_get( the_thread );
0066
0067 return ( wait_flags & THREAD_WAIT_CLASS_MASK ) == wait_class;
0068 }
0069
0070 static bool _Event_Is_satisfied(
0071 const Thread_Control *the_thread,
0072 rtems_event_set pending_events,
0073 rtems_event_set *seized_events
0074 )
0075 {
0076 rtems_option option_set;
0077 rtems_event_set event_condition;
0078
0079 option_set = the_thread->Wait.option;
0080 event_condition = the_thread->Wait.count;
0081 *seized_events = _Event_sets_Get( pending_events, event_condition );
0082
0083 return !_Event_sets_Is_empty( *seized_events )
0084 && ( *seized_events == event_condition || _Options_Is_any( option_set ) );
0085 }
0086
0087 rtems_status_code _Event_Surrender(
0088 Thread_Control *the_thread,
0089 rtems_event_set event_in,
0090 Event_Control *event,
0091 Thread_Wait_flags wait_class,
0092 ISR_lock_Context *lock_context
0093 )
0094 {
0095 rtems_event_set pending_events;
0096 rtems_event_set seized_events;
0097 bool unblock;
0098
0099 _Thread_Wait_acquire_default_critical( the_thread, lock_context );
0100
0101 _Event_sets_Post( event_in, &event->pending_events );
0102 pending_events = event->pending_events;
0103
0104 if (
0105 _Event_Is_blocking_on_event( the_thread, wait_class )
0106 && _Event_Is_satisfied( the_thread, pending_events, &seized_events )
0107 ) {
0108 bool success;
0109
0110 _Event_Satisfy( the_thread, event, pending_events, seized_events );
0111
0112 success = _Thread_Wait_flags_try_change_release(
0113 the_thread,
0114 wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK,
0115 THREAD_WAIT_STATE_READY
0116 );
0117
0118 if ( success ) {
0119 unblock = false;
0120 } else {
0121 _Assert(
0122 _Thread_Wait_flags_get( the_thread )
0123 == ( wait_class | THREAD_WAIT_STATE_BLOCKED )
0124 );
0125 _Thread_Wait_flags_set( the_thread, THREAD_WAIT_STATE_READY );
0126 unblock = true;
0127 }
0128 } else {
0129 unblock = false;
0130 }
0131
0132 if ( unblock ) {
0133 Per_CPU_Control *cpu_self;
0134
0135 cpu_self = _Thread_Dispatch_disable_critical( lock_context );
0136 _Thread_Wait_release_default( the_thread, lock_context );
0137
0138 _Thread_Timer_remove( the_thread );
0139 _Thread_Unblock( the_thread );
0140
0141 _Thread_Dispatch_enable( cpu_self );
0142 } else {
0143 _Thread_Wait_release_default( the_thread, lock_context );
0144 }
0145
0146 return RTEMS_SUCCESSFUL;
0147 }