Blame view

RIOT/sys/posix/pthread/pthread_attr.c 3.16 KB
a752c7ab   elopes   add first test an...
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  /*
   * Copyright (C) 2013 Freie Universität Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup pthread
   * @{
   * @file
   * @brief   Thread creation attributes.
   * @author  Christian Mehlis <mehlis@inf.fu-berlin.de>
   * @author  René Kijewski <kijewski@inf.fu-berlin.de>
   * @}
   */
  
  #include <string.h>
  
  #include "pthread.h"
  
  int pthread_attr_init(pthread_attr_t *attr)
  {
      memset(attr, 0, sizeof (*attr));
      return 0;
  }
  
  int pthread_attr_destroy(pthread_attr_t *attr)
  {
      (void) attr;
      return 0;
  }
  
  int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
  {
      *detachstate = attr->detached ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE;
      return 0;
  }
  
  int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
  {
      switch (detachstate) {
          case PTHREAD_CREATE_DETACHED:
              attr->detached = 1;
              return 0;
          case PTHREAD_CREATE_JOINABLE:
              attr->detached = 0;
              return 0;
          default:
              return -1;
      }
  }
  
  int pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
  {
      // TODO
      (void) attr;
      (void) guardsize;
      return -1;
  }
  
  int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
  {
      // TODO
      (void) attr;
      (void) guardsize;
      return -1;
  }
  
  int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param)
  {
      // TODO
      (void) attr;
      (void) param;
      return -1;
  }
  
  int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param)
  {
      // TODO
      (void) attr;
      (void) param;
      return -1;
  }
  
  int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
  {
      // TODO
      (void) attr;
      (void) policy;
      return -1;
  }
  
  int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
  {
      // TODO
      (void) attr;
      (void) policy;
      return -1;
  }
  
  int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit)
  {
      // TODO
      (void) attr;
      (void) inherit;
      return -1;
  }
  
  int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit)
  {
      // TODO
      (void) attr;
      (void) inherit;
      return -1;
  }
  
  int pthread_attr_getscope(const pthread_attr_t *attr, int *scope)
  {
      // TODO
      (void) attr;
      (void) scope;
      return -1;
  }
  
  int pthread_attr_setscope(pthread_attr_t *attr, int scope)
  {
      // TODO
      (void) attr;
      (void) scope;
      return -1;
  }
  
  int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr)
  {
      *stackaddr = attr->ss_sp;
      return 0;
  }
  
  int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr)
  {
      attr->ss_sp = (char *) stackaddr;
      return 0;
  }
  
  int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
  {
      *stacksize = attr->ss_size;
      if (*stacksize == 0) {
          /* FIXME: the standard says that this function should return the default value if no explicit value was set. */
      }
      return 0;
  }
  
  int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
  {
      attr->ss_size = stacksize;
      return 0;
  }