forked from Imagelibrary/rtems
Split cancel.c into multiple files.
This commit is contained in:
@@ -17,17 +17,21 @@ VPATH = @srcdir@
|
|||||||
# C_PIECES=aio cancel devctl intr utsname
|
# C_PIECES=aio cancel devctl intr utsname
|
||||||
|
|
||||||
# These are really in the stand but not really functional
|
# These are really in the stand but not really functional
|
||||||
BUILD_FOR_NOW_C_PIECES = aio cancel utsname
|
BUILD_FOR_NOW_C_PIECES = aio utsname
|
||||||
|
|
||||||
ENOSYS_C_PIECES = execl execle execlp execv execve execvp fork pthreadatfork \
|
ENOSYS_C_PIECES = execl execle execlp execv execve execvp fork pthreadatfork \
|
||||||
wait waitpid
|
wait waitpid
|
||||||
|
|
||||||
|
CANCEL_C_PIECES= cancel cancelrun cleanuppop cleanuppush setcancelstate \
|
||||||
|
setcanceltype testcancel
|
||||||
|
|
||||||
CONDITION_VARIABLE_C_PIECES= cond condattrdestroy condattrgetpshared \
|
CONDITION_VARIABLE_C_PIECES= cond condattrdestroy condattrgetpshared \
|
||||||
condattrinit condattrsetpshared condbroadcast conddefaultattributes \
|
condattrinit condattrsetpshared condbroadcast conddefaultattributes \
|
||||||
condmp condsignal condsignalsupp condtimedwait condwait condwaitsupp
|
conddestroy condinit condmp condsignal condsignalsupp condtimedwait \
|
||||||
|
condwait condwaitsupp
|
||||||
|
|
||||||
KEY_C_PIECES= key keycreate keydelete keygetspecific keyrundestructors \
|
KEY_C_PIECES= key keycreate keydelete keygetspecific keyrundestructors \
|
||||||
keysetspecific
|
keysetspecific
|
||||||
|
|
||||||
MESSAGE_QUEUE_C_PIECES= mqueue mqueueclose mqueuecreatesupp mqueuedeletesupp \
|
MESSAGE_QUEUE_C_PIECES= mqueue mqueueclose mqueuecreatesupp mqueuedeletesupp \
|
||||||
mqueuegetattr mqueuenametoid mqueuenotify mqueueopen mqueuereceive \
|
mqueuegetattr mqueuenametoid mqueuenotify mqueueopen mqueuereceive \
|
||||||
@@ -69,7 +73,7 @@ TIME_C_PIECES= time posixtimespecsubtract posixtimespectointerval \
|
|||||||
posixintervaltotimespec clockgetcpuclockid clockgetenableattr \
|
posixintervaltotimespec clockgetcpuclockid clockgetenableattr \
|
||||||
clockgetres clockgettime clocksetenableattr clocksettime nanosleep
|
clockgetres clockgettime clocksetenableattr clocksettime nanosleep
|
||||||
|
|
||||||
C_PIECES = adasupp $(CONDITION_VARIABLE_C_PIECES) \
|
C_PIECES = adasupp $(CANCEL_C_PIECES) $(CONDITION_VARIABLE_C_PIECES) \
|
||||||
getpid $(KEY_C_PIECES) $(MESSAGE_QUEUE_C_PIECES) \
|
getpid $(KEY_C_PIECES) $(MESSAGE_QUEUE_C_PIECES) \
|
||||||
$(MUTEX_C_PIECES) $(PTHREAD_C_PIECES) \
|
$(MUTEX_C_PIECES) $(PTHREAD_C_PIECES) \
|
||||||
$(PSIGNAL_C_PIECES) ptimer sched $(SEMAPHORE_C_PIECES) \
|
$(PSIGNAL_C_PIECES) ptimer sched $(SEMAPHORE_C_PIECES) \
|
||||||
|
|||||||
@@ -14,46 +14,6 @@
|
|||||||
#include <rtems/posix/pthread.h>
|
#include <rtems/posix/pthread.h>
|
||||||
#include <rtems/posix/threadsup.h>
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* POSIX_Thread_cancel_run
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void POSIX_Thread_cancel_run(
|
|
||||||
Thread_Control *the_thread
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int old_cancel_state;
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
ISR_Level level;
|
|
||||||
|
|
||||||
thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
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 ) ) {
|
|
||||||
_ISR_Disable( level );
|
|
||||||
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
|
||||||
_Chain_Extract_unprotected( &handler->Node );
|
|
||||||
_ISR_Enable( level );
|
|
||||||
|
|
||||||
(*handler->routine)( handler->arg );
|
|
||||||
|
|
||||||
_Workspace_Free( handler );
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_support->cancelation_requested = 0;
|
|
||||||
|
|
||||||
thread_support->cancelability_state = old_cancel_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
/*PAGE
|
||||||
*
|
*
|
||||||
* 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181
|
* 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181
|
||||||
@@ -84,145 +44,3 @@ int pthread_cancel(
|
|||||||
|
|
||||||
return POSIX_BOTTOM_REACHED();
|
return POSIX_BOTTOM_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
int pthread_setcancelstate(
|
|
||||||
int state,
|
|
||||||
int *oldstate
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !oldstate )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
*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 );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
int pthread_setcanceltype(
|
|
||||||
int type,
|
|
||||||
int *oldtype
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !oldtype )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
*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 );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_testcancel( void )
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_cleanup_push(
|
|
||||||
void (*routine)( void * ),
|
|
||||||
void *arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !routine )
|
|
||||||
return; /* XXX what to do really? */
|
|
||||||
|
|
||||||
handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
|
|
||||||
|
|
||||||
if ( !handler )
|
|
||||||
return; /* XXX what to do really? */
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
handler_stack = &thread_support->Cancellation_Handlers;
|
|
||||||
|
|
||||||
handler->routine = routine;
|
|
||||||
handler->arg = arg;
|
|
||||||
|
|
||||||
_Chain_Append( handler_stack, &handler->Node );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_cleanup_pop(
|
|
||||||
int execute
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
ISR_Level level;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
handler_stack = &thread_support->Cancellation_Handlers;
|
|
||||||
|
|
||||||
if ( _Chain_Is_empty( handler_stack ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
_ISR_Disable( level );
|
|
||||||
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
|
||||||
_Chain_Extract_unprotected( &handler->Node );
|
|
||||||
_ISR_Enable( level );
|
|
||||||
|
|
||||||
if ( execute )
|
|
||||||
(*handler->routine)( handler->arg );
|
|
||||||
|
|
||||||
_Workspace_Free( handler );
|
|
||||||
}
|
|
||||||
|
|||||||
55
c/src/exec/posix/src/cancelrun.c
Normal file
55
c/src/exec/posix/src/cancelrun.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* POSIX_Thread_cancel_run
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void POSIX_Thread_cancel_run(
|
||||||
|
Thread_Control *the_thread
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int old_cancel_state;
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
ISR_Level level;
|
||||||
|
|
||||||
|
thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
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 ) ) {
|
||||||
|
_ISR_Disable( level );
|
||||||
|
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
||||||
|
_Chain_Extract_unprotected( &handler->Node );
|
||||||
|
_ISR_Enable( level );
|
||||||
|
|
||||||
|
(*handler->routine)( handler->arg );
|
||||||
|
|
||||||
|
_Workspace_Free( handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_support->cancelation_requested = 0;
|
||||||
|
|
||||||
|
thread_support->cancelability_state = old_cancel_state;
|
||||||
|
}
|
||||||
47
c/src/exec/posix/src/cleanuppop.c
Normal file
47
c/src/exec/posix/src/cleanuppop.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_cleanup_pop(
|
||||||
|
int execute
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
ISR_Level level;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
handler_stack = &thread_support->Cancellation_Handlers;
|
||||||
|
|
||||||
|
if ( _Chain_Is_empty( handler_stack ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
_ISR_Disable( level );
|
||||||
|
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
||||||
|
_Chain_Extract_unprotected( &handler->Node );
|
||||||
|
_ISR_Enable( level );
|
||||||
|
|
||||||
|
if ( execute )
|
||||||
|
(*handler->routine)( handler->arg );
|
||||||
|
|
||||||
|
_Workspace_Free( handler );
|
||||||
|
}
|
||||||
47
c/src/exec/posix/src/cleanuppush.c
Normal file
47
c/src/exec/posix/src/cleanuppush.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_cleanup_push(
|
||||||
|
void (*routine)( void * ),
|
||||||
|
void *arg
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !routine )
|
||||||
|
return; /* XXX what to do really? */
|
||||||
|
|
||||||
|
handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
|
||||||
|
|
||||||
|
if ( !handler )
|
||||||
|
return; /* XXX what to do really? */
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
handler_stack = &thread_support->Cancellation_Handlers;
|
||||||
|
|
||||||
|
handler->routine = routine;
|
||||||
|
handler->arg = arg;
|
||||||
|
|
||||||
|
_Chain_Append( handler_stack, &handler->Node );
|
||||||
|
}
|
||||||
46
c/src/exec/posix/src/setcancelstate.c
Normal file
46
c/src/exec/posix/src/setcancelstate.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
int pthread_setcancelstate(
|
||||||
|
int state,
|
||||||
|
int *oldstate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !oldstate )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
*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 );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
46
c/src/exec/posix/src/setcanceltype.c
Normal file
46
c/src/exec/posix/src/setcanceltype.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
int pthread_setcanceltype(
|
||||||
|
int type,
|
||||||
|
int *oldtype
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !oldtype )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
*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 );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
31
c/src/exec/posix/src/testcancel.c
Normal file
31
c/src/exec/posix/src/testcancel.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_testcancel( void )
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
@@ -14,46 +14,6 @@
|
|||||||
#include <rtems/posix/pthread.h>
|
#include <rtems/posix/pthread.h>
|
||||||
#include <rtems/posix/threadsup.h>
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* POSIX_Thread_cancel_run
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void POSIX_Thread_cancel_run(
|
|
||||||
Thread_Control *the_thread
|
|
||||||
)
|
|
||||||
{
|
|
||||||
int old_cancel_state;
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
ISR_Level level;
|
|
||||||
|
|
||||||
thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
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 ) ) {
|
|
||||||
_ISR_Disable( level );
|
|
||||||
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
|
||||||
_Chain_Extract_unprotected( &handler->Node );
|
|
||||||
_ISR_Enable( level );
|
|
||||||
|
|
||||||
(*handler->routine)( handler->arg );
|
|
||||||
|
|
||||||
_Workspace_Free( handler );
|
|
||||||
}
|
|
||||||
|
|
||||||
thread_support->cancelation_requested = 0;
|
|
||||||
|
|
||||||
thread_support->cancelability_state = old_cancel_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
/*PAGE
|
||||||
*
|
*
|
||||||
* 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181
|
* 18.2.1 Canceling Execution of a Thread, P1003.1c/Draft 10, p. 181
|
||||||
@@ -84,145 +44,3 @@ int pthread_cancel(
|
|||||||
|
|
||||||
return POSIX_BOTTOM_REACHED();
|
return POSIX_BOTTOM_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
int pthread_setcancelstate(
|
|
||||||
int state,
|
|
||||||
int *oldstate
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !oldstate )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
*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 );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
int pthread_setcanceltype(
|
|
||||||
int type,
|
|
||||||
int *oldtype
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !oldtype )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
*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 );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_testcancel( void )
|
|
||||||
{
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_cleanup_push(
|
|
||||||
void (*routine)( void * ),
|
|
||||||
void *arg
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
|
|
||||||
if ( !routine )
|
|
||||||
return; /* XXX what to do really? */
|
|
||||||
|
|
||||||
handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
|
|
||||||
|
|
||||||
if ( !handler )
|
|
||||||
return; /* XXX what to do really? */
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
handler_stack = &thread_support->Cancellation_Handlers;
|
|
||||||
|
|
||||||
handler->routine = routine;
|
|
||||||
handler->arg = arg;
|
|
||||||
|
|
||||||
_Chain_Append( handler_stack, &handler->Node );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*PAGE
|
|
||||||
*
|
|
||||||
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
|
||||||
*/
|
|
||||||
|
|
||||||
void pthread_cleanup_pop(
|
|
||||||
int execute
|
|
||||||
)
|
|
||||||
{
|
|
||||||
POSIX_Cancel_Handler_control *handler;
|
|
||||||
Chain_Control *handler_stack;
|
|
||||||
POSIX_API_Control *thread_support;
|
|
||||||
ISR_Level level;
|
|
||||||
|
|
||||||
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
|
||||||
|
|
||||||
handler_stack = &thread_support->Cancellation_Handlers;
|
|
||||||
|
|
||||||
if ( _Chain_Is_empty( handler_stack ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
_ISR_Disable( level );
|
|
||||||
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
|
||||||
_Chain_Extract_unprotected( &handler->Node );
|
|
||||||
_ISR_Enable( level );
|
|
||||||
|
|
||||||
if ( execute )
|
|
||||||
(*handler->routine)( handler->arg );
|
|
||||||
|
|
||||||
_Workspace_Free( handler );
|
|
||||||
}
|
|
||||||
|
|||||||
55
cpukit/posix/src/cancelrun.c
Normal file
55
cpukit/posix/src/cancelrun.c
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* POSIX_Thread_cancel_run
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void POSIX_Thread_cancel_run(
|
||||||
|
Thread_Control *the_thread
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int old_cancel_state;
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
ISR_Level level;
|
||||||
|
|
||||||
|
thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
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 ) ) {
|
||||||
|
_ISR_Disable( level );
|
||||||
|
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
||||||
|
_Chain_Extract_unprotected( &handler->Node );
|
||||||
|
_ISR_Enable( level );
|
||||||
|
|
||||||
|
(*handler->routine)( handler->arg );
|
||||||
|
|
||||||
|
_Workspace_Free( handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_support->cancelation_requested = 0;
|
||||||
|
|
||||||
|
thread_support->cancelability_state = old_cancel_state;
|
||||||
|
}
|
||||||
47
cpukit/posix/src/cleanuppop.c
Normal file
47
cpukit/posix/src/cleanuppop.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_cleanup_pop(
|
||||||
|
int execute
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
ISR_Level level;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
handler_stack = &thread_support->Cancellation_Handlers;
|
||||||
|
|
||||||
|
if ( _Chain_Is_empty( handler_stack ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
_ISR_Disable( level );
|
||||||
|
handler = (POSIX_Cancel_Handler_control *) _Chain_Tail( handler_stack );
|
||||||
|
_Chain_Extract_unprotected( &handler->Node );
|
||||||
|
_ISR_Enable( level );
|
||||||
|
|
||||||
|
if ( execute )
|
||||||
|
(*handler->routine)( handler->arg );
|
||||||
|
|
||||||
|
_Workspace_Free( handler );
|
||||||
|
}
|
||||||
47
cpukit/posix/src/cleanuppush.c
Normal file
47
cpukit/posix/src/cleanuppush.c
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_cleanup_push(
|
||||||
|
void (*routine)( void * ),
|
||||||
|
void *arg
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_Cancel_Handler_control *handler;
|
||||||
|
Chain_Control *handler_stack;
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !routine )
|
||||||
|
return; /* XXX what to do really? */
|
||||||
|
|
||||||
|
handler = _Workspace_Allocate( sizeof( POSIX_Cancel_Handler_control ) );
|
||||||
|
|
||||||
|
if ( !handler )
|
||||||
|
return; /* XXX what to do really? */
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
handler_stack = &thread_support->Cancellation_Handlers;
|
||||||
|
|
||||||
|
handler->routine = routine;
|
||||||
|
handler->arg = arg;
|
||||||
|
|
||||||
|
_Chain_Append( handler_stack, &handler->Node );
|
||||||
|
}
|
||||||
46
cpukit/posix/src/setcancelstate.c
Normal file
46
cpukit/posix/src/setcancelstate.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
int pthread_setcancelstate(
|
||||||
|
int state,
|
||||||
|
int *oldstate
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !oldstate )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
*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 );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
46
cpukit/posix/src/setcanceltype.c
Normal file
46
cpukit/posix/src/setcanceltype.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
int pthread_setcanceltype(
|
||||||
|
int type,
|
||||||
|
int *oldtype
|
||||||
|
)
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
if ( !oldtype )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
|
||||||
|
|
||||||
|
*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 );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
31
cpukit/posix/src/testcancel.c
Normal file
31
cpukit/posix/src/testcancel.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <rtems/system.h>
|
||||||
|
#include <rtems/score/chain.h>
|
||||||
|
#include <rtems/score/isr.h>
|
||||||
|
#include <rtems/score/thread.h>
|
||||||
|
#include <rtems/score/wkspace.h>
|
||||||
|
#include <rtems/posix/cancel.h>
|
||||||
|
#include <rtems/posix/pthread.h>
|
||||||
|
#include <rtems/posix/threadsup.h>
|
||||||
|
|
||||||
|
/*PAGE
|
||||||
|
*
|
||||||
|
* 18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pthread_testcancel( void )
|
||||||
|
{
|
||||||
|
POSIX_API_Control *thread_support;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user