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:08 UTC

[nuttx] branch master updated (f49c20d28f -> 8bf693b362)

This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from f49c20d28f litex: System clock frequency selectable from Kconfig.
     new 679544cd32 Documentation: Remove the supported function from the unsupported list
     new 36b74bab02 libc/pthread: Implement pthread_rwlockattr API
     new c11cd7f103 libc/pthread: Implement pthread_attr_[set|get]stackaddr
     new 8bf693b362 libc/pthread: Implement pthread_condattr_[set|get]pshared

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Documentation/reference/user/08_pthread.rst        | 33 ---------
 include/pthread.h                                  | 82 ++++++++++++++++------
 libs/libc/pthread/Make.defs                        |  4 ++
 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 ++--
 ..._getpshared.c => pthread_condattr_getpshared.c} | 12 ++--
 ..._setpshared.c => pthread_condattr_setpshared.c} | 18 ++---
 ...attr_destroy.c => pthread_rwlockattr_destroy.c} | 12 ++--
 ...etpshared.c => pthread_rwlockattr_getpshared.c} | 12 ++--
 ...arrierattr_init.c => pthread_rwlockattr_init.c} | 10 +--
 ...etpshared.c => pthread_rwlockattr_setpshared.c} | 18 ++---
 15 files changed, 146 insertions(+), 163 deletions(-)
 copy libs/libc/pthread/{pthread_attr_getstack.c => pthread_attr_getstackaddr.c} (78%)
 copy libs/libc/pthread/{pthread_attr_setstacksize.c => pthread_attr_setstackaddr.c} (78%)
 copy libs/libc/pthread/{pthread_barrierattr_getpshared.c => pthread_condattr_getpshared.c} (85%)
 copy libs/libc/pthread/{pthread_barrierattr_setpshared.c => pthread_condattr_setpshared.c} (87%)
 copy libs/libc/pthread/{pthread_barrierattr_destroy.c => pthread_rwlockattr_destroy.c} (84%)
 copy libs/libc/pthread/{pthread_barrierattr_getpshared.c => pthread_rwlockattr_getpshared.c} (85%)
 copy libs/libc/pthread/{pthread_barrierattr_init.c => pthread_rwlockattr_init.c} (87%)
 copy libs/libc/pthread/{pthread_barrierattr_setpshared.c => pthread_rwlockattr_setpshared.c} (87%)


[nuttx] 04/04: libc/pthread: Implement pthread_condattr_[set|get]pshared

Posted by gu...@apache.org.
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 8bf693b36256439e91b4996c449c937ab508fe6f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 20 22:41:20 2023 +0800

    libc/pthread: Implement pthread_condattr_[set|get]pshared
    
    https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_condattr_getpshared.html
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 Documentation/reference/user/08_pthread.rst     |  4 -
 include/pthread.h                               |  4 +
 libs/libc/pthread/Make.defs                     |  1 +
 libs/libc/pthread/pthread_condattr_getpshared.c | 68 +++++++++++++++++
 libs/libc/pthread/pthread_condattr_setpshared.c | 99 +++++++++++++++++++++++++
 5 files changed, 172 insertions(+), 4 deletions(-)

diff --git a/Documentation/reference/user/08_pthread.rst b/Documentation/reference/user/08_pthread.rst
index ea406e5b38..77017cef04 100644
--- a/Documentation/reference/user/08_pthread.rst
+++ b/Documentation/reference/user/08_pthread.rst
@@ -115,10 +115,6 @@ No support for the following pthread interfaces is provided by NuttX:
   -  ``pthread_attr_setguardsize``. get and set the thread guardsize
      attribute.
   -  ``pthread_attr_setscope``. get and set the contentionscope attribute.
-  -  ``pthread_condattr_getpshared``. get the process-shared condition
-     variable attribute.
-  -  ``pthread_condattr_setpshared``. set the process-shared condition
-     variable attribute.
   -  ``pthread_getconcurrency``. get and set the level of concurrency.
   -  ``pthread_getcpuclockid``. access a thread CPU-time clock.
   -  ``pthread_mutex_getprioceiling``. get and set the priority ceiling of
diff --git a/include/pthread.h b/include/pthread.h
index 89db797e8b..f03f007fe9 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -248,6 +248,7 @@ typedef pid_t pthread_t;
 
 struct pthread_condattr_s
 {
+  int pshared;
   clockid_t clockid;
 };
 
@@ -615,6 +616,9 @@ int pthread_mutex_consistent(FAR pthread_mutex_t *mutex);
 
 int pthread_condattr_init(FAR pthread_condattr_t *attr);
 int pthread_condattr_destroy(FAR pthread_condattr_t *attr);
+int pthread_condattr_getpshared(FAR const pthread_condattr_t *attr,
+                                FAR int *pshared);
+int pthread_condattr_setpshared(FAR pthread_condattr_t *attr, int pshared);
 int pthread_condattr_getclock(FAR const pthread_condattr_t *attr,
                               clockid_t *clock_id);
 int pthread_condattr_setclock(FAR pthread_condattr_t *attr,
diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs
index dd590e1643..fe9849c3c1 100644
--- a/libs/libc/pthread/Make.defs
+++ b/libs/libc/pthread/Make.defs
@@ -39,6 +39,7 @@ CSRCS += pthread_barrierattr_init.c pthread_barrierattr_destroy.c
 CSRCS += pthread_barrierattr_getpshared.c pthread_barrierattr_setpshared.c
 CSRCS += pthread_barrierinit.c pthread_barrierdestroy.c pthread_barrierwait.c
 CSRCS += pthread_condattr_init.c pthread_condattr_destroy.c
+CSRCS += pthread_condattr_getpshared.c pthread_condattr_setpshared.c
 CSRCS += pthread_condattr_setclock.c pthread_condattr_getclock.c
 CSRCS += pthread_condinit.c pthread_conddestroy.c pthread_condtimedwait.c
 CSRCS += pthread_create.c pthread_exit.c
diff --git a/libs/libc/pthread/pthread_condattr_getpshared.c b/libs/libc/pthread/pthread_condattr_getpshared.c
new file mode 100644
index 0000000000..5667a19ca4
--- /dev/null
+++ b/libs/libc/pthread/pthread_condattr_getpshared.c
@@ -0,0 +1,68 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_condattr_getpshared.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_condattr_getpshared
+ *
+ * Description:
+ *   The pthread_condattr_getpshared() function will obtain the value of the
+ *   process-shared attribute from the attributes object referenced by attr.
+ *
+ * Input Parameters:
+ *   attr - cond attributes to be queried.
+ *   pshared - the location to stored the current value of the pshared attribute.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if either attr or pshared is invalid.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_condattr_getpshared(FAR const pthread_condattr_t *attr,
+                                FAR int *pshared)
+{
+  int ret = OK;
+
+  if (!attr || !pshared)
+    {
+      ret = EINVAL;
+    }
+  else
+    {
+      *pshared = attr->pshared;
+    }
+
+  return ret;
+}
diff --git a/libs/libc/pthread/pthread_condattr_setpshared.c b/libs/libc/pthread/pthread_condattr_setpshared.c
new file mode 100644
index 0000000000..a5a17cadbe
--- /dev/null
+++ b/libs/libc/pthread/pthread_condattr_setpshared.c
@@ -0,0 +1,99 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_condattr_setpshared.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Type Declarations
+ ********************************************************************************/
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Data
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Function Prototypes
+ ********************************************************************************/
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_condattr_setpshared
+ *
+ * Description:
+ *   The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit
+ *   a cond to be operated upon by any thread that has access to the
+ *   memory where the cond is allocated. If the process-shared attribute
+ *   is PTHREAD_PROCESS_PRIVATE, the cond can only be operated upon by
+ *   threads created within the same process as the thread that initialized
+ *   the cond.
+ *   If threads of different processes attempt to operate on such a cond,
+ *   the behavior is undefined. The default value of the attribute is
+ *   PTHREAD_PROCESS_PRIVATE.
+ *
+ *   Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are
+ *   defined in pthread.h.
+ *
+ * Input Parameters:
+ *   attr - cond attributes to be modified.
+ *   pshared - the new value of the pshared attribute.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if either attr is invalid or pshared is not
+ *   one of PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_condattr_setpshared(FAR pthread_condattr_t *attr, int pshared)
+{
+  int ret = OK;
+
+  if (!attr || (pshared != PTHREAD_PROCESS_SHARED &&
+       pshared != PTHREAD_PROCESS_PRIVATE))
+    {
+      ret = EINVAL;
+    }
+  else
+    {
+      attr->pshared = pshared;
+    }
+
+  return ret;
+}


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

Posted by gu...@apache.org.
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;
 }


[nuttx] 02/04: libc/pthread: Implement pthread_rwlockattr API

Posted by gu...@apache.org.
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 36b74bab024b2b3bb4bfbf75c2f098a9e828fcfe
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 20 22:06:45 2023 +0800

    libc/pthread: Implement pthread_rwlockattr API
    
    https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlockattr_getpshared.html
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 Documentation/reference/user/08_pthread.rst       |  8 --
 include/pthread.h                                 | 70 +++++++++++-----
 libs/libc/pthread/Make.defs                       |  2 +
 libs/libc/pthread/pthread_rwlockattr_destroy.c    | 64 +++++++++++++++
 libs/libc/pthread/pthread_rwlockattr_getpshared.c | 68 ++++++++++++++++
 libs/libc/pthread/pthread_rwlockattr_init.c       | 67 +++++++++++++++
 libs/libc/pthread/pthread_rwlockattr_setpshared.c | 99 +++++++++++++++++++++++
 7 files changed, 351 insertions(+), 27 deletions(-)

diff --git a/Documentation/reference/user/08_pthread.rst b/Documentation/reference/user/08_pthread.rst
index 68f94bca63..d951b1f369 100644
--- a/Documentation/reference/user/08_pthread.rst
+++ b/Documentation/reference/user/08_pthread.rst
@@ -131,14 +131,6 @@ No support for the following pthread interfaces is provided by NuttX:
      attribute of the mutex attributes object.
   -  ``pthread_mutexattr_setprioceiling``. get and set the prioceiling
      attribute of the mutex attributes object.
-  -  ``pthread_rwlockattr_destroy``. destroy and initialize the read-write
-     lock attributes object.
-  -  ``pthread_rwlockattr_getpshared``. get and set the process-shared
-     attribute of the read-write lock attributes object.
-  -  ``pthread_rwlockattr_init``. destroy and initialize the read-write
-     lock attributes object.
-  -  ``pthread_rwlockattr_setpshared``. get and set the process-shared
-     attribute of the read-write lock attributes object.
   -  ``pthread_setconcurrency``. get and set the level of concurrency.
 
 .. c:function:: int pthread_attr_init(pthread_attr_t *attr);
diff --git a/include/pthread.h b/include/pthread.h
index d7d01c2c89..496234e250 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -199,12 +199,12 @@ extern "C"
 
 #ifndef __PTHREAD_KEY_T_DEFINED
 typedef int pthread_key_t;
-#define __PTHREAD_KEY_T_DEFINED 1
+#  define __PTHREAD_KEY_T_DEFINED 1
 #endif
 
 #ifndef __PTHREAD_ADDR_T_DEFINED
 typedef FAR void *pthread_addr_t;
-#define __PTHREAD_ADDR_T_DEFINED 1
+#  define __PTHREAD_ADDR_T_DEFINED 1
 #endif
 
 typedef CODE pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
@@ -238,12 +238,12 @@ struct pthread_attr_s
 
 #ifndef __PTHREAD_ATTR_T_DEFINED
 typedef struct pthread_attr_s pthread_attr_t;
-#define __PTHREAD_ATTR_T_DEFINED 1
+#  define __PTHREAD_ATTR_T_DEFINED 1
 #endif
 
 #ifndef __PTHREAD_T_DEFINED
 typedef pid_t pthread_t;
-#define __PTHREAD_T_DEFINED 1
+#  define __PTHREAD_T_DEFINED 1
 #endif
 
 struct pthread_condattr_s
@@ -253,7 +253,7 @@ struct pthread_condattr_s
 
 #ifndef __PTHREAD_CONDATTR_T_DEFINED
 typedef struct pthread_condattr_s pthread_condattr_t;
-#define __PTHREAD_CONDATTR_T_DEFINED 1
+#  define __PTHREAD_CONDATTR_T_DEFINED 1
 #endif
 
 struct pthread_cond_s
@@ -264,7 +264,7 @@ struct pthread_cond_s
 
 #ifndef __PTHREAD_COND_T_DEFINED
 typedef struct pthread_cond_s pthread_cond_t;
-#define __PTHREAD_COND_T_DEFINED 1
+#  define __PTHREAD_COND_T_DEFINED 1
 #endif
 
 #define PTHREAD_COND_INITIALIZER {SEM_INITIALIZER(0), CLOCK_REALTIME }
@@ -285,7 +285,7 @@ struct pthread_mutexattr_s
 
 #ifndef __PTHREAD_MUTEXATTR_T_DEFINED
 typedef struct pthread_mutexattr_s pthread_mutexattr_t;
-#define __PTHREAD_MUTEXATTR_T_DEFINED 1
+#  define __PTHREAD_MUTEXATTR_T_DEFINED 1
 #endif
 
 struct pthread_mutex_s
@@ -311,7 +311,7 @@ struct pthread_mutex_s
 
 #ifndef __PTHREAD_MUTEX_T_DEFINED
 typedef struct pthread_mutex_s pthread_mutex_t;
-#define __PTHREAD_MUTEX_T_DEFINED 1
+#  define __PTHREAD_MUTEX_T_DEFINED 1
 #endif
 
 #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
@@ -350,7 +350,7 @@ struct pthread_barrierattr_s
 
 #ifndef __PTHREAD_BARRIERATTR_T_DEFINED
 typedef struct pthread_barrierattr_s pthread_barrierattr_t;
-#define __PTHREAD_BARRIERATTR_T_DEFINED 1
+#  define __PTHREAD_BARRIERATTR_T_DEFINED 1
 #endif
 
 struct pthread_barrier_s
@@ -361,12 +361,22 @@ struct pthread_barrier_s
 
 #ifndef __PTHREAD_BARRIER_T_DEFINED
 typedef struct pthread_barrier_s pthread_barrier_t;
-#define __PTHREAD_BARRIER_T_DEFINED 1
+#  define __PTHREAD_BARRIER_T_DEFINED 1
 #endif
 
 #ifndef __PTHREAD_ONCE_T_DEFINED
 typedef bool pthread_once_t;
-#define __PTHREAD_ONCE_T_DEFINED 1
+#  define __PTHREAD_ONCE_T_DEFINED 1
+#endif
+
+struct pthread_rwlockattr_s
+{
+  int pshared;
+};
+
+#ifndef __PTHREAD_RWLOCKATTR_T_DEFINED
+typedef struct pthread_rwlockattr_s pthread_rwlockattr_t;
+#  define __PTHREAD_RWLOCKATTR_T_DEFINED 1
 #endif
 
 struct pthread_rwlock_s
@@ -378,9 +388,10 @@ struct pthread_rwlock_s
   bool write_in_progress;
 };
 
+#ifndef __PTHREAD_RWLOCK_T_DEFINED
 typedef struct pthread_rwlock_s pthread_rwlock_t;
-
-typedef int pthread_rwlockattr_t;
+#  define __PTHREAD_RWLOCK_T_DEFINED 1
+#endif
 
 #define PTHREAD_RWLOCK_INITIALIZER  {PTHREAD_MUTEX_INITIALIZER, \
                                      PTHREAD_COND_INITIALIZER, \
@@ -396,12 +407,12 @@ struct pthread_spinlock_s
                                  * SP_UNLOCKED. */
   pthread_t sp_holder;          /* ID of the thread that holds the spinlock */
 };
-#ifndef __PTHREAD_SPINLOCK_T_DEFINED
+#  ifndef __PTHREAD_SPINLOCK_T_DEFINED
 /* It is referenced via this standard type */
 
 typedef FAR struct pthread_spinlock_s pthread_spinlock_t;
-#define __PTHREAD_SPINLOCK_T_DEFINED 1
-#endif
+#    define __PTHREAD_SPINLOCK_T_DEFINED 1
+#  endif
 #endif /* CONFIG_PTHREAD_SPINLOCKS */
 
 #ifdef CONFIG_PTHREAD_CLEANUP
@@ -651,6 +662,15 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier);
 int pthread_once(FAR pthread_once_t *once_control,
                  CODE void (*init_routine)(void));
 
+/* Pthread rwlock attributes */
+
+int pthread_rwlockattr_init(FAR pthread_rwlockattr_t *attr);
+int pthread_rwlockattr_destroy(FAR pthread_rwlockattr_t *attr);
+int pthread_rwlockattr_getpshared(FAR const pthread_rwlockattr_t *attr,
+                                  FAR int *pshared);
+int pthread_rwlockattr_setpshared(FAR pthread_rwlockattr_t *attr,
+                                  int pshared);
+
 /* Pthread rwlock */
 
 int pthread_rwlock_destroy(FAR pthread_rwlock_t *rw_lock);
@@ -772,12 +792,24 @@ typedef struct pthread_barrier_s pthread_barrier_t;
 #  define __PTHREAD_BARRIER_T_DEFINED 1
 #endif
 
+#ifndef __PTHREAD_RWLOCKATTR_T_DEFINED
+struct pthread_rwlockattr_s;
+typedef struct pthread_rwlockattr_s pthread_rwlockattr_t;
+#  define __PTHREAD_RWLOCKATTR_T_DEFINED 1
+#endif
+
+#ifndef __PTHREAD_RWLOCK_T_DEFINED
+struct pthread_rwlock_s;
+typedef struct pthread_rwlock_s pthread_rwlock_t;
+#  define __PTHREAD_RWLOCK_T_DEFINED 1
+#endif
+
 #ifdef CONFIG_PTHREAD_SPINLOCKS
-#ifndef __PTHREAD_SPINLOCK_T_DEFINED
+#  ifndef __PTHREAD_SPINLOCK_T_DEFINED
 struct pthread_spinlock_s;
 typedef FAR struct pthread_spinlock_s pthread_spinlock_t;
-#define __PTHREAD_SPINLOCK_T_DEFINED 1
-#endif
+#    define __PTHREAD_SPINLOCK_T_DEFINED 1
+#  endif
 #endif /* CONFIG_PTHREAD_SPINLOCKS */
 
 #ifndef __PTHREAD_ONCE_T_DEFINED
diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs
index 3ae2f03c66..0e2e152ea0 100644
--- a/libs/libc/pthread/Make.defs
+++ b/libs/libc/pthread/Make.defs
@@ -50,6 +50,8 @@ CSRCS += pthread_mutexattr_settype.c pthread_mutexattr_gettype.c
 CSRCS += pthread_mutexattr_setrobust.c pthread_mutexattr_getrobust.c
 CSRCS += pthread_mutex_lock.c
 CSRCS += pthread_once.c pthread_yield.c pthread_atfork.c
+CSRCS += pthread_rwlockattr_init.c pthread_rwlockattr_destroy.c
+CSRCS += pthread_rwlockattr_getpshared.c pthread_rwlockattr_setpshared.c
 CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c
 CSRCS += pthread_setcancelstate.c pthread_setcanceltype.c
 CSRCS += pthread_testcancel.c
diff --git a/libs/libc/pthread/pthread_rwlockattr_destroy.c b/libs/libc/pthread/pthread_rwlockattr_destroy.c
new file mode 100644
index 0000000000..6e3889c4c8
--- /dev/null
+++ b/libs/libc/pthread/pthread_rwlockattr_destroy.c
@@ -0,0 +1,64 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_rwlockattr_destroy.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_rwlockattr_destroy
+ *
+ * Description:
+ *   The pthread_rwlockattr_destroy() function will destroy a rwlock attributes
+ *   object.  A destroyed attr attributes object can be reinitialized using
+ *   pthread_rwlockattr_init(); the results of otherwise referencing the object
+ *   after it has been destroyed are undefined.
+ *
+ * Input Parameters:
+ *   attr - rwlock attributes to be destroyed.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if attr is invalid.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_rwlockattr_destroy(FAR pthread_rwlockattr_t *attr)
+{
+  int ret = OK;
+
+  if (!attr)
+    {
+      ret = EINVAL;
+    }
+
+  return ret;
+}
diff --git a/libs/libc/pthread/pthread_rwlockattr_getpshared.c b/libs/libc/pthread/pthread_rwlockattr_getpshared.c
new file mode 100644
index 0000000000..f68f1a4367
--- /dev/null
+++ b/libs/libc/pthread/pthread_rwlockattr_getpshared.c
@@ -0,0 +1,68 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_rwlockattr_getpshared.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_rwlockattr_getpshared
+ *
+ * Description:
+ *   The pthread_rwlockattr_getpshared() function will obtain the value of the
+ *   process-shared attribute from the attributes object referenced by attr.
+ *
+ * Input Parameters:
+ *   attr - rwlock attributes to be queried.
+ *   pshared - the location to stored the current value of the pshared attribute.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if either attr or pshared is invalid.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_rwlockattr_getpshared(FAR const pthread_rwlockattr_t *attr,
+                                  FAR int *pshared)
+{
+  int ret = OK;
+
+  if (!attr || !pshared)
+    {
+      ret = EINVAL;
+    }
+  else
+    {
+      *pshared = attr->pshared;
+    }
+
+  return ret;
+}
diff --git a/libs/libc/pthread/pthread_rwlockattr_init.c b/libs/libc/pthread/pthread_rwlockattr_init.c
new file mode 100644
index 0000000000..8d75b2dece
--- /dev/null
+++ b/libs/libc/pthread/pthread_rwlockattr_init.c
@@ -0,0 +1,67 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_rwlockattr_init.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_rwlockattr_init
+ *
+ * Description:
+ *   The pthread_rwlockattr_init() function will initialize a rwlock attribute
+ *   object attr with the default value for all of the attributes defined by the
+ *   implementation.
+ *
+ * Input Parameters:
+ *   attr - rwlock attributes to be initialized.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if attr is invalid.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_rwlockattr_init(FAR pthread_rwlockattr_t *attr)
+{
+  int ret = OK;
+
+  if (!attr)
+    {
+      ret = EINVAL;
+    }
+  else
+    {
+      attr->pshared = PTHREAD_PROCESS_PRIVATE;
+    }
+
+  return ret;
+}
diff --git a/libs/libc/pthread/pthread_rwlockattr_setpshared.c b/libs/libc/pthread/pthread_rwlockattr_setpshared.c
new file mode 100644
index 0000000000..a3c35d3c34
--- /dev/null
+++ b/libs/libc/pthread/pthread_rwlockattr_setpshared.c
@@ -0,0 +1,99 @@
+/********************************************************************************
+ * libs/libc/pthread/pthread_rwlockattr_setpshared.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 <nuttx/config.h>
+
+#include <pthread.h>
+#include <errno.h>
+#include <debug.h>
+
+/********************************************************************************
+ * Pre-processor Definitions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Type Declarations
+ ********************************************************************************/
+
+/********************************************************************************
+ * Public Data
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Data
+ ********************************************************************************/
+
+/********************************************************************************
+ * Private Function Prototypes
+ ********************************************************************************/
+
+/********************************************************************************
+ * Public Functions
+ ********************************************************************************/
+
+/********************************************************************************
+ * Name: pthread_rwlockattr_setpshared
+ *
+ * Description:
+ *   The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit
+ *   a rwlock to be operated upon by any thread that has access to the
+ *   memory where the rwlock is allocated. If the process-shared attribute
+ *   is PTHREAD_PROCESS_PRIVATE, the rwlock can only be operated upon by
+ *   threads created within the same process as the thread that initialized
+ *   the rwlock.
+ *   If threads of different processes attempt to operate on such a rwlock,
+ *   the behavior is undefined. The default value of the attribute is
+ *   PTHREAD_PROCESS_PRIVATE.
+ *
+ *   Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are
+ *   defined in pthread.h.
+ *
+ * Input Parameters:
+ *   attr - rwlock attributes to be modified.
+ *   pshared - the new value of the pshared attribute.
+ *
+ * Returned Value:
+ *   0 (OK) on success or EINVAL if either attr is invalid or pshared is not
+ *   one of PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE.
+ *
+ * Assumptions:
+ *
+ ********************************************************************************/
+
+int pthread_rwlockattr_setpshared(FAR pthread_rwlockattr_t *attr, int pshared)
+{
+  int ret = OK;
+
+  if (!attr || (pshared != PTHREAD_PROCESS_SHARED &&
+       pshared != PTHREAD_PROCESS_PRIVATE))
+    {
+      ret = EINVAL;
+    }
+  else
+    {
+      attr->pshared = pshared;
+    }
+
+  return ret;
+}


[nuttx] 01/04: Documentation: Remove the supported function from the unsupported list

Posted by gu...@apache.org.
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 679544cd32f77f96fc6c3ec78627aa793a56f5e5
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 20 22:16:03 2023 +0800

    Documentation: Remove the supported function from the unsupported list
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 Documentation/reference/user/08_pthread.rst | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/Documentation/reference/user/08_pthread.rst b/Documentation/reference/user/08_pthread.rst
index df01d5503b..68f94bca63 100644
--- a/Documentation/reference/user/08_pthread.rst
+++ b/Documentation/reference/user/08_pthread.rst
@@ -109,29 +109,16 @@ The main task thread does not have thread-specific data.
 
 No support for the following pthread interfaces is provided by NuttX:
 
-  -  ``pthread_atfork``. register fork handlers.
-  -  ``pthread_attr_getdetachstate``. get and set the detachstate
-     attribute.
   -  ``pthread_attr_getguardsize``. get and set the thread guardsize
      attribute.
-  -  ``pthread_attr_getinheritsched``. get and set the inheritsched
-     attribute.
   -  ``pthread_attr_getscope``. get and set the contentionscope attribute.
-  -  ``pthread_attr_getstack``. get and set stack attributes.
   -  ``pthread_attr_getstackaddr``. get and set the stackaddr attribute.
-  -  ``pthread_attr_setdetachstate``. get and set the detachstate
-     attribute.
   -  ``pthread_attr_setguardsize``. get and set the thread guardsize
      attribute.
   -  ``pthread_attr_setscope``. get and set the contentionscope attribute.
-  -  ``pthread_attr_setstack``. get and set stack attributes.
   -  ``pthread_attr_setstackaddr``. get and set the stackaddr attribute.
-  -  ``pthread_condattr_getclock``. set the clock selection condition
-     variable attribute.
   -  ``pthread_condattr_getpshared``. get the process-shared condition
      variable attribute.
-  -  ``pthread_condattr_setclock``. set the clock selection condition
-     variable attribute.
   -  ``pthread_condattr_setpshared``. set the process-shared condition
      variable attribute.
   -  ``pthread_getconcurrency``. get and set the level of concurrency.
@@ -140,7 +127,6 @@ No support for the following pthread interfaces is provided by NuttX:
      a mutex.
   -  ``pthread_mutex_setprioceiling``. get and set the priority ceiling of
      a mutex.
-  -  ``pthread_mutex_timedlock``. lock a mutex.
   -  ``pthread_mutexattr_getprioceiling``. get and set the prioceiling
      attribute of the mutex attributes object.
   -  ``pthread_mutexattr_setprioceiling``. get and set the prioceiling
@@ -154,11 +140,6 @@ No support for the following pthread interfaces is provided by NuttX:
   -  ``pthread_rwlockattr_setpshared``. get and set the process-shared
      attribute of the read-write lock attributes object.
   -  ``pthread_setconcurrency``. get and set the level of concurrency.
-  -  ``pthread_spin_destroy``. destroy or initialize a spin lock object.
-  -  ``pthread_spin_init``. destroy or initialize a spin lock object.
-  -  ``pthread_spin_lock``. lock a spin lock object.
-  -  ``pthread_spin_trylock``. lock a spin lock object.
-  -  ``pthread_spin_unlock``. unlock a spin lock object.
 
 .. c:function:: int pthread_attr_init(pthread_attr_t *attr);