diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-12-02 08:33:35 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-12-02 09:24:51 +0100 |
commit | 927a0a1f990c19a3e7295bb001896b3f3c75a77e (patch) | |
tree | b4c1cdb1a406b700a17b80e235613c9ced8c0cd9 /cpukit/posix/src/cleanuppush.c | |
parent | pstmtests_plan.csv: Update to reflect psxtmcond 09 and 10 exit (diff) | |
download | rtems-927a0a1f990c19a3e7295bb001896b3f3c75a77e.tar.bz2 |
posix: Use cleanup contexts on the stack
Provide support for latest Newlib <pthread.h> change. The cleanup
contexts are stored on the thread stack. This is conformant with the
POSIX requirements for the pthread_cleanup_push() and
pthread_cleanup_pop() statement pair.
Passing an invalid pointer as the routine to pthread_cleanup_push() is
now a usage error and the behaviour is undefined.
Diffstat (limited to 'cpukit/posix/src/cleanuppush.c')
-rw-r--r-- | cpukit/posix/src/cleanuppush.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/cpukit/posix/src/cleanuppush.c b/cpukit/posix/src/cleanuppush.c index 84dbc0043d..9d11c0553f 100644 --- a/cpukit/posix/src/cleanuppush.c +++ b/cpukit/posix/src/cleanuppush.c @@ -19,16 +19,18 @@ #endif #include <pthread.h> -#include <errno.h> -#include <rtems/system.h> +#include <rtems/score/thread.h> +#include <rtems/score/threaddispatch.h> +#include <rtems/posix/threadsup.h> + +#ifndef HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT + #include <rtems/score/chainimpl.h> #include <rtems/score/isr.h> -#include <rtems/score/thread.h> #include <rtems/score/wkspace.h> #include <rtems/posix/cancel.h> #include <rtems/posix/pthreadimpl.h> -#include <rtems/posix/threadsup.h> /* * 18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184 @@ -66,3 +68,30 @@ void pthread_cleanup_push( } _Thread_Enable_dispatch(); } + +#else /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */ + +void _pthread_cleanup_push( + struct _pthread_cleanup_context *context, + void ( *routine )( void * ), + void *arg +) +{ + POSIX_API_Control *thread_support; + + context->_routine = routine; + context->_arg = arg; + + /* This value is unused, just provide a deterministic value */ + context->_canceltype = -1; + + _Thread_Disable_dispatch(); + + thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + context->_previous = thread_support->last_cleanup_context; + thread_support->last_cleanup_context = context; + + _Thread_Enable_dispatch(); +} + +#endif /* HAVE_STRUCT__PTHREAD_CLEANUP_CONTEXT */ |