source: rtems/cpukit/posix/src/setcanceltype.c @ 345fc11

4.104.114.95
Last change on this file since 345fc11 was 345fc11, checked in by Joel Sherrill <joel.sherrill@…>, on 05/22/08 at 20:38:03

2008-05-22 Joel Sherrill <joel.sherrill@…>

  • itron/include/rtems/itron/task.h, itron/src/del_tsk.c, itron/src/exd_tsk.c, itron/src/task.c, posix/include/rtems/posix/threadsup.h, posix/src/cancel.c, posix/src/cancelrun.c, posix/src/pthread.c, posix/src/pthreadexit.c, posix/src/setcancelstate.c, posix/src/setcanceltype.c, posix/src/testcancel.c, rtems/src/taskdelete.c, score/inline/rtems/score/object.inl, score/src/objectclose.c, score/src/threadclose.c: Make all task delete/exit/cancel routines follow the same critical section pattern. Also ensure that POSIX cancelation routines are run at thread exit.
  • 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_setcanceltype(
34  int  type,
35  int *oldtype
36)
37{
38  POSIX_API_Control *thread_support;
39  boolean            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 ( !oldtype )
51    return EINVAL;
52
53  if ( type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS )
54    return EINVAL;
55
56  thread_support = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ];
57
58  _Thread_Disable_dispatch();
59    *oldtype = thread_support->cancelability_type;
60    thread_support->cancelability_type = type;
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  _Thread_Enable_dispatch();
67  if ( cancel )
68    _POSIX_Thread_Exit( _Thread_Executing, PTHREAD_CANCELED );
69
70  return 0;
71}
Note: See TracBrowser for help on using the repository browser.