diff --git a/Documentation/reference/user/08_pthread.rst b/Documentation/reference/user/08_pthread.rst index d951b1f369..ea406e5b38 100644 --- a/Documentation/reference/user/08_pthread.rst +++ b/Documentation/reference/user/08_pthread.rst @@ -112,11 +112,9 @@ No support for the following pthread interfaces is provided by NuttX: - ``pthread_attr_getguardsize``. get and set the thread guardsize attribute. - ``pthread_attr_getscope``. get and set the contentionscope attribute. - - ``pthread_attr_getstackaddr``. get and set the stackaddr attribute. - ``pthread_attr_setguardsize``. get and set the thread guardsize attribute. - ``pthread_attr_setscope``. get and set the contentionscope attribute. - - ``pthread_attr_setstackaddr``. get and set the stackaddr attribute. - ``pthread_condattr_getpshared``. get the process-shared condition variable attribute. - ``pthread_condattr_setpshared``. set the process-shared condition diff --git a/include/pthread.h b/include/pthread.h index 496234e250..89db797e8b 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -468,6 +468,12 @@ int pthread_attr_getaffinity_np(FAR const pthread_attr_t *attr, /* Set or obtain the default stack size */ +int pthread_attr_setstackaddr(FAR pthread_attr_t *attr, FAR void *stackaddr); +int pthread_attr_getstackaddr(FAR const pthread_attr_t *attr, + FAR void **stackaddr); + +/* Set or obtain the default stack size */ + int pthread_attr_setstacksize(FAR pthread_attr_t *attr, size_t stacksize); int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, FAR size_t *stacksize); @@ -476,7 +482,7 @@ int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, int pthread_attr_setstack(FAR pthread_attr_t *attr, FAR void *stackaddr, size_t stacksize); -int pthread_attr_getstack(FAR pthread_attr_t *attr, +int pthread_attr_getstack(FAR const pthread_attr_t *attr, FAR void **stackaddr, FAR size_t *stacksize); /* Set or get the name of a thread */ diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs index 0e2e152ea0..dd590e1643 100644 --- a/libs/libc/pthread/Make.defs +++ b/libs/libc/pthread/Make.defs @@ -31,6 +31,7 @@ CSRCS += pthread_attr_init.c pthread_attr_destroy.c CSRCS += pthread_attr_setschedpolicy.c pthread_attr_getschedpolicy.c CSRCS += pthread_attr_setinheritsched.c pthread_attr_getinheritsched.c CSRCS += pthread_attr_setdetachstate.c pthread_attr_getdetachstate.c +CSRCS += pthread_attr_setstackaddr.c pthread_attr_getstackaddr.c CSRCS += pthread_attr_setstacksize.c pthread_attr_getstacksize.c CSRCS += pthread_attr_setstack.c pthread_attr_getstack.c CSRCS += pthread_attr_setschedparam.c pthread_attr_getschedparam.c diff --git a/libs/libc/pthread/pthread_attr_getstack.c b/libs/libc/pthread/pthread_attr_getstack.c index 8b3c143c8f..4a35a9f422 100644 --- a/libs/libc/pthread/pthread_attr_getstack.c +++ b/libs/libc/pthread/pthread_attr_getstack.c @@ -22,10 +22,7 @@ * Included Files ****************************************************************************/ -#include #include -#include -#include #include /**************************************************************************** @@ -36,10 +33,13 @@ * Name: pthread_attr_getstack * * Description: + * The pthread_attr_getstack() function shall get the thread creation stack + * attributes stackaddr and stacksize from the attr object. * * Parameters: - * attr - * stacksize + * attr - thread attributes to be queried. + * stackaddr - stack address pointer + * stacksize - stack size pointer * * Return Value: * 0 if successful. Otherwise, an error code. @@ -48,14 +48,11 @@ * ****************************************************************************/ -int pthread_attr_getstack(FAR pthread_attr_t *attr, +int pthread_attr_getstack(FAR const pthread_attr_t *attr, FAR void **stackaddr, FAR size_t *stacksize) { int ret; - linfo("attr=%p stackaddr=%p stacksize=%p\n", - attr, stackaddr, stacksize); - if (!attr || !stackaddr || !stacksize) { ret = EINVAL; @@ -67,6 +64,5 @@ int pthread_attr_getstack(FAR pthread_attr_t *attr, ret = OK; } - linfo("Returning %d\n", ret); return ret; } diff --git a/libs/libc/pthread/pthread_attr_getstackaddr.c b/libs/libc/pthread/pthread_attr_getstackaddr.c new file mode 100644 index 0000000000..0b0ba13d79 --- /dev/null +++ b/libs/libc/pthread/pthread_attr_getstackaddr.c @@ -0,0 +1,66 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_attr_getstackaddr.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_attr_getstackaddr + * + * Description: + * The pthread_attr_getstack() function shall get the thread creation stack + * attributes stackaddr from the attr object. + * + * Parameters: + * attr - thread attributes to be queried. + * stackaddr - stack address pointer + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_getstackaddr(FAR const pthread_attr_t *attr, + FAR void **stackaddr) +{ + int ret; + + if (!attr || !stackaddr) + { + ret = EINVAL; + } + else + { + *stackaddr = attr->stackaddr; + ret = OK; + } + + return ret; +} diff --git a/libs/libc/pthread/pthread_attr_getstacksize.c b/libs/libc/pthread/pthread_attr_getstacksize.c index 11e9348b45..56b3dc2dc2 100644 --- a/libs/libc/pthread/pthread_attr_getstacksize.c +++ b/libs/libc/pthread/pthread_attr_getstacksize.c @@ -22,10 +22,7 @@ * Included Files ****************************************************************************/ -#include #include -#include -#include #include /**************************************************************************** @@ -36,10 +33,12 @@ * Name: pthread_attr_getstacksize * * Description: + * The pthread_attr_getstack() function shall get the thread creation stack + * attributes stacksize from the attr object. * * Input Parameters: - * attr - * stacksize + * attr - thread attributes to be queried. + * stacksize - stack size pointer * * Returned Value: * 0 if successful. Otherwise, an error code. @@ -53,8 +52,6 @@ int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, { int ret; - linfo("attr=%p stacksize=%p\n", attr, stacksize); - if (!stacksize) { ret = EINVAL; @@ -65,6 +62,5 @@ int pthread_attr_getstacksize(FAR const pthread_attr_t *attr, ret = OK; } - linfo("Returning %d\n", ret); return ret; } diff --git a/libs/libc/pthread/pthread_attr_setstack.c b/libs/libc/pthread/pthread_attr_setstack.c index 65e06fb01e..9c68a36d79 100644 --- a/libs/libc/pthread/pthread_attr_setstack.c +++ b/libs/libc/pthread/pthread_attr_setstack.c @@ -22,11 +22,7 @@ * Included Files ****************************************************************************/ -#include - #include -#include -#include #include /**************************************************************************** @@ -37,11 +33,13 @@ * Name: pthread_attr_setstack * * Description: + * The pthread_attr_setstack() function shall set the thread creation stack + * attributes stackaddr and stacksize in the attr object. * * Parameters: - * attr - * stackaddr - * stacksize + * attr - thread attributes to be modified. + * stackaddr - stack address + * stacksize - stack size * * Return Value: * 0 if successful. Otherwise, an error code. @@ -55,9 +53,6 @@ int pthread_attr_setstack(FAR pthread_attr_t *attr, { int ret; - linfo("attr=%p stackaddr=%p stacksize=%zu\n", - attr, stackaddr, stacksize); - if (!attr || !stackaddr || stacksize < PTHREAD_STACK_MIN) { ret = EINVAL; @@ -69,6 +64,5 @@ int pthread_attr_setstack(FAR pthread_attr_t *attr, ret = OK; } - linfo("Returning %d\n", ret); return ret; } diff --git a/libs/libc/pthread/pthread_attr_setstackaddr.c b/libs/libc/pthread/pthread_attr_setstackaddr.c new file mode 100644 index 0000000000..d2cfd5dc75 --- /dev/null +++ b/libs/libc/pthread/pthread_attr_setstackaddr.c @@ -0,0 +1,65 @@ +/**************************************************************************** + * libs/libc/pthread/pthread_attr_setstackaddr.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pthread_attr_setstackaddr + * + * Description: + * The pthread_attr_setstack() function shall set the thread creation stack + * attributes stackaddr in the attr object. + * + * Parameters: + * attr - thread attributes to be modified. + * stackaddr - stack address + * + * Return Value: + * 0 if successful. Otherwise, an error code. + * + * Assumptions: + * + ****************************************************************************/ + +int pthread_attr_setstackaddr(FAR pthread_attr_t *attr, FAR void *stackaddr) +{ + int ret; + + if (!attr || !stackaddr) + { + ret = EINVAL; + } + else + { + attr->stackaddr = stackaddr; + ret = OK; + } + + return ret; +} diff --git a/libs/libc/pthread/pthread_attr_setstacksize.c b/libs/libc/pthread/pthread_attr_setstacksize.c index aaab30b2e8..f3de28de17 100644 --- a/libs/libc/pthread/pthread_attr_setstacksize.c +++ b/libs/libc/pthread/pthread_attr_setstacksize.c @@ -22,11 +22,7 @@ * Included Files ****************************************************************************/ -#include - #include -#include -#include #include /**************************************************************************** @@ -37,10 +33,12 @@ * Name: pthread_attr_setstacksize * * Description: + * The pthread_attr_setstack() function shall set the thread creation stack + * attributes stacksize in the attr object. * * Input Parameters: - * attr - * stacksize + * attr - thread attributes to be modified. + * stacksize - stack size * * Returned Value: * 0 if successful. Otherwise, an error code. @@ -53,8 +51,6 @@ int pthread_attr_setstacksize(FAR pthread_attr_t *attr, size_t stacksize) { int ret; - linfo("attr=%p stacksize=%zu\n", attr, stacksize); - if (!attr || stacksize < PTHREAD_STACK_MIN) { ret = EINVAL; @@ -65,6 +61,5 @@ int pthread_attr_setstacksize(FAR pthread_attr_t *attr, size_t stacksize) ret = OK; } - linfo("Returning %d\n", ret); return ret; }