-
Notifications
You must be signed in to change notification settings - Fork 7.4k
kernel: posix: implement schedule related APIs for POSIX. #5510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2017 Intel Corporation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that it's 2018, these copyright headers need updating when (significant) changes are made, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've personally never received any guidance that this is necessary. |
||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdint.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need to include |
||
|
||
#define SCHED_COOP 0 | ||
#define SCHED_PREMPT 1 | ||
|
||
extern int sched_get_priority_min(int policy); | ||
extern int sched_get_priority_max(int policy); | ||
extern int sched_yield(void); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2017 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <kernel.h> | ||
#include <pthread.h> | ||
|
||
/* | ||
* ======== sched_get_priority_min ======== | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide the documentation in the header file, using the Doxygen format. |
||
* Provide Minimum Priority for the given policy | ||
* | ||
* In case of Cooperative priority value returned | ||
* is negative of the priority value. | ||
* | ||
* returns: priority corresponing to policy | ||
* -EINVAL for Error | ||
*/ | ||
int sched_get_priority_min(int policy) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be simplified by using the int sched_get_priority_min(int policy)
{
if (IS_ENABLED(CONFIG_COOP_ENABLED)) {
if (priority == SCHED_COOP) {
return K_LOWEST_APPLICATION_THREAD_PRIO;
}
}
if (IS_ENABLED(CONFIG_PREEMPT_ENABLED)) {
if (priority == SCHED_PREEMPT) {
return K_LOWEST_APPLICATION_THREAD_PRIO;
}
}
errno = EINVAL;
return -1;
} |
||
{ | ||
|
||
int priority = -EINVAL; | ||
|
||
if (!((policy == CONFIG_COOP_ENABLED) || (policy == SCHED_PREMPT))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CONFIG_COOP_ENABLED sounds like a Zephyr thing, rather than a POSIX thing. Is it correct here? |
||
return -EINVAL; | ||
} | ||
#if defined(CONFIG_COOP_ENABLED) && defined(CONFIG_PREEMPT_ENABLED) | ||
priority = (policy == SCHED_COOP) ? (-1 * -1) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
K_LOWEST_APPLICATION_THREAD_PRIO; | ||
#elif defined(CONFIG_COOP_ENABLED) | ||
priority = (policy == SCHED_COOP) ? | ||
(-1 * K_LOWEST_APPLICATION_THREAD_PRIO) : -EINVAL; | ||
#elif defined(CONFIG_PREEMPT_ENABLED) | ||
priority = (policy == SCHED_PREMPT) ? K_LOWEST_APPLICATION_THREAD_PRIO : | ||
-EINVAL; | ||
#endif | ||
return priority; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions will return |
||
} | ||
|
||
/* | ||
* ======== sched_get_priority_max ======== | ||
* Provide Maximum Priority for the given policy | ||
* | ||
* In case of Cooperative priority value returned | ||
* is negative of the priority value. | ||
* | ||
* returns: priority corresponing to policy | ||
* -EINVAL for Error | ||
*/ | ||
int sched_get_priority_max(int policy) | ||
{ | ||
int priority = -EINVAL; | ||
|
||
if (!((policy == CONFIG_COOP_ENABLED) || (policy == SCHED_PREMPT))) { | ||
return -EINVAL; | ||
} | ||
#if defined(CONFIG_COOP_ENABLED) && defined(CONFIG_PREEMPT_ENABLED) | ||
priority = (policy == SCHED_COOP) ? | ||
(-1 * K_HIGHEST_APPLICATION_THREAD_PRIO) : 0; | ||
#elif defined(CONFIG_COOP_ENABLED) | ||
priority = (policy == SCHED_COOP) ? | ||
(-1 * K_HIGHEST_APPLICATION_THREAD_PRIO) : -EINVAL; | ||
#elif defined(CONFIG_PREEMPT_ENABLED) | ||
priority = (policy == SCHED_PREMPT) ? | ||
K_HIGHEST_APPLICATION_THREAD_PRIO : -EINVAL; | ||
#endif | ||
return priority; | ||
} | ||
|
||
/* | ||
* ======== sched_yield ======== | ||
*/ | ||
int sched_yield(void) | ||
{ | ||
k_yield(); | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These definitions are in a file named
<sched.h>
; shouldn't them be in a file with the same name so that code that assumes this will be able to find them without change?