sched/sched_rrgetinterval.c: sched_get_rr_interval() should return {0,0} if round-robin scheduling is not selected for the task.

This commit is contained in:
Gregory Nutt
2019-09-10 10:04:36 -06:00
parent cc694e9862
commit af685dfe81
+23 -12
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/sched/sched_rrgetinterval.c * sched/sched/sched_rrgetinterval.c
* *
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -82,14 +82,13 @@
int sched_rr_get_interval(pid_t pid, struct timespec *interval) int sched_rr_get_interval(pid_t pid, struct timespec *interval)
{ {
#if CONFIG_RR_INTERVAL > 0
FAR struct tcb_s *rrtcb; FAR struct tcb_s *rrtcb;
/* If pid is zero, the timeslice for the calling process is written /* If pid is zero, the timeslice for the calling process is written
* into 'interval.' * into 'interval.'
*/ */
if (!pid) if (pid == 0)
{ {
rrtcb = this_task(); rrtcb = this_task();
} }
@@ -107,27 +106,39 @@ int sched_rr_get_interval(pid_t pid, struct timespec *interval)
else else
{ {
rrtcb = sched_gettcb(pid); rrtcb = sched_gettcb(pid);
if (!rrtcb) if (rrtcb == NULL)
{ {
set_errno(ESRCH); set_errno(ESRCH);
return ERROR; return ERROR;
} }
} }
if (!interval) if (interval == NULL)
{ {
set_errno(EFAULT); set_errno(EFAULT);
return ERROR; return ERROR;
} }
/* Convert the timeslice value from ticks to timespec */ #if CONFIG_RR_INTERVAL > 0
/* The thread has a timeslice ONLY if it is configured for round-robin
* scheduling.
*/
interval->tv_sec = CONFIG_RR_INTERVAL / MSEC_PER_SEC; if (rrtcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_RR)
interval->tv_nsec = (CONFIG_RR_INTERVAL % MSEC_PER_SEC) * NSEC_PER_MSEC; {
/* Convert the timeslice value from ticks to a timespec */
interval->tv_sec = CONFIG_RR_INTERVAL / MSEC_PER_SEC;
interval->tv_nsec = (CONFIG_RR_INTERVAL % MSEC_PER_SEC) * NSEC_PER_MSEC;
}
else
#endif
{
/* Return {0,0} meaning that the time slice is indefinite */
interval->tv_sec = 0;
interval->tv_nsec = 0;
}
return OK; return OK;
#else
set_errno(ENOSYS);
return ERROR;
#endif
} }