summaryrefslogtreecommitdiff
path: root/cancel.c
blob: 72c41ade75d2e6b372196dd6221a676fd2c55ec2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * cancel.c
 *
 * Description:
 * POSIX thread functions related to thread cancellation.
 */

#include "pthread.h"

int
pthread_setcancelstate(int state,
		       int *oldstate)
{
  _pthread_threads_thread_t * this = *_PTHREAD_THIS;

  /* Validate the new cancellation state. */
  if (state != PTHREAD_CANCEL_ENABLE || state != PTHREAD_CANCEL_DISABLE)
    {
      return EINVAL;
    }

  if (oldstate != NULL)
    {
      *oldstate = this->cancelability;
    }

  this->cancelability = state;
  return 0;
}

int
pthread_setcanceltype(int type, int *oldtype)
{
  _pthread_threads_thread_t * this = *_PTHREAD_THIS;

  /* Validate the new cancellation type. */
  if (type != PTHREAD_CANCEL_DEFERRED || type != PTHREAD_CANCEL_ASYNCHRONOUS)
    {
      return EINVAL;
    }

  if (oldtype != NULL)
    {
      *oldtype = this->canceltype;
    }

  this->canceltype = type;
  return 0;
}