Skip to content

Commit

Permalink
feature [posix]: Add bindings to scheduler policy (#3831)
Browse files Browse the repository at this point in the history
  • Loading branch information
catap committed Mar 11, 2024
1 parent 4b9f631 commit 5bd3b47
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
44 changes: 44 additions & 0 deletions posixlib/src/main/resources/scala-native/sched.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#if defined(__unix__) || defined(__unix) || defined(unix) || \
(defined(__APPLE__) && defined(__MACH__))

#include <sched.h>

int scalanative_sched_other() { return SCHED_OTHER; }

int scalanative_sched_fifo() { return SCHED_FIFO; }

int scalanative_sched_rr() { return SCHED_RR; }

int scalanative_sched_sporadic() {
#ifdef SCHED_SPORADIC
return SCHED_SPORADIC;
#else
return SCHED_OTHER;
#endif
}

int scalanative_sched_batch() {
#ifdef SCHED_BATCH
return SCHED_BATCH;
#else
return SCHED_OTHER;
#endif
}

int scalanative_sched_idle() {
#ifdef SCHED_IDLE
return SCHED_IDLE;
#else
return SCHED_OTHER;
#endif
}

int scalanative_sched_deadline() {
#ifdef SCHED_DEADLINE
return SCHED_DEADLINE;
#else
return SCHED_OTHER;
#endif
}

#endif // Unix or Mac OS
24 changes: 24 additions & 0 deletions posixlib/src/main/scala/scala/scalanative/posix/sched.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ object sched {
cpuset: Ptr[cpu_set_t]
): CInt = extern

@name("scalanative_sched_other")
def SCHED_OTHER: CInt = extern

@name("scalanative_sched_fifo")
def SCHED_FIFO: CInt = extern

@name("scalanative_sched_rr")
def SCHED_RR: CInt = extern

@name("scalanative_sched_sporadic")
def SCHED_SPORADIC: CInt = extern

/** Not defined in POSIX standard, might lead to runtime errors */
@name("scalanative_sched_batch")
def SCHED_BATCH: CInt = extern

/** Not defined in POSIX standard, might lead to runtime errors */
@name("scalanative_sched_idle")
def SCHED_IDLE: CInt = extern

/** Not defined in POSIX standard, might lead to runtime errors */
@name("scalanative_sched_deadline")
def SCHED_DEADLINE: CInt = extern

// Types
type cpu_set_t = CInt

Expand Down

0 comments on commit 5bd3b47

Please sign in to comment.