• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define _GNU_SOURCE
2 #include "pthread_impl.h"
3 #include <string.h>
4 
5 #define MIN(a,b) ((a)<(b) ? (a) : (b))
6 #define MAX(a,b) ((a)>(b) ? (a) : (b))
7 
pthread_setattr_default_np(const pthread_attr_t * attrp)8 int pthread_setattr_default_np(const pthread_attr_t *attrp)
9 {
10 	/* Reject anything in the attr object other than stack/guard size. */
11 	pthread_attr_t tmp = *attrp, zero = { 0 };
12 	tmp._a_stacksize = 0;
13 	tmp._a_guardsize = 0;
14 	if (memcmp(&tmp, &zero, sizeof tmp))
15 		return EINVAL;
16 
17 	unsigned stack = MIN(attrp->_a_stacksize, DEFAULT_STACK_MAX);
18 	unsigned guard = MIN(attrp->_a_guardsize, DEFAULT_GUARD_MAX);
19 
20 	__inhibit_ptc();
21 	__default_stacksize = MAX(__default_stacksize, stack);
22 	__default_guardsize = MAX(__default_guardsize, guard);
23 	__release_ptc();
24 
25 	return 0;
26 }
27 
pthread_getattr_default_np(pthread_attr_t * attrp)28 int pthread_getattr_default_np(pthread_attr_t *attrp)
29 {
30 	__acquire_ptc();
31 	*attrp = (pthread_attr_t) {
32 		._a_stacksize = __default_stacksize,
33 		._a_guardsize = __default_guardsize,
34 	};
35 	__release_ptc();
36 	return 0;
37 }
38