summaryrefslogtreecommitdiff
path: root/condvar.c
blob: 871f50d50a50bc85b4ca15ed30abebbd7734c3db (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * condvar.c
 *
 * Description:
 * This translation unit implements condition variables and their primitives.
 */

#include "pthread.h"

int
pthread_cond_init(pthread_condattr_t *attr)
{
  if (attr == NULL)
    {
      /* This is disallowed. */
      return EINVAL;
    }

  attr->ptr = malloc(sizeof(_pthread_condattr_t));
  if (attr->ptr == NULL)
    {
      return ENOMEM;
    }

  /* FIXME: fill out the structure with default values. */
  return 0;
}

int
pthread_condattr_destroy(pthread_condattr_t *attr)
{
  if (is_attr(attr) != 0)
    {
      return EINVAL;
    }
  
  free(attr->ptr);
  return 0;
}

int
pthread_condattr_setpshared(pthread_condattr_t *attr,
			    int pshared)
{
  if (is_attr(attr) != 0)
    {
      return EINVAL;
    }

  (_pthread_condattr_t *) (attr->ptr)->pshared = pshared;
  return 0;
}

int
pthread_condattr_getpshared(pthread_condattr_t *attr,
			    int *pshared)
{
  if (is_attr(attr) != 0)
    {
      return EINVAL;
    }

  *pshared = (_pthread_condattr_t *) (attr->ptr)->pshared;
  return 0;
}