source: rtems/cpukit/posix/src/cleanuppop.c @ be1b8a7

4.115
Last change on this file since be1b8a7 was be1b8a7, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 07:15:12

posix: Include proper header file

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Removes Routine from Top of Calling Thread's stack and Invoke it
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22#include <errno.h>
23
24#include <rtems/system.h>
25#include <rtems/score/chainimpl.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/wkspace.h>
29#include <rtems/posix/cancel.h>
30#include <rtems/posix/pthreadimpl.h>
31#include <rtems/posix/threadsup.h>
32
33/*
34 *  18.2.3.1 Establishing Cancellation Handlers, P1003.1c/Draft 10, p. 184
35 */
36
37void pthread_cleanup_pop(
38  int    execute
39)
40{
41  POSIX_Cancel_Handler_control      *handler;
42  POSIX_Cancel_Handler_control      tmp_handler;
43  Chain_Control                     *handler_stack;
44  POSIX_API_Control                 *thread_support;
45  ISR_Level                          level;
46
47  thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
48
49  handler_stack = &thread_support->Cancellation_Handlers;
50
51  /*
52   * We need interrupts disabled to safely check the chain and pull
53   * the last element off.  But we also need dispatching disabled to
54   * ensure that we do not get prempted and deleted while we are holding
55   * memory that needs to be freed.
56   */
57
58  _Thread_Disable_dispatch();
59  _ISR_Disable( level );
60
61    if ( _Chain_Is_empty( handler_stack ) ) {
62      _Thread_Enable_dispatch();
63      _ISR_Enable( level );
64      return;
65    }
66
67    handler = (POSIX_Cancel_Handler_control *)
68        _Chain_Tail( handler_stack )->previous;
69    _Chain_Extract_unprotected( &handler->Node );
70
71  _ISR_Enable( level );
72
73  tmp_handler = *handler;
74
75  _Workspace_Free( handler );
76
77  _Thread_Enable_dispatch();
78
79  if ( execute )
80    (*tmp_handler.routine)( tmp_handler.arg );
81}
Note: See TracBrowser for help on using the repository browser.