hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
/*
 * Copyright (C) 2011 Philippe Gerum <rpm@xenomai.org>.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
 
#include <stddef.h>
#include <errno.h>
#include <pthread.h>
#include <memory.h>
#include <cobalt/uapi/thread.h>
#include "internal.h"
 
COBALT_IMPL(int, pthread_attr_init, (pthread_attr_t *attr))
{
   __STD(pthread_attr_init)(attr);
   return pthread_attr_setstacksize(attr, PTHREAD_STACK_DEFAULT);
}
 
int pthread_attr_init_ex(pthread_attr_ex_t *attr_ex)
{
   struct sched_param param;
   int policy;
 
   /* Start with defaulting all fields to null. */
   memset(attr_ex, 0, sizeof(*attr_ex));
   /* Merge in the default standard attribute set. */
   __COBALT(pthread_attr_init)(&attr_ex->std);
   pthread_attr_getschedpolicy(&attr_ex->std, &policy);
   attr_ex->nonstd.sched_policy = policy;
   pthread_attr_getschedparam(&attr_ex->std, &param);
   attr_ex->nonstd.sched_param.sched_priority = param.sched_priority;
 
   return 0;
}
 
int pthread_attr_destroy_ex(pthread_attr_ex_t *attr_ex)
{
   return pthread_attr_destroy(&attr_ex->std);
}
 
int pthread_attr_setschedpolicy_ex(pthread_attr_ex_t *attr_ex,
                  int policy)
{
   attr_ex->nonstd.sched_policy = policy;
 
   return 0;
}
 
int pthread_attr_getschedpolicy_ex(const pthread_attr_ex_t *attr_ex,
                  int *policy)
{
   *policy = attr_ex->nonstd.sched_policy;
 
   return 0;
}
 
int pthread_attr_setschedparam_ex(pthread_attr_ex_t *attr_ex,
                 const struct sched_param_ex *param_ex)
{
   attr_ex->nonstd.sched_param = *param_ex;
 
   return 0;
}
 
int pthread_attr_getschedparam_ex(const pthread_attr_ex_t *attr_ex,
                 struct sched_param_ex *param_ex)
{
   *param_ex = attr_ex->nonstd.sched_param;
 
   return 0;
}
 
int pthread_attr_setinheritsched_ex(pthread_attr_ex_t *attr_ex,
                   int inheritsched)
{
   return pthread_attr_setinheritsched(&attr_ex->std, inheritsched);
}
 
int pthread_attr_getinheritsched_ex(const pthread_attr_ex_t *attr_ex,
                   int *inheritsched)
{
   return pthread_attr_getinheritsched(&attr_ex->std, inheritsched);
}
 
int pthread_attr_getdetachstate_ex(const pthread_attr_ex_t *attr_ex,
                  int *detachstate)
{
   return pthread_attr_getdetachstate(&attr_ex->std, detachstate);
}
 
int pthread_attr_setdetachstate_ex(pthread_attr_ex_t *attr_ex,
                  int detachstate)
{
   return pthread_attr_setdetachstate(&attr_ex->std, detachstate);
}
 
int pthread_attr_getstacksize_ex(const pthread_attr_ex_t *attr_ex,
                size_t *stacksize)
{
   return pthread_attr_getstacksize(&attr_ex->std, stacksize);
}
 
int pthread_attr_setstacksize_ex(pthread_attr_ex_t *attr_ex,
                size_t stacksize)
{
   return pthread_attr_setstacksize(&attr_ex->std, stacksize);
}
 
int pthread_attr_getscope_ex(const pthread_attr_ex_t *attr_ex,
                int *scope)
{
   return pthread_attr_getscope(&attr_ex->std, scope);
}
 
int pthread_attr_setscope_ex(pthread_attr_ex_t *attr_ex,
                int scope)
{
   return pthread_attr_setscope(&attr_ex->std, scope);
}
 
int pthread_attr_getpersonality_ex(const pthread_attr_ex_t *attr_ex,
                  int *personality)
{
   *personality = attr_ex->nonstd.personality;
 
   return 0;
}
 
int pthread_attr_setpersonality_ex(pthread_attr_ex_t *attr_ex,
                  int personality)
{
   attr_ex->nonstd.personality = personality;
 
   return 0;
}