Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions include/nuttx/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,6 @@
# define __HAVE_KERNEL_GLOBALS 1
#endif

/* The following are the bit fields of the clockid_t
* bit 0~2: the clock type
* CLOCK_REALTIME - 0
* CLOCK_MONOTONIC - 1
* CLOCK_PROCESS_CPUTIME_ID - 2
* CLOCK_THREAD_CPUTIME_ID - 3
* CLOCK_BOOTTIME - 4
* CLOCK_FD - 5
*
* if the clockid value exceeds CLOCK_MASK, it indicates a dynamic clockid.
* bit 3~32: the fd, pid or tid value
*
* The CLOCK_MASK are using to extract the clock_type from the clockid_t
*/

#define CLOCK_FD 5
#define CLOCK_MASK 7
#define CLOCK_SHIFT 3

/* Timing constants *********************************************************/

#define NSEC_PER_SEC 1000000000L /* Seconds */
Expand Down
1 change: 1 addition & 0 deletions include/nuttx/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
# define TCB_FLAG_SCHED_FIFO (0 << TCB_FLAG_POLICY_SHIFT) /* FIFO scheding policy */
# define TCB_FLAG_SCHED_RR (1 << TCB_FLAG_POLICY_SHIFT) /* Round robin scheding policy */
# define TCB_FLAG_SCHED_SPORADIC (2 << TCB_FLAG_POLICY_SHIFT) /* Sporadic scheding policy */
# define TCB_FLAG_SCHED_OTHER (3 << TCB_FLAG_POLICY_SHIFT) /* Other scheduling policy */
#define TCB_FLAG_CPU_LOCKED (1 << 5) /* Bit 5: Locked to this CPU */
#define TCB_FLAG_SIGNAL_ACTION (1 << 6) /* Bit 6: In a signal handler */
#define TCB_FLAG_SYSCALL (1 << 7) /* Bit 7: In a system call */
Expand Down
12 changes: 6 additions & 6 deletions include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@

/* Values for the process shared (pshared) attribute */

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED 1
#define PTHREAD_PROCESS_PRIVATE 1
#define PTHREAD_PROCESS_SHARED 2

/* Values for the mutext type attribute:
*
Expand Down Expand Up @@ -264,9 +264,9 @@ typedef struct pthread_cond_s pthread_cond_t;

struct pthread_mutexattr_s
{
uint8_t pshared : 1; /* PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED */
uint8_t pshared : 2; /* PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED */
#if defined(CONFIG_PRIORITY_INHERITANCE) || defined(CONFIG_PRIORITY_PROTECT)
uint8_t proto : 2; /* See PTHREAD_PRIO_* definitions */
uint8_t prio : 2; /* See PTHREAD_PRIO_* definitions */
#endif
#ifdef CONFIG_PRIORITY_PROTECT
uint8_t ceiling; /* Priority ceiling */
Expand Down Expand Up @@ -319,13 +319,13 @@ typedef struct pthread_mutex_s pthread_mutex_t;
#ifdef CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT
# define PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT SEM_PRIO_INHERIT
#else
# define PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT 0
# define PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT SEM_PRIO_NONE
#endif

#ifdef CONFIG_PTHREAD_MUTEX_DEFAULT_PRIO_PROTECT
# define PTHREAD_MUTEX_DEFAULT_PRIO_PROTECT SEM_PRIO_PROTECT
#else
# define PTHREAD_MUTEX_DEFAULT_PRIO_PROTECT 0
# define PTHREAD_MUTEX_DEFAULT_PRIO_PROTECT SEM_PRIO_NONE
#endif

#define PTHREAD_MUTEX_DEFAULT_PRIO_FLAGS (PTHREAD_MUTEX_DEFAULT_PRIO_INHERIT | \
Expand Down
10 changes: 5 additions & 5 deletions include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

/* POSIX-like scheduling policies */

#define SCHED_NORMAL 0 /* Alias to SCHED_OTHER */
#define SCHED_OTHER 0 /* Map to SCHED_FIFO or SCHED_RR */
#define SCHED_FIFO 1 /* FIFO priority scheduling policy */
#define SCHED_RR 2 /* Round robin scheduling policy */
#define SCHED_SPORADIC 3 /* Sporadic scheduling policy */
#define SCHED_FIFO 0 /* FIFO priority scheduling policy */
#define SCHED_RR 1 /* Round robin scheduling policy */
#define SCHED_SPORADIC 2 /* Sporadic scheduling policy */
#define SCHED_OTHER 3 /* Map to SCHED_FIFO or SCHED_RR */
#define SCHED_NORMAL 3 /* Alias to SCHED_OTHER */
#define SCHED_BATCH 4 /* Batch scheduling policy */
#define SCHED_IDLE 5 /* Idle scheduling policy */

Expand Down
6 changes: 3 additions & 3 deletions include/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ typedef struct sem_s sem_t;
/* semcount, flags, waitlist, hhead */

# define SEM_INITIALIZER(c) \
{{(c)}, 0, SEM_WAITLIST_INITIALIZER, NULL}
{{(c)}, SEM_PRIO_NONE, SEM_WAITLIST_INITIALIZER, NULL}
# else
/* semcount, flags, waitlist, holder[2] */

# define SEM_INITIALIZER(c) \
{{(c)}, 0, SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER}
{{(c)}, SEM_PRIO_NONE, SEM_WAITLIST_INITIALIZER, SEMHOLDER_INITIALIZER}
# endif
#else
/* semcount, flags, waitlist */

# define SEM_INITIALIZER(c) \
{{(c)}, 0, SEM_WAITLIST_INITIALIZER}
{{(c)}, SEM_PRIO_NONE, SEM_WAITLIST_INITIALIZER}
#endif

#define SEM_WAITLIST(sem) (&((sem)->waitlist))
Expand Down
32 changes: 27 additions & 5 deletions include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,50 @@
* forward and backward as the system time-of-day clock is changed.
*/

#define CLOCK_REALTIME 0
#define CLOCK_REALTIME 1

/* Clock that cannot be set and represents monotonic time since some
* unspecified starting point. It is not affected by changes in the
* system time-of-day clock.
*/

#define CLOCK_MONOTONIC 1
#define CLOCK_MONOTONIC 2

/* Clock that measures CPU time consumed by this process (i.e., CPU
* time consumed by all threads in the process).
*/

#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_PROCESS_CPUTIME_ID 3

/* Clock that measures CPU time consumed by this thread */

#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_THREAD_CPUTIME_ID 4

/* Monotonic system-wide clock that includes time spent in suspension. */

#define CLOCK_BOOTTIME 4
#define CLOCK_BOOTTIME 5

/* Clock sources that are managed via file descriptors(e.g. PTP driver) */

#define CLOCK_FD 6

/* The following are the bit fields of the clockid_t
* bit 0~2: the clock type
* CLOCK_REALTIME - 1
* CLOCK_MONOTONIC - 2
* CLOCK_PROCESS_CPUTIME_ID - 3
* CLOCK_THREAD_CPUTIME_ID - 4
* CLOCK_BOOTTIME - 5
* CLOCK_FD - 6
*
* if the clockid value exceeds CLOCK_MASK, it indicates a dynamic clockid.
* bit 3~31: the fd, pid or tid value
*
* CLOCK_MASK extracts the clock type from the clockid_t
*/

#define CLOCK_MASK 7
#define CLOCK_SHIFT 3

/* This is a flag that may be passed to the timer_settime() and
* clock_nanosleep() functions.
Expand Down
20 changes: 20 additions & 0 deletions include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@
# define _POSIX_SPIN_LOCKS -1
#endif

/* For the PSE52 certification, define the following macros.
* _POSIX_THREAD_ATTR_STACKADDR and _POSIX_THREAD_ATTR_STACKSIZE are
* defined above. The priority protocols are only supported when they are
* built in.
*/

#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_PTHREAD)
# define _POSIX_THREAD_PRIO_INHERIT 200112L
#else
# define _POSIX_THREAD_PRIO_INHERIT -1
#endif

#if defined(CONFIG_PRIORITY_PROTECT) && !defined(CONFIG_DISABLE_PTHREAD)
# define _POSIX_THREAD_PRIO_PROTECT 200112L
#else
# define _POSIX_THREAD_PRIO_PROTECT -1
#endif

#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L

#ifdef CONFIG_FS_AIO
# define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION
#else
Expand Down
67 changes: 67 additions & 0 deletions libs/libc/pthread/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,73 @@

#define COND_WAIT_COUNT(cond) ((FAR atomic_t *)&(cond)->wait_count)

/* Validate if a pthread_attr_t object is valid.
*
* This macro checks:
* - The attribute pointer is not NULL
* - The priority field is within valid scheduling priority range
*/

#define PTHREAD_ATTR_IS_VALID(attr) \
((attr) != NULL && \
(attr)->priority >= SCHED_PRIORITY_MIN && \
(attr)->priority <= SCHED_PRIORITY_MAX)

/* Validate if a pthread_condattr_t object is valid.
*
* This macro checks:
* - The attribute pointer is not NULL
* - The pshared field contains a valid value
*/

#define PTHREAD_CONDATTR_IS_VALID(attr) \
((attr) != NULL && \
((attr)->pshared == PTHREAD_PROCESS_PRIVATE || \
(attr)->pshared == PTHREAD_PROCESS_SHARED))

/* Validate if a pthread_cond_t object is valid.
*
* This macro checks:
* - The condition pointer is not NULL
* - The clockid field contains a valid value
*/

#define PTHREAD_COND_IS_VALID(cond) \
((cond) != NULL && \
((cond)->clockid == CLOCK_REALTIME || \
(cond)->clockid == CLOCK_MONOTONIC))

/* Validate if a pthread_mutexattr_t object is valid.
*
* This macro checks:
* - The attribute pointer is not NULL
* - The pshared field contains a valid value
*/

#define PTHREAD_MUTEXATTR_IS_VALID(attr) \
((attr) != NULL && \
((attr)->pshared == PTHREAD_PROCESS_PRIVATE || \
(attr)->pshared == PTHREAD_PROCESS_SHARED))

/* Validate if a pthread_mutex_t object is valid.
*
* This macro checks:
* - The mutex pointer is not NULL
* - The underlying semaphore is a mutex,
* when initialized, the flag SEM_TYPE_MUTEX is set.
* when destroyed, the flag SEM_TYPE_MUTEX is cleared.
*/

#ifdef CONFIG_PTHREAD_MUTEX_TYPES
# define PTHREAD_MUTEX_IS_VALID(mutex) \
((mutex) != NULL && \
((mutex)->mutex.mutex.sem.flags & SEM_TYPE_MUTEX))
#else
# define PTHREAD_MUTEX_IS_VALID(mutex) \
((mutex) != NULL && \
((mutex)->mutex.sem.flags & SEM_TYPE_MUTEX))
#endif

/****************************************************************************
* Public Function Prototypes
****************************************************************************/
Expand Down
9 changes: 8 additions & 1 deletion libs/libc/pthread/pthread_attr_destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <nuttx/debug.h>
#include <errno.h>

#include "pthread.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -57,7 +59,12 @@ int pthread_attr_destroy(FAR pthread_attr_t *attr)

linfo("attr=%p\n", attr);

if (!attr)
/* When the attribute object specified by attr is invalid,
* then a call to pthread_attr_destroy(attr)
* returns EINVAL.
*/

if (!PTHREAD_ATTR_IS_VALID(attr))
{
ret = EINVAL;
}
Expand Down
9 changes: 8 additions & 1 deletion libs/libc/pthread/pthread_attr_getdetachstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <pthread.h>
#include <errno.h>

#include "pthread.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -50,7 +52,12 @@
int pthread_attr_getdetachstate(FAR const pthread_attr_t *attr,
FAR int *detachstate)
{
if (!attr || !detachstate)
/* When the attribute object specified by attr is invalid,
* then a call to pthread_attr_getdetachstate(attr, detachstate)
* returns EINVAL.
*/

if (!PTHREAD_ATTR_IS_VALID(attr) || !detachstate)
{
return EINVAL;
}
Expand Down
9 changes: 8 additions & 1 deletion libs/libc/pthread/pthread_attr_getguardsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <pthread.h>

#include "pthread.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -53,7 +55,12 @@ int pthread_attr_getguardsize(FAR const pthread_attr_t *attr,
{
int ret;

if (!guardsize)
/* When the attribute object specified by attr is invalid,
* then a call to pthread_attr_getguardsize(attr, guardsize)
* returns EINVAL.
*/

if (!PTHREAD_ATTR_IS_VALID(attr) || !guardsize)
{
ret = EINVAL;
}
Expand Down
9 changes: 8 additions & 1 deletion libs/libc/pthread/pthread_attr_getinheritsched.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <nuttx/debug.h>
#include <errno.h>

#include "pthread.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -61,7 +63,12 @@ int pthread_attr_getinheritsched(FAR const pthread_attr_t *attr,

linfo("attr=%p inheritsched=%p\n", attr, inheritsched);

if (!attr || !inheritsched)
/* When the attribute object specified by attr is invalid,
* then a call to pthread_attr_getinheritsched(attr, inheritsched)
* returns EINVAL.
*/

if (!PTHREAD_ATTR_IS_VALID(attr) || !inheritsched)
{
ret = EINVAL;
}
Expand Down
9 changes: 8 additions & 1 deletion libs/libc/pthread/pthread_attr_getschedparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <nuttx/debug.h>
#include <errno.h>

#include "pthread.h"

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down Expand Up @@ -59,7 +61,12 @@ int pthread_attr_getschedparam(FAR const pthread_attr_t *attr,

linfo("attr=%p param=%p\n", attr, param);

if (!attr || !param)
/* When the attribute object specified by attr is invalid,
* then a call to pthread_attr_getschedparam(attr, param)
* returns EINVAL.
*/

if (!PTHREAD_ATTR_IS_VALID(attr) || !param)
{
ret = EINVAL;
}
Expand Down
Loading
Loading