mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
libc/pthread: Implement pthread_rwlockattr API
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_rwlockattr_getpshared.html Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Gustavo Henrique Nihei
parent
679544cd32
commit
36b74bab02
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user