[db7f70a] | 1 | /* |
---|
| 2 | * $Id$ |
---|
| 3 | */ |
---|
| 4 | |
---|
[f42b726] | 5 | #if HAVE_CONFIG_H |
---|
| 6 | #include "config.h" |
---|
| 7 | #endif |
---|
| 8 | |
---|
[db7f70a] | 9 | #include <pthread.h> |
---|
| 10 | #include <errno.h> |
---|
| 11 | |
---|
| 12 | #include <rtems/system.h> |
---|
| 13 | #include <rtems/score/chain.h> |
---|
| 14 | #include <rtems/score/isr.h> |
---|
| 15 | #include <rtems/score/thread.h> |
---|
| 16 | #include <rtems/score/wkspace.h> |
---|
| 17 | #include <rtems/posix/cancel.h> |
---|
| 18 | #include <rtems/posix/pthread.h> |
---|
| 19 | #include <rtems/posix/threadsup.h> |
---|
| 20 | |
---|
| 21 | /*PAGE |
---|
| 22 | * |
---|
[f845e96e] | 23 | * _POSIX_Threads_cancel_run |
---|
[db7f70a] | 24 | * |
---|
| 25 | */ |
---|
| 26 | |
---|
[f845e96e] | 27 | void _POSIX_Threads_cancel_run( |
---|
[db7f70a] | 28 | Thread_Control *the_thread |
---|
| 29 | ) |
---|
| 30 | { |
---|
| 31 | POSIX_Cancel_Handler_control *handler; |
---|
| 32 | Chain_Control *handler_stack; |
---|
| 33 | POSIX_API_Control *thread_support; |
---|
| 34 | ISR_Level level; |
---|
| 35 | |
---|
| 36 | thread_support = the_thread->API_Extensions[ THREAD_API_POSIX ]; |
---|
| 37 | |
---|
| 38 | handler_stack = &thread_support->Cancellation_Handlers; |
---|
| 39 | |
---|
| 40 | thread_support->cancelability_state = PTHREAD_CANCEL_DISABLE; |
---|
| 41 | |
---|
| 42 | while ( !_Chain_Is_empty( handler_stack ) ) { |
---|
| 43 | _ISR_Disable( level ); |
---|
[e5b78e2] | 44 | handler = (POSIX_Cancel_Handler_control *) |
---|
| 45 | _Chain_Tail( handler_stack )->previous; |
---|
[db7f70a] | 46 | _Chain_Extract_unprotected( &handler->Node ); |
---|
| 47 | _ISR_Enable( level ); |
---|
| 48 | |
---|
| 49 | (*handler->routine)( handler->arg ); |
---|
| 50 | |
---|
| 51 | _Workspace_Free( handler ); |
---|
| 52 | } |
---|
| 53 | |
---|
[f845e96e] | 54 | /* Now we can delete the thread */ |
---|
| 55 | |
---|
[e7bd66a7] | 56 | the_thread->Wait.return_argument = PTHREAD_CANCELED; |
---|
[f845e96e] | 57 | _Thread_Close( |
---|
| 58 | _Objects_Get_information( the_thread->Object.id ), |
---|
| 59 | the_thread |
---|
| 60 | ); |
---|
| 61 | _POSIX_Threads_Free( the_thread ); |
---|
[db7f70a] | 62 | |
---|
| 63 | } |
---|