mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 06:08:20 +00:00
2002-07-05 Joel Sherrill <joel@OARcorp.com>
* include/rtems/posix/cancel.h, src/cancel.c, src/cancelrun.c, src/mqueue.c, src/pthread.c, src/semaphore.c, src/setcancelstate.c, src/setcanceltype.c, src/testcancel.c: Per PR164, corrected the behavior of thread cancellation and did some cleanup as a side-effect.
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2002-07-05 Joel Sherrill <joel@OARcorp.com>
|
||||
|
||||
* include/rtems/posix/cancel.h, src/cancel.c, src/cancelrun.c,
|
||||
src/mqueue.c, src/pthread.c, src/semaphore.c, src/setcancelstate.c,
|
||||
src/setcanceltype.c, src/testcancel.c: Per PR164, corrected the
|
||||
behavior of thread cancellation and did some cleanup as a side-effect.
|
||||
|
||||
2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
|
||||
|
||||
* configure.ac: RTEMS_TOP(../..).
|
||||
|
||||
@@ -13,7 +13,7 @@ typedef struct {
|
||||
} POSIX_Cancel_Handler_control;
|
||||
|
||||
/*
|
||||
* _POSIX_Thread_cancel_run
|
||||
* _POSIX_Threads_cancel_run
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
@@ -21,7 +21,7 @@ typedef struct {
|
||||
* have been registered and executes them.
|
||||
*/
|
||||
|
||||
void _POSIX_Thread_cancel_run(
|
||||
void _POSIX_Threads_cancel_run(
|
||||
Thread_Control *the_thread
|
||||
);
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@ int pthread_cancel(
|
||||
POSIX_API_Control *thread_support;
|
||||
Objects_Locations location;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
the_thread = _POSIX_Threads_Get( thread, &location );
|
||||
switch ( location ) {
|
||||
case OBJECTS_ERROR:
|
||||
@@ -42,6 +49,11 @@ int pthread_cancel(
|
||||
|
||||
thread_support->cancelation_requested = 1;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS ) {
|
||||
_POSIX_Threads_cancel_run( the_thread );
|
||||
}
|
||||
|
||||
_Thread_Enable_dispatch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@
|
||||
|
||||
/*PAGE
|
||||
*
|
||||
* _POSIX_Thread_cancel_run
|
||||
* _POSIX_Threads_cancel_run
|
||||
*
|
||||
*/
|
||||
|
||||
void _POSIX_Thread_cancel_run(
|
||||
#if !defined(PTHREAD_CANCELED)
|
||||
#warning "PTHREAD_CANCELED NOT DEFINED -- patch newlib"
|
||||
#define PTHREAD_CANCELED ((void *) -1)
|
||||
#endif
|
||||
|
||||
void _POSIX_Threads_cancel_run(
|
||||
Thread_Control *the_thread
|
||||
)
|
||||
{
|
||||
int old_cancel_state;
|
||||
POSIX_Cancel_Handler_control *handler;
|
||||
Chain_Control *handler_stack;
|
||||
POSIX_API_Control *thread_support;
|
||||
@@ -38,8 +42,6 @@ void _POSIX_Thread_cancel_run(
|
||||
|
||||
handler_stack = &thread_support->Cancellation_Handlers;
|
||||
|
||||
old_cancel_state = thread_support->cancelability_state;
|
||||
|
||||
thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
|
||||
|
||||
while ( !_Chain_Is_empty( handler_stack ) ) {
|
||||
@@ -53,7 +55,13 @@ void _POSIX_Thread_cancel_run(
|
||||
_Workspace_Free( handler );
|
||||
}
|
||||
|
||||
thread_support->cancelation_requested = 0;
|
||||
/* Now we can delete the thread */
|
||||
|
||||
the_thread->Wait.return_argument = (unsigned32 *)PTHREAD_CANCELED;
|
||||
_Thread_Close(
|
||||
_Objects_Get_information( the_thread->Object.id ),
|
||||
the_thread
|
||||
);
|
||||
_POSIX_Threads_Free( the_thread );
|
||||
|
||||
thread_support->cancelability_state = old_cancel_state;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void _POSIX_Message_queue_Manager_initialization(
|
||||
maximum_message_queues, /* maximum objects of this class */
|
||||
sizeof( POSIX_Message_queue_Control ),
|
||||
/* size of this object's control block */
|
||||
FALSE, /* TRUE if names for this object are strings */
|
||||
TRUE, /* TRUE if names for this object are strings */
|
||||
_POSIX_PATH_MAX /* maximum length of each object's name */
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
,
|
||||
|
||||
@@ -207,7 +207,9 @@ User_extensions_routine _POSIX_Threads_Delete_extension(
|
||||
|
||||
api = deleted->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
/* XXX run cancellation handlers */
|
||||
/*
|
||||
* Run the POSIX cancellation handlers
|
||||
*/
|
||||
|
||||
_POSIX_Keys_Run_destructors( deleted );
|
||||
|
||||
@@ -373,8 +375,9 @@ void _POSIX_Threads_Manager_initialization(
|
||||
*/
|
||||
|
||||
_User_extensions_Add_API_set( &_POSIX_Threads_User_extensions );
|
||||
|
||||
|
||||
_API_extensions_Add( &_POSIX_Threads_API_extensions );
|
||||
|
||||
|
||||
/*
|
||||
* If we supported MP, then here we would ...
|
||||
|
||||
@@ -43,7 +43,7 @@ void _POSIX_Semaphore_Manager_initialization(
|
||||
maximum_semaphores /* maximum objects of this class */,
|
||||
sizeof( POSIX_Semaphore_Control ),
|
||||
/* size of this object's control block */
|
||||
FALSE, /* TRUE if names for this object are strings */
|
||||
TRUE, /* TRUE if names for this object are strings */
|
||||
_POSIX_PATH_MAX /* maximum length of each object's name */
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
,
|
||||
|
||||
@@ -30,6 +30,15 @@ int pthread_setcancelstate(
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
if ( !oldstate )
|
||||
return EINVAL;
|
||||
|
||||
@@ -38,13 +47,15 @@ int pthread_setcancelstate(
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
*oldstate = thread_support->cancelability_state;
|
||||
thread_support->cancelability_state = state;
|
||||
_Thread_Disable_dispatch();
|
||||
*oldstate = thread_support->cancelability_state;
|
||||
thread_support->cancelability_state = state;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,15 @@ int pthread_setcanceltype(
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
if ( !oldtype )
|
||||
return EINVAL;
|
||||
|
||||
@@ -38,13 +47,15 @@ int pthread_setcanceltype(
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
*oldtype = thread_support->cancelability_type;
|
||||
thread_support->cancelability_type = type;
|
||||
_Thread_Disable_dispatch();
|
||||
*oldtype = thread_support->cancelability_type;
|
||||
thread_support->cancelability_type = type;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,20 @@ void pthread_testcancel( void )
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return;
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
_Thread_Disable_dispatch();
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
2002-07-05 Joel Sherrill <joel@OARcorp.com>
|
||||
|
||||
* include/rtems/posix/cancel.h, src/cancel.c, src/cancelrun.c,
|
||||
src/mqueue.c, src/pthread.c, src/semaphore.c, src/setcancelstate.c,
|
||||
src/setcanceltype.c, src/testcancel.c: Per PR164, corrected the
|
||||
behavior of thread cancellation and did some cleanup as a side-effect.
|
||||
|
||||
2002-07-05 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
|
||||
|
||||
* configure.ac: RTEMS_TOP(../..).
|
||||
|
||||
@@ -13,7 +13,7 @@ typedef struct {
|
||||
} POSIX_Cancel_Handler_control;
|
||||
|
||||
/*
|
||||
* _POSIX_Thread_cancel_run
|
||||
* _POSIX_Threads_cancel_run
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
@@ -21,7 +21,7 @@ typedef struct {
|
||||
* have been registered and executes them.
|
||||
*/
|
||||
|
||||
void _POSIX_Thread_cancel_run(
|
||||
void _POSIX_Threads_cancel_run(
|
||||
Thread_Control *the_thread
|
||||
);
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@ int pthread_cancel(
|
||||
POSIX_API_Control *thread_support;
|
||||
Objects_Locations location;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
the_thread = _POSIX_Threads_Get( thread, &location );
|
||||
switch ( location ) {
|
||||
case OBJECTS_ERROR:
|
||||
@@ -42,6 +49,11 @@ int pthread_cancel(
|
||||
|
||||
thread_support->cancelation_requested = 1;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS ) {
|
||||
_POSIX_Threads_cancel_run( the_thread );
|
||||
}
|
||||
|
||||
_Thread_Enable_dispatch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,15 +20,19 @@
|
||||
|
||||
/*PAGE
|
||||
*
|
||||
* _POSIX_Thread_cancel_run
|
||||
* _POSIX_Threads_cancel_run
|
||||
*
|
||||
*/
|
||||
|
||||
void _POSIX_Thread_cancel_run(
|
||||
#if !defined(PTHREAD_CANCELED)
|
||||
#warning "PTHREAD_CANCELED NOT DEFINED -- patch newlib"
|
||||
#define PTHREAD_CANCELED ((void *) -1)
|
||||
#endif
|
||||
|
||||
void _POSIX_Threads_cancel_run(
|
||||
Thread_Control *the_thread
|
||||
)
|
||||
{
|
||||
int old_cancel_state;
|
||||
POSIX_Cancel_Handler_control *handler;
|
||||
Chain_Control *handler_stack;
|
||||
POSIX_API_Control *thread_support;
|
||||
@@ -38,8 +42,6 @@ void _POSIX_Thread_cancel_run(
|
||||
|
||||
handler_stack = &thread_support->Cancellation_Handlers;
|
||||
|
||||
old_cancel_state = thread_support->cancelability_state;
|
||||
|
||||
thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE;
|
||||
|
||||
while ( !_Chain_Is_empty( handler_stack ) ) {
|
||||
@@ -53,7 +55,13 @@ void _POSIX_Thread_cancel_run(
|
||||
_Workspace_Free( handler );
|
||||
}
|
||||
|
||||
thread_support->cancelation_requested = 0;
|
||||
/* Now we can delete the thread */
|
||||
|
||||
the_thread->Wait.return_argument = (unsigned32 *)PTHREAD_CANCELED;
|
||||
_Thread_Close(
|
||||
_Objects_Get_information( the_thread->Object.id ),
|
||||
the_thread
|
||||
);
|
||||
_POSIX_Threads_Free( the_thread );
|
||||
|
||||
thread_support->cancelability_state = old_cancel_state;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void _POSIX_Message_queue_Manager_initialization(
|
||||
maximum_message_queues, /* maximum objects of this class */
|
||||
sizeof( POSIX_Message_queue_Control ),
|
||||
/* size of this object's control block */
|
||||
FALSE, /* TRUE if names for this object are strings */
|
||||
TRUE, /* TRUE if names for this object are strings */
|
||||
_POSIX_PATH_MAX /* maximum length of each object's name */
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
,
|
||||
|
||||
@@ -207,7 +207,9 @@ User_extensions_routine _POSIX_Threads_Delete_extension(
|
||||
|
||||
api = deleted->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
/* XXX run cancellation handlers */
|
||||
/*
|
||||
* Run the POSIX cancellation handlers
|
||||
*/
|
||||
|
||||
_POSIX_Keys_Run_destructors( deleted );
|
||||
|
||||
@@ -373,8 +375,9 @@ void _POSIX_Threads_Manager_initialization(
|
||||
*/
|
||||
|
||||
_User_extensions_Add_API_set( &_POSIX_Threads_User_extensions );
|
||||
|
||||
|
||||
_API_extensions_Add( &_POSIX_Threads_API_extensions );
|
||||
|
||||
|
||||
/*
|
||||
* If we supported MP, then here we would ...
|
||||
|
||||
@@ -43,7 +43,7 @@ void _POSIX_Semaphore_Manager_initialization(
|
||||
maximum_semaphores /* maximum objects of this class */,
|
||||
sizeof( POSIX_Semaphore_Control ),
|
||||
/* size of this object's control block */
|
||||
FALSE, /* TRUE if names for this object are strings */
|
||||
TRUE, /* TRUE if names for this object are strings */
|
||||
_POSIX_PATH_MAX /* maximum length of each object's name */
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
,
|
||||
|
||||
@@ -30,6 +30,15 @@ int pthread_setcancelstate(
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
if ( !oldstate )
|
||||
return EINVAL;
|
||||
|
||||
@@ -38,13 +47,15 @@ int pthread_setcancelstate(
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
*oldstate = thread_support->cancelability_state;
|
||||
thread_support->cancelability_state = state;
|
||||
_Thread_Disable_dispatch();
|
||||
*oldstate = thread_support->cancelability_state;
|
||||
thread_support->cancelability_state = state;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,15 @@ int pthread_setcanceltype(
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return EPROTO;
|
||||
|
||||
if ( !oldtype )
|
||||
return EINVAL;
|
||||
|
||||
@@ -38,13 +47,15 @@ int pthread_setcanceltype(
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
*oldtype = thread_support->cancelability_type;
|
||||
thread_support->cancelability_type = type;
|
||||
_Thread_Disable_dispatch();
|
||||
*oldtype = thread_support->cancelability_type;
|
||||
thread_support->cancelability_type = type;
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,20 @@ void pthread_testcancel( void )
|
||||
{
|
||||
POSIX_API_Control *thread_support;
|
||||
|
||||
/*
|
||||
* Don't even think about deleting a resource from an ISR.
|
||||
* Besides this request is supposed to be for _Thread_Executing
|
||||
* and the ISR context is not a thread.
|
||||
*/
|
||||
|
||||
if ( _ISR_Is_in_progress() )
|
||||
return;
|
||||
|
||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Thread_cancel_run( _Thread_Executing );
|
||||
_Thread_Disable_dispatch();
|
||||
if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
|
||||
thread_support->cancelation_requested )
|
||||
_POSIX_Threads_cancel_run( _Thread_Executing );
|
||||
_Thread_Enable_dispatch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user