source: rtems/cpukit/posix/src/setcancelstate.c @ 92f4671

4.104.115
Last change on this file since 92f4671 was f8437c8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/04/08 at 15:23:12

Convert to "bool".

  • Property mode set to 100644
File size: 1.7 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.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
31 */
32
33int pthread_setcancelstate(
34  int  state,
35  int *oldstate
36)
37{
38  POSIX_API_Control *thread_support;
39  bool               cancel = false;
40
41  /*
42   *  Don't even think about deleting a resource from an ISR.
43   *  Besides this request is supposed to be for _Thread_Executing
44   *  and the ISR context is not a thread.
45   */
46
47  if ( _ISR_Is_in_progress() )
48    return EPROTO;
49
50  if ( !oldstate )
51    return EINVAL;
52
53  if ( state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE )
54    return EINVAL;
55
56  thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
57
58  _Thread_Disable_dispatch();
59    *oldstate = thread_support->cancelability_state;
60    thread_support->cancelability_state = state;
61
62    if ( thread_support->cancelability_state == PTHREAD_CANCEL_ENABLE &&
63         thread_support->cancelability_type == PTHREAD_CANCEL_ASYNCHRONOUS &&
64         thread_support->cancelation_requested )
65      cancel = true;
66
67 _Thread_Enable_dispatch();
68 if ( cancel )
69   _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
70  return 0;
71}
Note: See TracBrowser for help on using the repository browser.