libc/pthread: Implement pthread_attr_[set|get]stackaddr

https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-01-20 22:30:36 +08:00 committed by Gustavo Henrique Nihei
parent 36b74bab02
commit c11cd7f103
9 changed files with 158 additions and 41 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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

View File

@ -22,10 +22,7 @@
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <pthread.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
/****************************************************************************
@ -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;
}

View File

@ -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 <pthread.h>
#include <errno.h>
/****************************************************************************
* 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;
}

View File

@ -22,10 +22,7 @@
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <pthread.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
/****************************************************************************
@ -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;
}

View File

@ -22,11 +22,7 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <pthread.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
/****************************************************************************
@ -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;
}

View File

@ -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 <pthread.h>
#include <errno.h>
/****************************************************************************
* 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;
}

View File

@ -22,11 +22,7 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <pthread.h>
#include <string.h>
#include <debug.h>
#include <errno.h>
/****************************************************************************
@ -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;
}