diff --git a/include/nuttx/pthread.h b/include/nuttx/pthread.h index 257db022ec3..a7dd31adaee 100644 --- a/include/nuttx/pthread.h +++ b/include/nuttx/pthread.h @@ -37,11 +37,7 @@ /* Default pthread attribute initializer */ -#if CONFIG_RR_INTERVAL == 0 -# define PTHREAD_DEFAULT_POLICY SCHED_FIFO -#else -# define PTHREAD_DEFAULT_POLICY SCHED_RR -#endif +#define PTHREAD_DEFAULT_POLICY SCHED_NORMAL /* A lot of hassle to use the old-fashioned struct initializers. But this * gives us backward compatibility with some very old compilers. diff --git a/include/sched.h b/include/sched.h index 480a8728d08..b0a7cf8e140 100644 --- a/include/sched.h +++ b/include/sched.h @@ -41,10 +41,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_OTHER 4 /* Not supported */ /* Maximum number of SCHED_SPORADIC replenishments */ diff --git a/libs/libc/pthread/pthread_attr_setschedpolicy.c b/libs/libc/pthread/pthread_attr_setschedpolicy.c index 87d52ce892e..3e164d41ed2 100644 --- a/libs/libc/pthread/pthread_attr_setschedpolicy.c +++ b/libs/libc/pthread/pthread_attr_setschedpolicy.c @@ -57,8 +57,8 @@ int pthread_attr_setschedpolicy(FAR pthread_attr_t *attr, int policy) linfo("attr=%p policy=%d\n", attr, policy); - if (!attr || - (policy != SCHED_FIFO + if (!attr || (policy != SCHED_OTHER + && policy != SCHED_FIFO #if CONFIG_RR_INTERVAL > 0 && policy != SCHED_RR #endif diff --git a/libs/libc/sched/sched_getprioritymax.c b/libs/libc/sched/sched_getprioritymax.c index 57682ccc62d..e5fd5d13fd1 100644 --- a/libs/libc/sched/sched_getprioritymax.c +++ b/libs/libc/sched/sched_getprioritymax.c @@ -52,7 +52,7 @@ int sched_get_priority_max(int policy) { - if (policy < SCHED_FIFO || policy > SCHED_OTHER) + if (policy < SCHED_OTHER || policy > SCHED_SPORADIC) { set_errno(EINVAL); return ERROR; diff --git a/libs/libc/sched/sched_getprioritymin.c b/libs/libc/sched/sched_getprioritymin.c index 4df14d13880..8f2d362f0ec 100644 --- a/libs/libc/sched/sched_getprioritymin.c +++ b/libs/libc/sched/sched_getprioritymin.c @@ -52,6 +52,6 @@ int sched_get_priority_min(int policy) { - DEBUGASSERT(policy >= SCHED_FIFO && policy <= SCHED_OTHER); + DEBUGASSERT(policy >= SCHED_OTHER && policy <= SCHED_SPORADIC); return SCHED_PRIORITY_MIN; } diff --git a/libs/libc/spawn/lib_psa_dump.c b/libs/libc/spawn/lib_psa_dump.c index d5631763b71..16c4159f9c4 100644 --- a/libs/libc/spawn/lib_psa_dump.c +++ b/libs/libc/spawn/lib_psa_dump.c @@ -102,7 +102,11 @@ void posix_spawnattr_dump(posix_spawnattr_t *attr) _err(" priority: %d\n", attr->priority); _err(" policy: %d\n", attr->policy); - if (attr->policy == SCHED_FIFO) + if (attr->policy == SCHED_OTHER) + { + _err(" SCHED_OTHER\n"); + } + else if (attr->policy == SCHED_FIFO) { _err(" SCHED_FIFO\n"); } @@ -110,6 +114,10 @@ void posix_spawnattr_dump(posix_spawnattr_t *attr) { _err(" SCHED_RR\n"); } + else if (attr->policy == SCHED_SPORADIC) + { + _err(" SCHED_SPORADIC\n"); + } else { _err(" Unrecognized\n"); diff --git a/libs/libc/spawn/lib_psa_setschedpolicy.c b/libs/libc/spawn/lib_psa_setschedpolicy.c index bd3143c89c5..c0f5c395259 100644 --- a/libs/libc/spawn/lib_psa_setschedpolicy.c +++ b/libs/libc/spawn/lib_psa_setschedpolicy.c @@ -51,7 +51,7 @@ int posix_spawnattr_setschedpolicy(FAR posix_spawnattr_t *attr, int policy) { - DEBUGASSERT(attr && (policy == SCHED_FIFO || policy == SCHED_RR)); + DEBUGASSERT(attr && (policy >= SCHED_OTHER && policy <= SCHED_SPORADIC)); attr->policy = (uint8_t)policy; return OK; } diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c index 1568bd1863b..99acf0cf518 100644 --- a/sched/pthread/pthread_create.c +++ b/sched/pthread/pthread_create.c @@ -421,12 +421,12 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, switch (policy) { default: - DEBUGPANIC(); case SCHED_FIFO: ptcb->cmn.flags |= TCB_FLAG_SCHED_FIFO; break; #if CONFIG_RR_INTERVAL > 0 + case SCHED_OTHER: case SCHED_RR: ptcb->cmn.flags |= TCB_FLAG_SCHED_RR; ptcb->cmn.timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); @@ -438,12 +438,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread, ptcb->cmn.flags |= TCB_FLAG_SCHED_SPORADIC; break; #endif - -#if 0 /* Not supported */ - case SCHED_OTHER: - ptcb->cmn.flags |= TCB_FLAG_SCHED_OTHER; - break; -#endif } #ifdef CONFIG_CANCELLATION_POINTS diff --git a/sched/sched/sched_setscheduler.c b/sched/sched/sched_setscheduler.c index 2cae203a951..77f73c1c676 100644 --- a/sched/sched/sched_setscheduler.c +++ b/sched/sched/sched_setscheduler.c @@ -84,7 +84,8 @@ int nxsched_set_scheduler(pid_t pid, int policy, /* Check for supported scheduling policy */ - if (policy != SCHED_FIFO + if (policy != SCHED_OTHER + && policy != SCHED_FIFO #if CONFIG_RR_INTERVAL > 0 && policy != SCHED_RR #endif @@ -132,9 +133,6 @@ int nxsched_set_scheduler(pid_t pid, int policy, switch (policy) { default: - DEBUGPANIC(); - break; - case SCHED_FIFO: { #ifdef CONFIG_SCHED_SPORADIC @@ -148,14 +146,15 @@ int nxsched_set_scheduler(pid_t pid, int policy, /* Save the FIFO scheduling parameters */ - tcb->flags |= TCB_FLAG_SCHED_FIFO; + tcb->flags |= TCB_FLAG_SCHED_FIFO; #if CONFIG_RR_INTERVAL > 0 || defined(CONFIG_SCHED_SPORADIC) - tcb->timeslice = 0; + tcb->timeslice = 0; #endif } break; #if CONFIG_RR_INTERVAL > 0 + case SCHED_OTHER: case SCHED_RR: { #ifdef CONFIG_SCHED_SPORADIC @@ -169,8 +168,8 @@ int nxsched_set_scheduler(pid_t pid, int policy, /* Save the round robin scheduling parameters */ - tcb->flags |= TCB_FLAG_SCHED_RR; - tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); + tcb->flags |= TCB_FLAG_SCHED_RR; + tcb->timeslice = MSEC2TICK(CONFIG_RR_INTERVAL); } break; #endif @@ -265,12 +264,6 @@ int nxsched_set_scheduler(pid_t pid, int policy, } break; #endif - -#if 0 /* Not supported */ - case SCHED_OTHER: - tcb->flags |= TCB_FLAG_SCHED_OTHER; - break; -#endif } leave_critical_section(flags);