mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-22 10:01:34 +08:00
score: Add _Thread_Get_interrupt_disable()
Remove _Thread_Acquire() and _Thread_Acquire_for_executing(). Add utility functions for the default thread lock. Use the default thread lock for the RTEMS events. There is no need to disable thread dispatching and a Giant acquire in _Event_Timeout() since this was already done by the caller. Update #2273.
This commit is contained in:
@@ -34,9 +34,13 @@ rtems_status_code rtems_event_receive(
|
||||
|
||||
if ( event_out != NULL ) {
|
||||
ISR_lock_Context lock_context;
|
||||
Thread_Control *executing = _Thread_Acquire_executing( &lock_context );
|
||||
RTEMS_API_Control *api = executing->API_Extensions[ THREAD_API_RTEMS ];
|
||||
Event_Control *event = &api->Event;
|
||||
Thread_Control *executing;
|
||||
RTEMS_API_Control *api;
|
||||
Event_Control *event;
|
||||
|
||||
executing = _Thread_Lock_acquire_default_for_executing( &lock_context );
|
||||
api = executing->API_Extensions[ THREAD_API_RTEMS ];
|
||||
event = &api->Event;
|
||||
|
||||
if ( !_Event_sets_Is_empty( event_in ) ) {
|
||||
_Event_Seize(
|
||||
@@ -54,7 +58,7 @@ rtems_status_code rtems_event_receive(
|
||||
sc = executing->Wait.return_code;
|
||||
} else {
|
||||
*event_out = event->pending_events;
|
||||
_Objects_Release_and_ISR_enable( &executing->Object, &lock_context );
|
||||
_Thread_Lock_release_default( executing, &lock_context );
|
||||
sc = RTEMS_SUCCESSFUL;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -57,13 +57,13 @@ void _Event_Seize(
|
||||
(seized_events == event_in || _Options_Is_any( option_set )) ) {
|
||||
event->pending_events =
|
||||
_Event_sets_Clear( pending_events, seized_events );
|
||||
_Objects_Release_and_ISR_enable( &executing->Object, lock_context );
|
||||
_Thread_Lock_release_default( executing, lock_context );
|
||||
*event_out = seized_events;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( _Options_Is_no_wait( option_set ) ) {
|
||||
_Objects_Release_and_ISR_enable( &executing->Object, lock_context );
|
||||
_Thread_Lock_release_default( executing, lock_context );
|
||||
executing->Wait.return_code = RTEMS_UNSATISFIED;
|
||||
*event_out = seized_events;
|
||||
return;
|
||||
@@ -84,19 +84,12 @@ void _Event_Seize(
|
||||
executing->Wait.return_argument = event_out;
|
||||
_Thread_Wait_flags_set( executing, intend_to_block );
|
||||
|
||||
cpu_self = _Objects_Release_and_thread_dispatch_disable(
|
||||
&executing->Object,
|
||||
lock_context
|
||||
);
|
||||
cpu_self = _Thread_Dispatch_disable_critical();
|
||||
_Thread_Lock_release_default( executing, lock_context );
|
||||
_Giant_Acquire( cpu_self );
|
||||
|
||||
if ( ticks ) {
|
||||
_Watchdog_Initialize(
|
||||
&executing->Timer,
|
||||
_Event_Timeout,
|
||||
executing->Object.id,
|
||||
NULL
|
||||
);
|
||||
_Watchdog_Initialize( &executing->Timer, _Event_Timeout, 0, executing );
|
||||
_Watchdog_Insert_ticks( &executing->Timer, ticks );
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ rtems_status_code rtems_event_send(
|
||||
RTEMS_API_Control *api;
|
||||
ISR_lock_Context lock_context;
|
||||
|
||||
thread = _Thread_Acquire( id, &location, &lock_context );
|
||||
thread = _Thread_Get_interrupt_disable( id, &location, &lock_context );
|
||||
switch ( location ) {
|
||||
case OBJECTS_LOCAL:
|
||||
api = thread->API_Extensions[ THREAD_API_RTEMS ];
|
||||
@@ -44,6 +44,7 @@ rtems_status_code rtems_event_send(
|
||||
THREAD_WAIT_CLASS_EVENT,
|
||||
&lock_context
|
||||
);
|
||||
_Objects_Put_for_get_isr_disable( &thread->Object );
|
||||
sc = RTEMS_SUCCESSFUL;
|
||||
break;
|
||||
#ifdef RTEMS_MULTIPROCESSING
|
||||
|
||||
@@ -64,6 +64,8 @@ void _Event_Surrender(
|
||||
Thread_Wait_flags wait_flags;
|
||||
bool unblock;
|
||||
|
||||
_Thread_Lock_acquire_default_critical( the_thread, lock_context );
|
||||
|
||||
_Event_sets_Post( event_in, &event->pending_events );
|
||||
pending_events = event->pending_events;
|
||||
|
||||
@@ -105,10 +107,8 @@ void _Event_Surrender(
|
||||
if ( unblock ) {
|
||||
Per_CPU_Control *cpu_self;
|
||||
|
||||
cpu_self = _Objects_Release_and_thread_dispatch_disable(
|
||||
&the_thread->Object,
|
||||
lock_context
|
||||
);
|
||||
cpu_self = _Thread_Dispatch_disable_critical();
|
||||
_Thread_Lock_release_default( the_thread, lock_context );
|
||||
_Giant_Acquire( cpu_self );
|
||||
|
||||
_Watchdog_Remove( &the_thread->Timer );
|
||||
@@ -117,6 +117,6 @@ void _Event_Surrender(
|
||||
_Giant_Release( cpu_self );
|
||||
_Thread_Dispatch_enable( cpu_self );
|
||||
} else {
|
||||
_Objects_Release_and_ISR_enable( &the_thread->Object, lock_context );
|
||||
_Thread_Lock_release_default( the_thread, lock_context );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ void _Event_Timeout(
|
||||
)
|
||||
{
|
||||
Thread_Control *the_thread;
|
||||
Objects_Locations location;
|
||||
ISR_lock_Context lock_context;
|
||||
Thread_Wait_flags wait_flags;
|
||||
Thread_Wait_flags wait_class;
|
||||
@@ -36,55 +35,36 @@ void _Event_Timeout(
|
||||
bool success;
|
||||
bool unblock;
|
||||
|
||||
the_thread = _Thread_Acquire( id, &location, &lock_context );
|
||||
switch ( location ) {
|
||||
case OBJECTS_LOCAL:
|
||||
wait_flags = _Thread_Wait_flags_get( the_thread );
|
||||
wait_class = wait_flags & THREAD_WAIT_CLASS_MASK;
|
||||
intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
|
||||
blocked = wait_class | THREAD_WAIT_STATE_BLOCKED;
|
||||
success = _Thread_Wait_flags_try_change_critical(
|
||||
the_thread,
|
||||
intend_to_block,
|
||||
wait_class | THREAD_WAIT_STATE_INTERRUPT_TIMEOUT
|
||||
);
|
||||
the_thread = arg;
|
||||
_Thread_Lock_acquire_default( the_thread, &lock_context );
|
||||
|
||||
if ( success ) {
|
||||
the_thread->Wait.return_code = RTEMS_TIMEOUT;
|
||||
unblock = false;
|
||||
} else if ( _Thread_Wait_flags_get( the_thread ) == blocked ) {
|
||||
the_thread->Wait.return_code = RTEMS_TIMEOUT;
|
||||
_Thread_Wait_flags_set(
|
||||
the_thread,
|
||||
wait_class | THREAD_WAIT_STATE_TIMEOUT
|
||||
);
|
||||
unblock = true;
|
||||
} else {
|
||||
unblock = false;
|
||||
}
|
||||
wait_flags = _Thread_Wait_flags_get( the_thread );
|
||||
wait_class = wait_flags & THREAD_WAIT_CLASS_MASK;
|
||||
intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK;
|
||||
blocked = wait_class | THREAD_WAIT_STATE_BLOCKED;
|
||||
success = _Thread_Wait_flags_try_change_critical(
|
||||
the_thread,
|
||||
intend_to_block,
|
||||
wait_class | THREAD_WAIT_STATE_INTERRUPT_TIMEOUT
|
||||
);
|
||||
|
||||
if ( unblock ) {
|
||||
Per_CPU_Control *cpu_self;
|
||||
if ( success ) {
|
||||
the_thread->Wait.return_code = RTEMS_TIMEOUT;
|
||||
unblock = false;
|
||||
} else if ( _Thread_Wait_flags_get( the_thread ) == blocked ) {
|
||||
the_thread->Wait.return_code = RTEMS_TIMEOUT;
|
||||
_Thread_Wait_flags_set(
|
||||
the_thread,
|
||||
wait_class | THREAD_WAIT_STATE_TIMEOUT
|
||||
);
|
||||
unblock = true;
|
||||
} else {
|
||||
unblock = false;
|
||||
}
|
||||
|
||||
cpu_self = _Objects_Release_and_thread_dispatch_disable(
|
||||
&the_thread->Object,
|
||||
&lock_context
|
||||
);
|
||||
_Giant_Acquire( cpu_self );
|
||||
_Thread_Lock_release_default( the_thread, &lock_context );
|
||||
|
||||
_Thread_Unblock( the_thread );
|
||||
|
||||
_Giant_Release( cpu_self );
|
||||
_Thread_Dispatch_enable( cpu_self );
|
||||
} else {
|
||||
_Objects_Release_and_ISR_enable( &the_thread->Object, &lock_context );
|
||||
}
|
||||
|
||||
break;
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
case OBJECTS_REMOTE: /* impossible */
|
||||
#endif
|
||||
case OBJECTS_ERROR:
|
||||
break;
|
||||
if ( unblock ) {
|
||||
_Thread_Unblock( the_thread );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,13 @@ rtems_status_code rtems_event_system_receive(
|
||||
|
||||
if ( event_out != NULL ) {
|
||||
ISR_lock_Context lock_context;
|
||||
Thread_Control *executing = _Thread_Acquire_executing( &lock_context );
|
||||
RTEMS_API_Control *api = executing->API_Extensions[ THREAD_API_RTEMS ];
|
||||
Event_Control *event = &api->System_event;
|
||||
Thread_Control *executing;
|
||||
RTEMS_API_Control *api;
|
||||
Event_Control *event;
|
||||
|
||||
executing = _Thread_Lock_acquire_default_for_executing( &lock_context );
|
||||
api = executing->API_Extensions[ THREAD_API_RTEMS ];
|
||||
event = &api->System_event;
|
||||
|
||||
if ( !_Event_sets_Is_empty( event_in ) ) {
|
||||
_Event_Seize(
|
||||
@@ -60,7 +64,7 @@ rtems_status_code rtems_event_system_receive(
|
||||
sc = executing->Wait.return_code;
|
||||
} else {
|
||||
*event_out = event->pending_events;
|
||||
_Objects_Release_and_ISR_enable( &executing->Object, &lock_context );
|
||||
_Thread_Lock_release_default( executing, &lock_context );
|
||||
sc = RTEMS_SUCCESSFUL;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,7 +39,7 @@ rtems_status_code rtems_event_system_send(
|
||||
RTEMS_API_Control *api;
|
||||
ISR_lock_Context lock_context;
|
||||
|
||||
thread = _Thread_Acquire( id, &location, &lock_context );
|
||||
thread = _Thread_Get_interrupt_disable( id, &location, &lock_context );
|
||||
switch ( location ) {
|
||||
case OBJECTS_LOCAL:
|
||||
api = thread->API_Extensions[ THREAD_API_RTEMS ];
|
||||
@@ -50,6 +50,7 @@ rtems_status_code rtems_event_system_send(
|
||||
THREAD_WAIT_CLASS_SYSTEM_EVENT,
|
||||
&lock_context
|
||||
);
|
||||
_Objects_Put_for_get_isr_disable( &thread->Object );
|
||||
sc = RTEMS_SUCCESSFUL;
|
||||
break;
|
||||
#ifdef RTEMS_MULTIPROCESSING
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#define _RTEMS_SCORE_THREADIMPL_H
|
||||
|
||||
#include <rtems/score/thread.h>
|
||||
#include <rtems/score/assert.h>
|
||||
#include <rtems/score/chainimpl.h>
|
||||
#include <rtems/score/interr.h>
|
||||
#include <rtems/score/isr.h>
|
||||
@@ -382,23 +383,16 @@ Thread_Control *_Thread_Get (
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Acquires a thread by its identifier.
|
||||
* @brief Gets a thread by its identifier.
|
||||
*
|
||||
* @see _Objects_Acquire().
|
||||
* @see _Objects_Get_isr_disable().
|
||||
*/
|
||||
Thread_Control *_Thread_Acquire(
|
||||
Thread_Control *_Thread_Get_interrupt_disable(
|
||||
Objects_Id id,
|
||||
Objects_Locations *location,
|
||||
ISR_lock_Context *lock_context
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Acquires the executing thread.
|
||||
*
|
||||
* @see _Objects_Acquire().
|
||||
*/
|
||||
Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context );
|
||||
|
||||
RTEMS_INLINE_ROUTINE Per_CPU_Control *_Thread_Get_CPU(
|
||||
const Thread_Control *thread
|
||||
)
|
||||
@@ -865,6 +859,80 @@ RTEMS_INLINE_ROUTINE bool _Thread_Owns_resources(
|
||||
return owns_resources;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquires the default thread lock and returns the executing thread.
|
||||
*
|
||||
* @param[in] lock_context The lock context used for the corresponding lock
|
||||
* release.
|
||||
*
|
||||
* @return The executing thread.
|
||||
*
|
||||
* @see _Thread_Lock_release_default().
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Lock_acquire_default_for_executing(
|
||||
ISR_lock_Context *lock_context
|
||||
)
|
||||
{
|
||||
Thread_Control *executing;
|
||||
|
||||
_ISR_lock_ISR_disable( lock_context );
|
||||
executing = _Thread_Executing;
|
||||
_ISR_lock_Acquire( &executing->Lock.Default, lock_context );
|
||||
|
||||
return executing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquires the default thread lock inside a critical section
|
||||
* (interrupts disabled).
|
||||
*
|
||||
* @param[in] the_thread The thread.
|
||||
* @param[in] lock_context The lock context used for the corresponding lock
|
||||
* release.
|
||||
*
|
||||
* @see _Thread_Lock_release_default().
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE void _Thread_Lock_acquire_default_critical(
|
||||
Thread_Control *the_thread,
|
||||
ISR_lock_Context *lock_context
|
||||
)
|
||||
{
|
||||
_Assert( _ISR_Get_level() != 0 );
|
||||
_ISR_lock_Acquire( &the_thread->Lock.Default, lock_context );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Acquires the default thread lock.
|
||||
*
|
||||
* @param[in] the_thread The thread.
|
||||
* @param[in] lock_context The lock context used for the corresponding lock
|
||||
* release.
|
||||
*
|
||||
* @see _Thread_Lock_release_default().
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE void _Thread_Lock_acquire_default(
|
||||
Thread_Control *the_thread,
|
||||
ISR_lock_Context *lock_context
|
||||
)
|
||||
{
|
||||
_ISR_lock_ISR_disable_and_acquire( &the_thread->Lock.Default, lock_context );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the default thread lock.
|
||||
*
|
||||
* @param[in] the_thread The thread.
|
||||
* @param[in] lock_context The lock context used for the corresponding lock
|
||||
* acquire.
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE void _Thread_Lock_release_default(
|
||||
Thread_Control *the_thread,
|
||||
ISR_lock_Context *lock_context
|
||||
)
|
||||
{
|
||||
_ISR_lock_Release_and_ISR_enable( &the_thread->Lock.Default, lock_context );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release the thread lock.
|
||||
*
|
||||
|
||||
@@ -75,22 +75,7 @@ Thread_Control *_Thread_Get(
|
||||
return (Thread_Control *) _Objects_Get( information, id, location );
|
||||
}
|
||||
|
||||
Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context )
|
||||
{
|
||||
Thread_Control *executing;
|
||||
|
||||
#if defined(RTEMS_SMP)
|
||||
_ISR_Disable_without_giant( lock_context->Lock_context.isr_level );
|
||||
#else
|
||||
_ISR_Disable( lock_context->isr_level );
|
||||
#endif
|
||||
executing = _Thread_Executing;
|
||||
_ISR_lock_Acquire( &executing->Object.Lock, lock_context );
|
||||
|
||||
return executing;
|
||||
}
|
||||
|
||||
Thread_Control *_Thread_Acquire(
|
||||
Thread_Control *_Thread_Get_interrupt_disable(
|
||||
Objects_Id id,
|
||||
Objects_Locations *location,
|
||||
ISR_lock_Context *lock_context
|
||||
@@ -100,7 +85,8 @@ Thread_Control *_Thread_Acquire(
|
||||
|
||||
if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
|
||||
*location = OBJECTS_LOCAL;
|
||||
return _Thread_Acquire_executing( lock_context );
|
||||
_ISR_lock_ISR_disable( lock_context );
|
||||
return _Thread_Executing;
|
||||
}
|
||||
|
||||
information = _Thread_Get_objects_information( id );
|
||||
@@ -110,5 +96,5 @@ Thread_Control *_Thread_Acquire(
|
||||
}
|
||||
|
||||
return (Thread_Control *)
|
||||
_Objects_Acquire( information, id, location, lock_context );
|
||||
_Objects_Get_isr_disable( information, id, location, lock_context );
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ static void any_satisfy_before_timeout(rtems_id timer, void *arg)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
test_context *ctx = arg;
|
||||
const Thread_Control *thread = ctx->thread;
|
||||
Thread_Control *thread = ctx->thread;
|
||||
Thread_Wait_flags flags = _Thread_Wait_flags_get(thread);
|
||||
|
||||
if (blocks_for_event(flags)) {
|
||||
@@ -78,7 +78,7 @@ static void any_satisfy_before_timeout(rtems_id timer, void *arg)
|
||||
);
|
||||
rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
|
||||
|
||||
_Event_Timeout(thread->Object.id, NULL);
|
||||
_Event_Timeout(0, thread);
|
||||
|
||||
rtems_test_assert(
|
||||
*(rtems_event_set *) thread->Wait.return_argument == GREEN
|
||||
@@ -148,7 +148,7 @@ static void all_satisfy_before_timeout(rtems_id timer, void *arg)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
test_context *ctx = arg;
|
||||
const Thread_Control *thread = ctx->thread;
|
||||
Thread_Control *thread = ctx->thread;
|
||||
Thread_Wait_flags flags = _Thread_Wait_flags_get(thread);
|
||||
|
||||
if (blocks_for_event(flags)) {
|
||||
@@ -175,7 +175,7 @@ static void all_satisfy_before_timeout(rtems_id timer, void *arg)
|
||||
);
|
||||
rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
|
||||
|
||||
_Event_Timeout(thread->Object.id, NULL);
|
||||
_Event_Timeout(0, thread);
|
||||
|
||||
rtems_test_assert(
|
||||
*(rtems_event_set *) thread->Wait.return_argument == EVENTS
|
||||
@@ -240,7 +240,7 @@ static void timeout_before_satisfied(rtems_id timer, void *arg)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
test_context *ctx = arg;
|
||||
const Thread_Control *thread = ctx->thread;
|
||||
Thread_Control *thread = ctx->thread;
|
||||
Thread_Wait_flags flags = _Thread_Wait_flags_get(thread);
|
||||
|
||||
if (blocks_for_event(flags)) {
|
||||
@@ -251,7 +251,7 @@ static void timeout_before_satisfied(rtems_id timer, void *arg)
|
||||
);
|
||||
rtems_test_assert(thread->Wait.return_code == RTEMS_SUCCESSFUL);
|
||||
|
||||
_Event_Timeout(thread->Object.id, NULL);
|
||||
_Event_Timeout(0, thread);
|
||||
|
||||
rtems_test_assert(
|
||||
*(rtems_event_set *) thread->Wait.return_argument == DEADBEEF
|
||||
|
||||
Reference in New Issue
Block a user