File: pthread_attr.c

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (310 lines) | stat: -rw-r--r-- 5,679 bytes parent folder | download
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
 * Copyright (c) 1996, 1998, 1999 University of Utah and the Flux Group.
 * All rights reserved.
 * 
 * This file is part of the Flux OSKit.  The OSKit is free software, also known
 * as "open source;" you can redistribute it and/or modify it under the terms
 * of the GNU General Public License (GPL), version 2, as published by the Free
 * Software Foundation (FSF).  To explore alternate licensing terms, contact
 * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
 * 
 * The OSKit 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 GPL for more details.  You should have
 * received a copy of the GPL along with the OSKit; see the file COPYING.  If
 * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
 */

/*
 * Basic attributes stuff.
 */
#include <threads/pthread_internal.h>
#include <oskit/c/string.h>

int
pthread_attr_init(pthread_attr_t *attr)
{
	attr->detachstate = PTHREAD_CREATE_JOINABLE;
	attr->priority    = PRIORITY_NORMAL;
	attr->stacksize   = PTHREAD_STACK_MIN;
	attr->guardsize   = DEFAULT_STACKGUARD;
	attr->stackaddr   = 0;
	attr->policy      = SCHED_RR;
	attr->inherit     = PTHREAD_EXPLICIT_SCHED;
#ifdef	CPU_INHERIT
	attr->scheduler   = 0;
	attr->opaque      = 0;
#endif
	return 0;
}

int
pthread_attr_destroy(pthread_attr_t *attr)
{
	memset((void *) attr, -1, sizeof(*attr));

	return 0;
}

int
pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize)
{
#ifdef	STACKGUARD
	if (guardsize < 0)
		return EINVAL;
	
	attr->guardsize = guardsize;
	return 0;
#else
	printf("pthread_attr_setguardsize: STACKGUARD not defined\n");
	return EINVAL;
#endif
}

int
pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize)
{
#ifdef	STACKGUARD
	*guardsize = attr->guardsize;
	return 0;
#else
	printf("pthread_attr_getguardsize: STACKGUARD not defined\n");
	return EINVAL;
#endif
}

int
pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
{
	if (detachstate != PTHREAD_CREATE_JOINABLE &&
	    detachstate != PTHREAD_CREATE_DETACHED)
		return EINVAL;
	
	attr->detachstate = detachstate;

	return 0;
}

int
pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
{
	*detachstate = attr->detachstate;

	return 0;
}

int
pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritstate)
{
	if (inheritstate != PTHREAD_INHERIT_SCHED &&
	    inheritstate != PTHREAD_EXPLICIT_SCHED)
		return EINVAL;
	
	attr->inherit = inheritstate;

	return 0;
}

int
pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritstate)
{
	*inheritstate = attr->inherit;

	return 0;
}

int
pthread_attr_setschedparam(pthread_attr_t *attr,
			   const struct sched_param *param)
{
	int	pri = param->priority;
		
	if (pri < PRIORITY_MIN || pri > PRIORITY_MAX)
		return EINVAL;
	
	attr->priority = pri;
	
	return 0;
}

int
pthread_attr_getschedparam(pthread_attr_t *attr, struct sched_param *param)
{
	param->priority = attr->priority;
	return 0;
}

int
pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
{
	switch (policy) {
	case SCHED_FIFO:
	case SCHED_RR:
		attr->policy = policy;
		break;

	case SCHED_DECAY:
		printf("pthread_attr_setschedpolicy: "
		       "SCHED_DECAY not supported yet\n");

	default:
		return EINVAL;
	}

	return 0;
}

int
pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
{
	*policy = attr->policy;

	return 0;
}

int
pthread_attr_setstackaddr(pthread_attr_t *attr, oskit_u32_t stackaddr)
{
	attr->stackaddr = stackaddr;
	return 0;
}

int
pthread_attr_getstackaddr(const pthread_attr_t *attr, oskit_u32_t *stackaddr)
{
	*stackaddr = attr->stackaddr;
	return 0;
}

int
pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize)
{
	if (stacksize < PTHREAD_STACK_MIN)
		return EINVAL;
	
	attr->stacksize = stacksize;

	return 0;
}

int
pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
{
	*stacksize = attr->stacksize;

	return 0;
}

/*
 * Local
 */
int
oskit_pthread_attr_setprio(pthread_attr_t *attr, int pri)
{
	if (pri < PRIORITY_MIN || pri > PRIORITY_MAX)
		return EINVAL;
	
	attr->priority = pri;
	
	return 0;
}

#ifdef	CPU_INHERIT
int
pthread_attr_setopaque(pthread_attr_t *attr, oskit_u32_t opaque)
{
	attr->opaque = opaque;
	
	return 0;
}

int
pthread_attr_setscheduler(pthread_attr_t *attr, pthread_t tid)
{
	if (tidtothread(tid) == NULL_THREADPTR)
		return EINVAL;

	attr->scheduler = tid;
	
	return 0;
}
#endif

int
pthread_mutexattr_init(pthread_mutexattr_t *attr)
{
	attr->priority_inherit = PTHREAD_PRIO_NONE;
	
	return 0;
}

int
pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
{
	memset((void *) attr, -1, sizeof(*attr));
	
	return 0;
}

int
pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int inherit)
{
	switch (inherit) {
	case PTHREAD_PRIO_NONE:
	case PTHREAD_PRIO_INHERIT:
		attr->priority_inherit = inherit;
		break;

	default:
		return EINVAL;
	}

	return 0;
}

int
pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *inherit)
{
	*inherit = attr->priority_inherit;

	return 0;
}

int
pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
{
	switch (type) {
	case PTHREAD_MUTEX_NORMAL:
	case PTHREAD_MUTEX_ERRORCHECK:
	case PTHREAD_MUTEX_RECURSIVE:
	case PTHREAD_MUTEX_DEFAULT:
		attr->type = type;
		break;

	default:
		return EINVAL;
	}

	return 0;
}

int
pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type)
{
	*type = attr->type;

	return 0;
}

int
pthread_condattr_init(pthread_condattr_t *attr)
{
	return 0;
}

int
pthread_condattr_destroy(pthread_condattr_t *attr)
{
	return 0;
}