pthread: restore pthread mutex default protocol POSIX compatibility

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
Petro Karashchenko 2022-01-06 11:02:13 +01:00 committed by Xiang Xiao
parent 5a0ab205ca
commit 2447b7bd9a
24 changed files with 63 additions and 22 deletions

View file

@ -120,6 +120,7 @@ CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PSEUDOTERM=y CONFIG_PSEUDOTERM=y
CONFIG_PTABLE_PARTITION=y CONFIG_PTABLE_PARTITION=y
CONFIG_PTHREAD_CLEANUP=y CONFIG_PTHREAD_CLEANUP=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_STACK_MIN=1024 CONFIG_PTHREAD_STACK_MIN=1024
CONFIG_RAM_SIZE=1048576 CONFIG_RAM_SIZE=1048576

View file

@ -67,6 +67,7 @@ CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=2048 CONFIG_PTHREAD_STACK_DEFAULT=2048
CONFIG_RAM_SIZE=524288 CONFIG_RAM_SIZE=524288
CONFIG_RAM_START=0x34000000 CONFIG_RAM_START=0x34000000

View file

@ -62,6 +62,7 @@ CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_CHILDSTATUS=2 CONFIG_PREALLOC_CHILDSTATUS=2
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_RAM_SIZE=262144 CONFIG_RAM_SIZE=262144
CONFIG_RAM_START=0x1fff0000 CONFIG_RAM_START=0x1fff0000
CONFIG_RAW_BINARY=y CONFIG_RAW_BINARY=y

View file

@ -75,6 +75,7 @@ CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_CHILDSTATUS=2 CONFIG_PREALLOC_CHILDSTATUS=2
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PWM=y CONFIG_PWM=y
CONFIG_RAM_SIZE=262144 CONFIG_RAM_SIZE=262144
CONFIG_RAM_START=0x1fff0000 CONFIG_RAM_START=0x1fff0000

View file

@ -133,6 +133,7 @@ CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PSEUDOTERM=y CONFIG_PSEUDOTERM=y
CONFIG_PTABLE_PARTITION=y CONFIG_PTABLE_PARTITION=y
CONFIG_PTHREAD_CLEANUP=y CONFIG_PTHREAD_CLEANUP=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_STACK_MIN=1024 CONFIG_PTHREAD_STACK_MIN=1024
CONFIG_RAM_SIZE=65536 CONFIG_RAM_SIZE=65536

View file

@ -30,6 +30,7 @@ CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64 CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y CONFIG_NSH_READLINE=y
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_RAM_SIZE=98304 CONFIG_RAM_SIZE=98304
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y CONFIG_RAW_BINARY=y

View file

@ -66,6 +66,7 @@ CONFIG_NSH_NESTDEPTH=0
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768
CONFIG_PREALLOC_TIMERS=2 CONFIG_PREALLOC_TIMERS=2
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=464 CONFIG_PTHREAD_STACK_DEFAULT=464
CONFIG_RAM_SIZE=20480 CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000

View file

@ -84,6 +84,7 @@ CONFIG_NSH_LINELEN=40
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768
CONFIG_PREALLOC_TIMERS=2 CONFIG_PREALLOC_TIMERS=2
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=464 CONFIG_PTHREAD_STACK_DEFAULT=464
CONFIG_RAM_SIZE=20480 CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000

View file

@ -72,6 +72,7 @@ CONFIG_NSH_LINELEN=40
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768
CONFIG_PREALLOC_TIMERS=2 CONFIG_PREALLOC_TIMERS=2
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=464 CONFIG_PTHREAD_STACK_DEFAULT=464
CONFIG_RAM_SIZE=20480 CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000

View file

@ -49,6 +49,7 @@ CONFIG_NSH_NESTDEPTH=0
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768
CONFIG_PREALLOC_TIMERS=2 CONFIG_PREALLOC_TIMERS=2
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=464 CONFIG_PTHREAD_STACK_DEFAULT=464
CONFIG_RAM_SIZE=20480 CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000

View file

@ -44,6 +44,7 @@ CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=5
CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768 CONFIG_POSIX_SPAWN_PROXY_STACKSIZE=768
CONFIG_PREALLOC_TIMERS=2 CONFIG_PREALLOC_TIMERS=2
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_STACK_DEFAULT=464 CONFIG_PTHREAD_STACK_DEFAULT=464
CONFIG_RAM_SIZE=20480 CONFIG_RAM_SIZE=20480
CONFIG_RAM_START=0x20000000 CONFIG_RAM_START=0x20000000

View file

@ -39,6 +39,7 @@ CONFIG_NSH_READLINE=y
CONFIG_NUCLEO_CONSOLE_VIRTUAL=y CONFIG_NUCLEO_CONSOLE_VIRTUAL=y
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_RAM_SIZE=245760 CONFIG_RAM_SIZE=245760
CONFIG_RAM_START=0x20010000 CONFIG_RAM_START=0x20010000
CONFIG_RAW_BINARY=y CONFIG_RAW_BINARY=y

View file

@ -74,6 +74,7 @@ CONFIG_NUCLEO_CONSOLE_VIRTUAL=y
CONFIG_PIPES=y CONFIG_PIPES=y
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PWM=y CONFIG_PWM=y
CONFIG_PWM_MULTICHAN=y CONFIG_PWM_MULTICHAN=y
CONFIG_PWM_NCHANNELS=4 CONFIG_PWM_NCHANNELS=4

View file

@ -40,6 +40,7 @@ CONFIG_NSH_READLINE=y
CONFIG_NUCLEO_CONSOLE_VIRTUAL=y CONFIG_NUCLEO_CONSOLE_VIRTUAL=y
CONFIG_PREALLOC_TIMERS=4 CONFIG_PREALLOC_TIMERS=4
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_RAM_SIZE=245760 CONFIG_RAM_SIZE=245760
CONFIG_RAM_START=0x20010000 CONFIG_RAM_START=0x20010000
CONFIG_RAW_BINARY=y CONFIG_RAW_BINARY=y

View file

@ -40,6 +40,7 @@ CONFIG_NSH_DISABLE_IFCONFIG=y
CONFIG_NSH_DISABLE_IFUPDOWN=y CONFIG_NSH_DISABLE_IFUPDOWN=y
CONFIG_PREALLOC_CHILDSTATUS=16 CONFIG_PREALLOC_CHILDSTATUS=16
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_STACK_DEFAULT=4194304 CONFIG_PTHREAD_STACK_DEFAULT=4194304
CONFIG_PTHREAD_STACK_MIN=4194304 CONFIG_PTHREAD_STACK_MIN=4194304

View file

@ -32,6 +32,7 @@ CONFIG_INIT_STACKSIZE=4194304
CONFIG_LIBM=y CONFIG_LIBM=y
CONFIG_PREALLOC_CHILDSTATUS=16 CONFIG_PREALLOC_CHILDSTATUS=16
CONFIG_PRIORITY_INHERITANCE=y CONFIG_PRIORITY_INHERITANCE=y
CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT=y
CONFIG_PTHREAD_MUTEX_TYPES=y CONFIG_PTHREAD_MUTEX_TYPES=y
CONFIG_PTHREAD_STACK_DEFAULT=4194304 CONFIG_PTHREAD_STACK_DEFAULT=4194304
CONFIG_PTHREAD_STACK_MIN=4194304 CONFIG_PTHREAD_STACK_MIN=4194304

View file

@ -59,7 +59,7 @@ int pthread_mutexattr_getprotocol(FAR const pthread_mutexattr_t *attr,
#else #else
linfo("Returning %d\n", PTHREAD_PRIO_NONE); linfo("Returning %d\n", PTHREAD_PRIO_NONE);
*protocol = PTHREAD_PRIO_NONE; *protocol = PTHREAD_PRIO_NONE;
#endif #endif /* CONFIG_PRIORITY_INHERITANCE */
return 0; return 0;
} }

View file

@ -63,8 +63,12 @@ int pthread_mutexattr_init(FAR pthread_mutexattr_t *attr)
attr->pshared = 0; attr->pshared = 0;
#ifdef CONFIG_PRIORITY_INHERITANCE #ifdef CONFIG_PRIORITY_INHERITANCE
attr->proto = SEM_PRIO_INHERIT; # ifdef PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
#endif attr->proto = PTHREAD_PRIO_INHERIT;
# else
attr->proto = PTHREAD_PRIO_NONE;
# endif
#endif /* CONFIG_PRIORITY_INHERITANCE */
#ifdef CONFIG_PTHREAD_MUTEX_TYPES #ifdef CONFIG_PTHREAD_MUTEX_TYPES
attr->type = PTHREAD_MUTEX_DEFAULT; attr->type = PTHREAD_MUTEX_DEFAULT;

View file

@ -54,21 +54,21 @@ int pthread_mutexattr_setprotocol(FAR pthread_mutexattr_t *attr,
linfo("attr=0x%p protocol=%d\n", attr, protocol); linfo("attr=0x%p protocol=%d\n", attr, protocol);
DEBUGASSERT(attr != NULL); DEBUGASSERT(attr != NULL);
#ifdef CONFIG_PRIORITY_INHERITANCE
if (protocol >= PTHREAD_PRIO_NONE && protocol <= PTHREAD_PRIO_PROTECT) if (protocol >= PTHREAD_PRIO_NONE && protocol <= PTHREAD_PRIO_PROTECT)
{ {
attr->proto = protocol; switch (protocol)
return OK; {
case PTHREAD_PRIO_NONE:
#ifdef CONFIG_PRIORITY_INHERITANCE
case PTHREAD_PRIO_INHERIT:
attr->proto = protocol;
#endif /* CONFIG_PRIORITY_INHERITANCE */
return OK;
default:
return ENOTSUP;
}
} }
return EINVAL; return EINVAL;
#else
if (protocol == PTHREAD_PRIO_NONE)
{
return OK;
}
return EINVAL;
#endif
} }

View file

@ -46,8 +46,7 @@
* *
* Returned Value: * Returned Value:
* This function is exposed as a non-standard application interface. It * This function is exposed as a non-standard application interface. It
* returns zero (OK) if successful. Otherwise, -1 (ERROR) is returned and * returns zero (OK). Otherwise, an error code.
* the errno value is set appropriately.
* *
****************************************************************************/ ****************************************************************************/

View file

@ -67,8 +67,9 @@
* *
* Returned Value: * Returned Value:
* This function is exposed as a non-standard application interface. It * This function is exposed as a non-standard application interface. It
* returns zero (OK) if successful. Otherwise, -1 (ERROR) is returned and * returns zero (OK) if successful. Otherwise, -EINVAL is returned if the
* the errno value is set appropriately. * value specified by protocol is invalid or -ENOTSUP if the value
* specified by protocol is an unsupported value.
* *
****************************************************************************/ ****************************************************************************/
@ -83,8 +84,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
case SEM_PRIO_INHERIT: case SEM_PRIO_INHERIT:
case SEM_PRIO_PROTECT: case SEM_PRIO_PROTECT:
return -ENOSYS; return -ENOTSUP;
break;
default: default:
break; break;

View file

@ -658,6 +658,24 @@ config PTHREAD_MUTEX_DEFAULT_UNSAFE
endchoice # Default NORMAL mutex robustness endchoice # Default NORMAL mutex robustness
choice
prompt "Default pthread mutex protocol"
default PTHREAD_MUTEX_DEFAULT_PRIO_NONE
config PTHREAD_MUTEX_DEFAULT_PRIO_NONE
bool "PTHREAD_PRIO_NONE default"
---help---
By default, pthread mutexes utilize PTHREAD_PRIO_NONE protocol (standard).
config PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
bool "PTHREAD_PRIO_INHERIT default"
depends on PRIORITY_INHERITANCE
---help---
By default, pthread mutexes utilize PTHREAD_PRIO_INHERIT protocol
(POSIX non-standard but a reasonable choice for most real-time systems).
endchoice # Default pthread mutex protocol
config PTHREAD_CLEANUP config PTHREAD_CLEANUP
bool "pthread cleanup stack" bool "pthread cleanup stack"
default n default n

View file

@ -61,7 +61,11 @@ int pthread_mutex_init(FAR pthread_mutex_t *mutex,
uint8_t type = PTHREAD_MUTEX_DEFAULT; uint8_t type = PTHREAD_MUTEX_DEFAULT;
#endif #endif
#ifdef CONFIG_PRIORITY_INHERITANCE #ifdef CONFIG_PRIORITY_INHERITANCE
# ifdef PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
uint8_t proto = PTHREAD_PRIO_INHERIT; uint8_t proto = PTHREAD_PRIO_INHERIT;
# else
uint8_t proto = PTHREAD_PRIO_NONE;
# endif
#endif #endif
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
#ifdef CONFIG_PTHREAD_MUTEX_DEFAULT_UNSAFE #ifdef CONFIG_PTHREAD_MUTEX_DEFAULT_UNSAFE

View file

@ -100,7 +100,7 @@ int nxsem_set_protocol(FAR sem_t *sem, int protocol)
/* Not yet supported */ /* Not yet supported */
return -ENOSYS; return -ENOTSUP;
default: default:
break; break;