mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 14:42:18 +08:00
score: Avoid direct usage of _Thread_Executing
Pass the executing thread as a function parameter. Obtain the executing thread inside a thread dispatch critical section to avoid problems on SMP.
This commit is contained in:
@@ -39,6 +39,7 @@ int pthread_rwlock_rdlock(
|
||||
{
|
||||
POSIX_RWLock_Control *the_rwlock;
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -48,17 +49,19 @@ int pthread_rwlock_rdlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_reading(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
true, /* we are willing to wait forever */
|
||||
0,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
true, /* we are willing to wait forever */
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -48,6 +48,7 @@ int pthread_rwlock_timedrdlock(
|
||||
Watchdog_Interval ticks;
|
||||
bool do_wait = true;
|
||||
POSIX_Absolute_timeout_conversion_results_t status;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -74,27 +75,29 @@ int pthread_rwlock_timedrdlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_reading(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
do_wait,
|
||||
ticks,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
do_wait,
|
||||
ticks,
|
||||
NULL
|
||||
);
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
if ( !do_wait ) {
|
||||
if ( _Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) {
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
|
||||
return EINVAL;
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
|
||||
status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
|
||||
return ETIMEDOUT;
|
||||
if ( executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) {
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
|
||||
return EINVAL;
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
|
||||
status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -50,6 +50,7 @@ int pthread_rwlock_timedwrlock(
|
||||
Watchdog_Interval ticks;
|
||||
bool do_wait = true;
|
||||
POSIX_Absolute_timeout_conversion_results_t status;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -76,26 +77,28 @@ int pthread_rwlock_timedwrlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_writing(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
do_wait,
|
||||
ticks,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
do_wait,
|
||||
ticks,
|
||||
NULL
|
||||
);
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
if ( !do_wait &&
|
||||
(_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
|
||||
return EINVAL;
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
|
||||
status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
|
||||
return ETIMEDOUT;
|
||||
(executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
|
||||
return EINVAL;
|
||||
if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
|
||||
status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -43,6 +43,7 @@ int pthread_rwlock_tryrdlock(
|
||||
{
|
||||
POSIX_RWLock_Control *the_rwlock;
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -52,18 +53,20 @@ int pthread_rwlock_tryrdlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_reading(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
false, /* do not wait for the rwlock */
|
||||
0,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
false, /* do not wait for the rwlock */
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -43,6 +43,7 @@ int pthread_rwlock_trywrlock(
|
||||
{
|
||||
POSIX_RWLock_Control *the_rwlock;
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -52,17 +53,19 @@ int pthread_rwlock_trywrlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_writing(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
false, /* we are not willing to wait */
|
||||
0,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
false, /* we are not willing to wait */
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -54,7 +54,7 @@ int pthread_rwlock_unlock(
|
||||
switch ( location ) {
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
status = _CORE_RWLock_Release( &the_rwlock->RWLock );
|
||||
status = _CORE_RWLock_Release( &the_rwlock->RWLock, _Thread_Executing );
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code( status );
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ int pthread_rwlock_wrlock(
|
||||
{
|
||||
POSIX_RWLock_Control *the_rwlock;
|
||||
Objects_Locations location;
|
||||
Thread_Control *executing;
|
||||
|
||||
if ( !rwlock )
|
||||
return EINVAL;
|
||||
@@ -54,17 +55,19 @@ int pthread_rwlock_wrlock(
|
||||
|
||||
case OBJECTS_LOCAL:
|
||||
|
||||
executing = _Thread_Executing;
|
||||
_CORE_RWLock_Obtain_for_writing(
|
||||
&the_rwlock->RWLock,
|
||||
*rwlock,
|
||||
true, /* do not timeout -- wait forever */
|
||||
0,
|
||||
NULL
|
||||
&the_rwlock->RWLock,
|
||||
executing,
|
||||
*rwlock,
|
||||
true, /* do not timeout -- wait forever */
|
||||
0,
|
||||
NULL
|
||||
);
|
||||
|
||||
_Objects_Put( &the_rwlock->Object );
|
||||
return _POSIX_RWLock_Translate_core_RWLock_return_code(
|
||||
(CORE_RWLock_Status) _Thread_Executing->Wait.return_code
|
||||
(CORE_RWLock_Status) executing->Wait.return_code
|
||||
);
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
|
||||
@@ -105,6 +105,7 @@ void _CORE_RWLock_Initialize(
|
||||
|
||||
void _CORE_RWLock_Obtain_for_reading(
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing,
|
||||
Objects_Id id,
|
||||
bool wait,
|
||||
Watchdog_Interval timeout,
|
||||
@@ -128,6 +129,7 @@ void _CORE_RWLock_Obtain_for_reading(
|
||||
*/
|
||||
void _CORE_RWLock_Obtain_for_writing(
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing,
|
||||
Objects_Id id,
|
||||
bool wait,
|
||||
Watchdog_Interval timeout,
|
||||
@@ -145,7 +147,8 @@ void _CORE_RWLock_Obtain_for_writing(
|
||||
* @retval Status is returned to indicate successful or failure.
|
||||
*/
|
||||
CORE_RWLock_Status _CORE_RWLock_Release(
|
||||
CORE_RWLock_Control *the_rwlock
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
void _CORE_RWLock_Obtain_for_reading(
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing,
|
||||
Objects_Id id,
|
||||
bool wait,
|
||||
Watchdog_Interval timeout,
|
||||
@@ -33,7 +34,6 @@ void _CORE_RWLock_Obtain_for_reading(
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
Thread_Control *executing = _Thread_Executing;
|
||||
|
||||
/*
|
||||
* If unlocked, then OK to read.
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
void _CORE_RWLock_Obtain_for_writing(
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing,
|
||||
Objects_Id id,
|
||||
bool wait,
|
||||
Watchdog_Interval timeout,
|
||||
@@ -33,7 +34,6 @@ void _CORE_RWLock_Obtain_for_writing(
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
Thread_Control *executing = _Thread_Executing;
|
||||
|
||||
/*
|
||||
* If unlocked, then OK to read.
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
CORE_RWLock_Status _CORE_RWLock_Release(
|
||||
CORE_RWLock_Control *the_rwlock
|
||||
CORE_RWLock_Control *the_rwlock,
|
||||
Thread_Control *executing
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
Thread_Control *executing = _Thread_Executing;
|
||||
Thread_Control *next;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user