Skip to content

Commit 9405ad6

Browse files
committed
Replace pthread_getpriority nonstandard function with standard ones
I chose the scheduler priorities based on https://man7.org/linux/man-pages/man7/sched.7.html I think the cooperative app cores are most like SCHED_FIFO, while the sys core is similar to SCHED_RR. However, I don't think our pthread implementation would be able to accurately return the right policy since we need to know what processor the thread is running on, and the only API to get that gets the ID for the current thread. Since the pthread function passes in a thread ID, we are unable to always get the processor ID and thus the policy. In this case, I think we should just always return (and accept in set) SCHED_FIFO. I don't think this will be used anyways.
1 parent cf92808 commit 9405ad6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/unix/newlib/horizon/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ pub const FIONBIO: ::c_ulong = 1;
151151

152152
pub const RTLD_DEFAULT: *mut ::c_void = 0 as *mut ::c_void;
153153

154+
// For pthread get/setschedparam
155+
pub const SCHED_FIFO: ::c_int = 1;
156+
pub const SCHED_RR: ::c_int = 2;
157+
154158
// Horizon OS works doesn't or can't hold any of this information
155159
safe_f! {
156160
pub {const} fn WIFSTOPPED(_status: ::c_int) -> bool {
@@ -214,7 +218,17 @@ extern "C" {
214218
ideal_processor: ::c_int,
215219
) -> ::c_int;
216220

217-
pub fn pthread_getpriority() -> ::c_int;
221+
pub fn pthread_getschedparam(
222+
native: ::pthread_t,
223+
policy: *mut ::c_int,
224+
param: *mut ::sched_param,
225+
) -> ::c_int;
226+
227+
pub fn pthread_setschedparam(
228+
native: ::pthread_t,
229+
policy: ::c_int,
230+
param: *const ::sched_param,
231+
) -> ::c_int;
218232

219233
pub fn gethostid() -> ::c_long;
220234
}

0 commit comments

Comments
 (0)