pthread: Cleanups for attr init/destroy

* Zero all fields of the attr structure when initializing
* Can implement pthread_attr_destroy() by calling pthread_attr_init()
This commit is contained in:
Angus Gratton 2021-04-23 10:02:08 +10:00
parent a6dea64106
commit c6b2191643

View File

@ -728,6 +728,7 @@ int pthread_mutexattr_init(pthread_mutexattr_t *attr)
if (!attr) {
return EINVAL;
}
memset(attr, 0, sizeof(*attr));
attr->type = PTHREAD_MUTEX_NORMAL;
attr->is_initialized = 1;
return 0;
@ -769,6 +770,7 @@ int pthread_attr_init(pthread_attr_t *attr)
{
if (attr) {
/* Nothing to allocate. Set everything to default */
memset(attr, 0, sizeof(*attr));
attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT;
attr->detachstate = PTHREAD_CREATE_JOINABLE;
return 0;
@ -778,13 +780,8 @@ int pthread_attr_init(pthread_attr_t *attr)
int pthread_attr_destroy(pthread_attr_t *attr)
{
if (attr) {
/* Nothing to deallocate. Reset everything to default */
attr->stacksize = CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT;
attr->detachstate = PTHREAD_CREATE_JOINABLE;
return 0;
}
return EINVAL;
/* Nothing to deallocate. Reset everything to default */
return pthread_attr_init(attr);
}
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)