mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 06:18:40 +08:00
libc/pthread: Implement pthread_condattr_[set|get]pshared
https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_condattr_getpshared.html Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
c11cd7f103
commit
8bf693b362
5 changed files with 172 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
68
libs/libc/pthread/pthread_condattr_getpshared.c
Normal file
68
libs/libc/pthread/pthread_condattr_getpshared.c
Normal file
|
@ -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;
|
||||
}
|
99
libs/libc/pthread/pthread_condattr_setpshared.c
Normal file
99
libs/libc/pthread/pthread_condattr_setpshared.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue