source: rtems/cpukit/posix/src/cleanuppop.c @ 3bacb250

4.104.115
Last change on this file since 3bacb250 was c3925db, checked in by Jennifer Averett <Jennifer.Averett@…>, on 01/18/08 at 16:31:57

2008-01-18 Jennifer Averett <jennifer.averett@…>

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