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

5
Last change on this file since dbb30e26 was da826560, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/16 at 08:28:14

posix: Rework thread cancellation

Add Thread_Life_state::THREAD_LIFE_CHANGE_DEFERRED and rework the POSIX
thread cancellation to use the thread life states.

Update #2555.
Update #2626.

  • Property mode set to 100644
File size: 1.4 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 *  Copyright (c) 2016 embedded brains GmbH.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <pthread.h>
24#include <errno.h>
25
26#include <rtems/score/isr.h>
27#include <rtems/score/threadimpl.h>
28
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  Thread_Life_state set_life_state;
39  Thread_Life_state previous_life_state;
40
41  if ( _ISR_Is_in_progress() ) {
42    return EPROTO;
43  }
44
45  if ( type == PTHREAD_CANCEL_DEFERRED ) {
46    set_life_state = THREAD_LIFE_CHANGE_DEFERRED;
47  } else if ( type == PTHREAD_CANCEL_ASYNCHRONOUS ) {
48    set_life_state = 0;
49  } else {
50    return EINVAL;
51  }
52
53  previous_life_state = _Thread_Change_life(
54    THREAD_LIFE_CHANGE_DEFERRED,
55    set_life_state,
56    0
57  );
58
59  if ( oldtype != NULL ) {
60    if ( ( previous_life_state & THREAD_LIFE_CHANGE_DEFERRED ) != 0 ) {
61      *oldtype = PTHREAD_CANCEL_DEFERRED;
62    } else {
63      *oldtype = PTHREAD_CANCEL_ASYNCHRONOUS;
64    }
65  }
66
67  return 0;
68}
Note: See TracBrowser for help on using the repository browser.