diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 3a7a16b27d..0179e81588 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -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 * * 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) diff --git a/libs/libc/pthread/Make.defs b/libs/libc/pthread/Make.defs index e8a521b8a3..f9c2de2fbd 100644 --- a/libs/libc/pthread/Make.defs +++ b/libs/libc/pthread/Make.defs @@ -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 # # 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 diff --git a/libs/libc/pthread/pthread_mutex_lock.c b/libs/libc/pthread/pthread_mutex_lock.c new file mode 100644 index 0000000000..0717586920 --- /dev/null +++ b/libs/libc/pthread/pthread_mutex_lock.c @@ -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 + * + * 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 + +#include + +/**************************************************************************** + * 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); +} diff --git a/libs/libc/stdio/lib_setvbuf.c b/libs/libc/stdio/lib_setvbuf.c index 90481520bf..e585df34d9 100644 --- a/libs/libc/stdio/lib_setvbuf.c +++ b/libs/libc/stdio/lib_setvbuf.c @@ -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 */ diff --git a/sched/pthread/Make.defs b/sched/pthread/Make.defs index 79a5b3a15d..317d313c58 100644 --- a/sched/pthread/Make.defs +++ b/sched/pthread/Make.defs @@ -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 diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutextimedlock.c similarity index 76% rename from sched/pthread/pthread_mutexlock.c rename to sched/pthread/pthread_mutextimedlock.c index a4a8c44a26..f972b6a7ff 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutextimedlock.c @@ -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 @@ -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 * diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 24dbcdc737..fcbb9fbdae 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -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*" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 4ccfbb451b..7a90ce2e5a 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -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 * * 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 diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 482faf5c1e..56ac32142f 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -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 * * 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);