source: rtems/cpukit/posix/src/setcanceltype.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Sets the Cancelability Type of Calling Thread to value given in type
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
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.org/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/chain.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/thread.h>
28#include <rtems/posix/cancel.h>
29#include <rtems/posix/pthreadimpl.h>
30#include <rtems/posix/threadsup.h>
31
32/*
33 *  18.2.2 Setting Cancelability State, P1003.1c/Draft 10, p. 183
34 */
35
36int pthread_setcanceltype(
37  int  type,
38  int *oldtype
39)
40{
41  POSIX_API_Control *thread_support;
42  Thread_Control    *executing;
43
44  /*
45   *  Don't even think about deleting a resource from an ISR.
46   *  Besides this request is supposed to be for _Thread_Executing
47   *  and the ISR context is not a thread.
48   */
49
50  if ( _ISR_Is_in_progress() )
51    return EPROTO;
52
53  if ( !oldtype )
54    return EINVAL;
55
56  if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
57    return EINVAL;
58
59  _Thread_Disable_dispatch();
60
61    executing = _Thread_Executing;
62    thread_support =  executing ->API_Extensions[ THREAD_API_POSIX ];
63
64    *oldtype = thread_support->cancelability_type;
65    thread_support->cancelability_type = type;
66
67    _POSIX_Thread_Evaluate_cancellation_and_enable_dispatch( executing );
68
69  /*
70   *  _Thread_Enable_dispatch is invoked by above call.
71   */
72  return 0;
73}
Note: See TracBrowser for help on using the repository browser.