int pthread_attr_getstacksize (const pthread_attr_t * attr, size_t * stacksize) /* * ------------------------------------------------------ * DOCPUBLIC * This function determines the size of the stack on * which threads created with 'attr' will run. * * PARAMETERS * attr * pointer to an instance of pthread_attr_t * * stacksize * pointer to size_t into which is returned the * stack size, in bytes. * * * DESCRIPTION * This function determines the size of the stack on * which threads created with 'attr' will run. * * NOTES: * 1) Function supported only if this macro is * defined: * * _POSIX_THREAD_ATTR_STACKSIZE * * 2) Use on newly created attributes object to * find the default stack size. * * RESULTS * 0 successfully retrieved stack size, * EINVAL 'attr' is invalid * ENOSYS function not supported * * ------------------------------------------------------ */ { #ifdef _POSIX_THREAD_ATTR_STACKSIZE if (ptw32_is_attr (attr) != 0) { return EINVAL; } /* Everything is okay. */ *stacksize = (*attr)->stacksize; return 0; #else return ENOSYS; #endif /* _POSIX_THREAD_ATTR_STACKSIZE */ }
int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr) /* * ------------------------------------------------------ * DOCPUBLIC * This function determines the address of the stack * on which threads created with 'attr' will run. * * PARAMETERS * attr * pointer to an instance of pthread_attr_t * * stackaddr * pointer into which is returned the stack address. * * * DESCRIPTION * This function determines the address of the stack * on which threads created with 'attr' will run. * * NOTES: * 1) Function supported only if this macro is * defined: * * _POSIX_THREAD_ATTR_STACKADDR * * 2) Create only one thread for each stack * address.. * * RESULTS * 0 successfully retreived stack address, * EINVAL 'attr' is invalid * ENOSYS function not supported * * ------------------------------------------------------ */ { #if defined( _POSIX_THREAD_ATTR_STACKADDR ) if (ptw32_is_attr(attr) != 0) { return EINVAL; } *stackaddr = (*attr)->stackaddr; return 0; #else return ENOSYS; #endif /* _POSIX_THREAD_ATTR_STACKADDR */ }
int pthread_attr_getinheritsched (pthread_attr_t * attr, int *inheritsched) { if (ptw32_is_attr (attr) != 0 || inheritsched == NULL) { return EINVAL; } *inheritsched = (*attr)->inheritsched; return 0; }
int pthread_attr_getschedparam (const pthread_attr_t * attr, struct sched_param *param) { if (ptw32_is_attr (attr) != 0 || param == NULL) { return EINVAL; } memcpy (param, &(*attr)->param, sizeof (*param)); return 0; }
int pthread_attr_setaffinity_np (pthread_attr_t * attr, size_t cpusetsize, const cpu_set_t * cpuset) { if (ptw32_is_attr (attr) != 0 || cpuset == NULL) { return EINVAL; } (*attr)->cpuset = ((_sched_cpu_set_vector_*)cpuset)->_cpuset; return 0; }
// Get a pthread_attr_t containing attributes of the given pthread_t. int pthread_getattr_np(pthread_t tid, pthread_attr_t* attr) { ptw32_thread_t* thread_ptr; if (ptw32_is_attr(attr) != 0) { return EINVAL; } thread_ptr = (ptw32_thread_t*)to_internal(tid).p; (*attr)->stacksize = thread_ptr->stackSize; (*attr)->stackaddr = thread_ptr->stackAddr; (*attr)->detachstate = thread_ptr->detachState; (*attr)->param.sched_priority = thread_ptr->sched_priority; return 0; }
int pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate) /* * ------------------------------------------------------ * DOCPUBLIC * This function specifies whether threads created with * 'attr' will run detached. * * PARAMETERS * attr * pointer to an instance of pthread_attr_t * * detachstate * an integer containing one of: * * PTHREAD_CREATE_JOINABLE * Thread ID is valid, must be joined * * PTHREAD_CREATE_DETACHED * Thread ID is invalid, cannot be joined, * canceled, or modified * * * DESCRIPTION * This function specifies whether threads created with * 'attr' will run detached. * * NOTES: * 1) You cannot join or cancel detached threads. * * RESULTS * 0 successfully set detach state, * EINVAL 'attr' or 'detachstate' is invalid * * ------------------------------------------------------ */ { if (ptw32_is_attr (attr) != 0) { return EINVAL; } if (detachstate != PTHREAD_CREATE_JOINABLE && detachstate != PTHREAD_CREATE_DETACHED) { return EINVAL; } (*attr)->detachstate = detachstate; return 0; }
int pthread_attr_destroy (pthread_attr_t * attr) { if (ptw32_is_attr (attr) != 0) { return EINVAL; } (*attr)->valid = 0; free (*attr); *attr = NULL; return 0; }
int pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy) { if (ptw32_is_attr (attr) != 0) { return EINVAL; } if (policy != SCHED_OTHER) { return ENOTSUP; } return 0; }
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) /* * ------------------------------------------------------ * DOCPUBLIC * This function determines whether threads created with * 'attr' will run detached. * * PARAMETERS * attr * pointer to an instance of pthread_attr_t * * detachstate * pointer to an integer into which is returned one * of: * * PTHREAD_CREATE_JOINABLE * Thread ID is valid, must be joined * * PTHREAD_CREATE_DETACHED * Thread ID is invalid, cannot be joined, * canceled, or modified * * * DESCRIPTION * This function determines whether threads created with * 'attr' will run detached. * * NOTES: * 1) You cannot join or cancel detached threads. * * RESULTS * 0 successfully retrieved detach state, * EINVAL 'attr' is invalid * * ------------------------------------------------------ */ { if (ptw32_is_attr(attr) != 0 || detachstate == NULL) { *detachstate = PTHREAD_CREATE_DETACHED; return EINVAL; } *detachstate = (*attr)->detachstate; return 0; }
int pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate) { if (ptw32_is_attr (attr) != 0) { return EINVAL; } if (detachstate != PTHREAD_CREATE_JOINABLE && detachstate != PTHREAD_CREATE_DETACHED) { return EINVAL; } (*attr)->detachstate = detachstate; return 0; }
int pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched) { if (ptw32_is_attr (attr) != 0) { return EINVAL; } if (PTHREAD_INHERIT_SCHED != inheritsched && PTHREAD_EXPLICIT_SCHED != inheritsched) { return EINVAL; } (*attr)->inheritsched = inheritsched; return 0; }
int pthread_attr_getstackaddr (const pthread_attr_t * attr, void **stackaddr) { #if defined( _POSIX_THREAD_ATTR_STACKADDR ) if (ptw32_is_attr (attr) != 0) { return EINVAL; } *stackaddr = (*attr)->stackaddr; return 0; #else return ENOSYS; #endif }
int pthread_attr_getschedpolicy (pthread_attr_t * attr, int *policy) { if (ptw32_is_attr (attr) != 0 || policy == NULL) { return EINVAL; } /* * Validate the policy arg. * Check that a policy constant wasn't passed rather than &policy. */ if (policy <= (int *) SCHED_MAX) { return EINVAL; } *policy = SCHED_OTHER; return 0; }
int pthread_attr_destroy (pthread_attr_t * attr) /* * ------------------------------------------------------ * DOCPUBLIC * Destroys a thread attributes object. * * PARAMETERS * attr * pointer to an instance of pthread_attr_t * * * DESCRIPTION * Destroys a thread attributes object. * * NOTES: * 1) Does not affect threads created with 'attr'. * * RESULTS * 0 successfully destroyed attr, * EINVAL 'attr' is invalid. * * ------------------------------------------------------ */ { if (ptw32_is_attr (attr) != 0) { return EINVAL; } /* * Set the attribute object to a specific invalid value. */ (*attr)->valid = 0; free (*attr); *attr = NULL; return 0; }
int pthread_attr_setschedparam (pthread_attr_t * attr, const struct sched_param *param) { int priority; if (ptw32_is_attr (attr) != 0 || param == NULL) { return EINVAL; } priority = param->sched_priority; /* Validate priority level. */ if (priority < sched_get_priority_min (SCHED_OTHER) || priority > sched_get_priority_max (SCHED_OTHER)) { return EINVAL; } memcpy (&(*attr)->param, param, sizeof (*param)); return 0; }