You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gu...@apache.org on 2023/01/24 16:53:11 UTC
[nuttx] 03/04: libc/pthread: Implement pthread_attr_[set|get]stackaddr
This is an automated email from the ASF dual-hosted git repository.
gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit c11cd7f103323d910235a5782c5f1416895bac62
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 20 22:30:36 2023 +0800
libc/pthread: Implement pthread_attr_[set|get]stackaddr
https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
Documentation/reference/user/08_pthread.rst | 2 --
include/pthread.h | 8 ++++++-
libs/libc/pthread/Make.defs | 1 +
libs/libc/pthread/pthread_attr_getstack.c | 16 +++++--------
...attr_getstack.c => pthread_attr_getstackaddr.c} | 24 ++++++++-----------
libs/libc/pthread/pthread_attr_getstacksize.c | 12 ++++------
libs/libc/pthread/pthread_attr_setstack.c | 16 ++++---------
..._setstacksize.c => pthread_attr_setstackaddr.c} | 27 +++++++++-------------
libs/libc/pthread/pthread_attr_setstacksize.c | 13 ++++-------
9 files changed, 47 insertions(+), 72 deletions(-)
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 <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;
}
diff --git a/libs/libc/pthread/pthread_attr_getstack.c b/libs/libc/pthread/pthread_attr_getstackaddr.c
similarity index 78%
copy from libs/libc/pthread/pthread_attr_getstack.c
copy to libs/libc/pthread/pthread_attr_getstackaddr.c
index 8b3c143c8f..0b0ba13d79 100644
--- a/libs/libc/pthread/pthread_attr_getstack.c
+++ b/libs/libc/pthread/pthread_attr_getstackaddr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * libs/libc/pthread/pthread_attr_getstack.c
+ * 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
@@ -22,10 +22,7 @@
* Included Files
****************************************************************************/
-#include <sys/types.h>
#include <pthread.h>
-#include <string.h>
-#include <debug.h>
#include <errno.h>
/****************************************************************************
@@ -33,13 +30,15 @@
****************************************************************************/
/****************************************************************************
- * Name: pthread_attr_getstack
+ * Name: pthread_attr_getstackaddr
*
* Description:
+ * The pthread_attr_getstack() function shall get the thread creation stack
+ * attributes stackaddr from the attr object.
*
* Parameters:
- * attr
- * stacksize
+ * attr - thread attributes to be queried.
+ * stackaddr - stack address pointer
*
* Return Value:
* 0 if successful. Otherwise, an error code.
@@ -48,25 +47,20 @@
*
****************************************************************************/
-int pthread_attr_getstack(FAR pthread_attr_t *attr,
- FAR void **stackaddr, FAR size_t *stacksize)
+int pthread_attr_getstackaddr(FAR const pthread_attr_t *attr,
+ FAR void **stackaddr)
{
int ret;
- linfo("attr=%p stackaddr=%p stacksize=%p\n",
- attr, stackaddr, stacksize);
-
- if (!attr || !stackaddr || !stacksize)
+ if (!attr || !stackaddr)
{
ret = EINVAL;
}
else
{
*stackaddr = attr->stackaddr;
- *stacksize = attr->stacksize;
ret = OK;
}
- linfo("Returning %d\n", ret);
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 <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;
}
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 <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;
}
diff --git a/libs/libc/pthread/pthread_attr_setstacksize.c b/libs/libc/pthread/pthread_attr_setstackaddr.c
similarity index 78%
copy from libs/libc/pthread/pthread_attr_setstacksize.c
copy to libs/libc/pthread/pthread_attr_setstackaddr.c
index aaab30b2e8..d2cfd5dc75 100644
--- a/libs/libc/pthread/pthread_attr_setstacksize.c
+++ b/libs/libc/pthread/pthread_attr_setstackaddr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * libs/libc/pthread/pthread_attr_setstacksize.c
+ * 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
@@ -22,11 +22,7 @@
* Included Files
****************************************************************************/
-#include <nuttx/config.h>
-
#include <pthread.h>
-#include <string.h>
-#include <debug.h>
#include <errno.h>
/****************************************************************************
@@ -34,37 +30,36 @@
****************************************************************************/
/****************************************************************************
- * Name: pthread_attr_setstacksize
+ * Name: pthread_attr_setstackaddr
*
* Description:
+ * The pthread_attr_setstack() function shall set the thread creation stack
+ * attributes stackaddr in the attr object.
*
- * Input Parameters:
- * attr
- * stacksize
+ * Parameters:
+ * attr - thread attributes to be modified.
+ * stackaddr - stack address
*
- * Returned Value:
+ * Return Value:
* 0 if successful. Otherwise, an error code.
*
* Assumptions:
*
****************************************************************************/
-int pthread_attr_setstacksize(FAR pthread_attr_t *attr, size_t stacksize)
+int pthread_attr_setstackaddr(FAR pthread_attr_t *attr, FAR void *stackaddr)
{
int ret;
- linfo("attr=%p stacksize=%zu\n", attr, stacksize);
-
- if (!attr || stacksize < PTHREAD_STACK_MIN)
+ if (!attr || !stackaddr)
{
ret = EINVAL;
}
else
{
- attr->stacksize = stacksize;
+ attr->stackaddr = stackaddr;
ret = OK;
}
- linfo("Returning %d\n", ret);
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 <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;
}