1
0
Fork 0
forked from nuttx/nuttx-update

libs/libc/pthread, syscall/, and include/sys/syscall.h: Support for pthread_mutex_timedlock() was added recently, however no new system call was added for the API make is usable only in the FLAT build. With a pthread_mutex_timedlock() system call, there is no reason for a pthread_mutex_lock() system call since it is now nothing more than an wrapper around pthread_mutex_timedlock(), passing NULL for the time value. The pthread_mutex_lock() syscall was removed and the pthread_mutex_lock() implemented was moved from /sched/pthread to where it now belows in libs/libc/pthread.

This commit is contained in:
Gregory Nutt 2019-02-25 18:19:13 -06:00
parent 68f8161a45
commit 0951151c33
9 changed files with 124 additions and 72 deletions

View file

@ -2,7 +2,7 @@
* include/sys/syscall.h
* This file contains the system call numbers.
*
* Copyright (C) 2011-2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -432,7 +432,7 @@
# define SYS_pthread_key_delete (__SYS_pthread + 11)
# define SYS_pthread_mutex_destroy (__SYS_pthread + 12)
# define SYS_pthread_mutex_init (__SYS_pthread + 13)
# define SYS_pthread_mutex_lock (__SYS_pthread + 14)
# define SYS_pthread_mutex_timedlock (__SYS_pthread + 14)
# define SYS_pthread_mutex_trylock (__SYS_pthread + 15)
# define SYS_pthread_mutex_unlock (__SYS_pthread + 16)

View file

@ -1,7 +1,7 @@
############################################################################
# libs/libc/pthread/Make.defs
#
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
# Copyright (C) 2011-2012, 2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -53,6 +53,7 @@ CSRCS += pthread_mutexattr_getpshared.c pthread_mutexattr_setpshared.c
CSRCS += pthread_mutexattr_setprotocol.c pthread_mutexattr_getprotocol.c
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_setcancelstate.c pthread_setcanceltype.c
CSRCS += pthread_testcancel.c
CSRCS += pthread_rwlock.c pthread_rwlock_rdlock.c pthread_rwlock_wrlock.c

View file

@ -0,0 +1,105 @@
/****************************************************************************
* libs/libc/pthread/pthread_mutex_lock.c
*
* Copyright (C) 2007-2009, 2017, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <pthread.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_mutex_lock
*
* Description:
* The mutex object referenced by mutex is locked by calling
* pthread_mutex_lock(). If the mutex is already locked, the calling thread
* blocks until the mutex becomes available. This operation returns with the
* mutex object referenced by mutex in the locked state with the calling
* thread as its owner.
*
* If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection is not
* provided. Attempting to relock the mutex causes deadlock. If a thread
* attempts to unlock a mutex that it has not locked or a mutex which is
* unlocked, undefined behavior results.
*
* If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking is
* provided. If a thread attempts to relock a mutex that it has already
* locked, an error will be returned. If a thread attempts to unlock a
* mutex that it has not locked or a mutex which is unlocked, an error will
* be returned.
*
* If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains
* the concept of a lock count. When a thread successfully acquires a mutex
* for the first time, the lock count is set to one. Every time a thread
* relocks this mutex, the lock count is incremented by one. Each time the
* thread unlocks the mutex, the lock count is decremented by one. When the
* lock count reaches zero, the mutex becomes available for other threads to
* acquire. If a thread attempts to unlock a mutex that it has not locked or
* a mutex which is unlocked, an error will be returned.
*
* If a signal is delivered to a thread waiting for a mutex, upon return
* from the signal handler the thread resumes waiting for the mutex as if
* it was not interrupted.
*
* Input Parameters:
* mutex - A reference to the mutex to be locked.
*
* Returned Value:
* 0 on success or an errno value on failure. Note that the errno EINTR
* is never returned by pthread_mutex_lock().
*
* Assumptions:
*
* POSIX Compatibility:
* - This implementation does not return EAGAIN when the mutex could not be
* acquired because the maximum number of recursive locks for mutex has
* been exceeded.
*
****************************************************************************/
int pthread_mutex_lock(FAR pthread_mutex_t *mutex)
{
/* pthread_mutex_lock() is equivalent to pthread_mutex_timedlock() when
* the absolute time delay is a NULL value.
*/
return pthread_mutex_timedlock(mutex, NULL);
}

View file

@ -69,11 +69,11 @@
* _IOLBF - Will cause input/output to be line buffered.
* _IONBF - Will cause input/output to be unbuffered.
*
* If buf is not a null pointer, the array it points to may be used instead
* of a buffer allocated by setvbuf() and the argument size specifies the size
* of the array; otherwise, size may determine the size of a buffer allocated
* by the setvbuf() function. The contents of the array at any time are
* unspecified.
* If buf is not a null pointer, the array it points to may be used instead
* of a buffer allocated by setvbuf() and the argument size specifies the size
* of the array; otherwise, size may determine the size of a buffer allocated
* by the setvbuf() function. The contents of the array at any time are
* unspecified.
*
* Input Parameters:
* stream - the stream to flush
@ -141,8 +141,8 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
lib_take_semaphore(stream);
/* setvbuf() may only be called AFTER the file has been opened and BEFORE
* any operations have been performed on the string.
/* setvbuf() may only be called AFTER the stream has been opened and
* BEFORE any operations have been performed on the stream.
*/
/* Return EBADF if the file is not open */

View file

@ -41,7 +41,7 @@ ifneq ($(CONFIG_DISABLE_PTHREAD),y)
CSRCS += pthread_create.c pthread_exit.c pthread_join.c pthread_detach.c
CSRCS += pthread_getschedparam.c pthread_setschedparam.c
CSRCS += pthread_mutexinit.c pthread_mutexdestroy.c
CSRCS += pthread_mutexlock.c pthread_mutextrylock.c pthread_mutexunlock.c
CSRCS += pthread_mutextimedlock.c pthread_mutextrylock.c pthread_mutexunlock.c
CSRCS += pthread_condwait.c pthread_condsignal.c pthread_condbroadcast.c
CSRCS += pthread_cancel.c
CSRCS += pthread_initialize.c pthread_completejoin.c pthread_findjoininfo.c

View file

@ -1,5 +1,5 @@
/****************************************************************************
* sched/pthread/pthread_mutexlock.c
* sched/pthread/pthread_mutextimedlock.c
*
* Copyright (C) 2007-2009, 2017, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@ -54,61 +54,6 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: pthread_mutex_lock
*
* Description:
* The mutex object referenced by mutex is locked by calling
* pthread_mutex_lock(). If the mutex is already locked, the calling thread
* blocks until the mutex becomes available. This operation returns with the
* mutex object referenced by mutex in the locked state with the calling
* thread as its owner.
*
* If the mutex type is PTHREAD_MUTEX_NORMAL, deadlock detection is not
* provided. Attempting to relock the mutex causes deadlock. If a thread
* attempts to unlock a mutex that it has not locked or a mutex which is
* unlocked, undefined behavior results.
*
* If the mutex type is PTHREAD_MUTEX_ERRORCHECK, then error checking is
* provided. If a thread attempts to relock a mutex that it has already
* locked, an error will be returned. If a thread attempts to unlock a
* mutex that it has not locked or a mutex which is unlocked, an error will
* be returned.
*
* If the mutex type is PTHREAD_MUTEX_RECURSIVE, then the mutex maintains
* the concept of a lock count. When a thread successfully acquires a mutex
* for the first time, the lock count is set to one. Every time a thread
* relocks this mutex, the lock count is incremented by one. Each time the
* thread unlocks the mutex, the lock count is decremented by one. When the
* lock count reaches zero, the mutex becomes available for other threads to
* acquire. If a thread attempts to unlock a mutex that it has not locked or
* a mutex which is unlocked, an error will be returned.
*
* If a signal is delivered to a thread waiting for a mutex, upon return
* from the signal handler the thread resumes waiting for the mutex as if
* it was not interrupted.
*
* Input Parameters:
* mutex - A reference to the mutex to be locked.
*
* Returned Value:
* 0 on success or an errno value on failure. Note that the errno EINTR
* is never returned by pthread_mutex_lock().
*
* Assumptions:
*
* POSIX Compatibility:
* - This implementation does not return EAGAIN when the mutex could not be
* acquired because the maximum number of recursive locks for mutex has
* been exceeded.
*
****************************************************************************/
int pthread_mutex_lock(FAR pthread_mutex_t *mutex)
{
return pthread_mutex_timedlock(mutex, NULL);
}
/****************************************************************************
* Name: pthread_mutex_timedlock
*

View file

@ -93,7 +93,7 @@
"pthread_kill","pthread.h","!defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t","int"
"pthread_mutex_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*"
"pthread_mutex_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*","FAR const pthread_mutexattr_t*"
"pthread_mutex_lock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*"
"pthread_mutex_timedlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*","FAR const struct timespec*"
"pthread_mutex_trylock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*"
"pthread_mutex_unlock","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutex_t*"
"pthread_mutex_consistent","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)","int","FAR pthread_mutex_t*"

Can't render this file because it has a wrong number of fields in line 2.

View file

@ -1,7 +1,7 @@
/****************************************************************************
* syscall/syscall_lookup.h
*
* Copyright (C) 2011, 2013-2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2013-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -306,7 +306,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
SYSCALL_LOOKUP(pthread_key_delete, 1, STUB_pthread_key_delete)
SYSCALL_LOOKUP(pthread_mutex_destroy, 1, STUB_pthread_mutex_destroy)
SYSCALL_LOOKUP(pthread_mutex_init, 2, STUB_pthread_mutex_init)
SYSCALL_LOOKUP(pthread_mutex_lock, 1, STUB_pthread_mutex_lock)
SYSCALL_LOOKUP(pthread_mutex_timedlock, 2, STUB_pthread_mutex_timedlock)
SYSCALL_LOOKUP(pthread_mutex_trylock, 1, STUB_pthread_mutex_trylock)
SYSCALL_LOOKUP(pthread_mutex_unlock, 1, STUB_pthread_mutex_unlock)
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE

View file

@ -1,7 +1,7 @@
/****************************************************************************
* syscall/syscall_stublookup.c
*
* Copyright (C) 2011-2013, 2015-2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013, 2015-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -311,7 +311,8 @@ uintptr_t STUB_pthread_key_delete(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_destroy(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_init(int nbr, uintptr_t parm1,
uintptr_t parm2);
uintptr_t STUB_pthread_mutex_lock(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_timedlock(int nbr, uintptr_t parm1,
uintptr_t parm2);
uintptr_t STUB_pthread_mutex_trylock(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_unlock(int nbr, uintptr_t parm1);
uintptr_t STUB_pthread_mutex_consistent(int nbr, uintptr_t parm1);