Skip to content

Commit

Permalink
Update thread_priority.cpp (#170)
Browse files Browse the repository at this point in the history
* Update thread_priority.cpp

Adding implementation for build on windows.

* applying clang-format

---------

Co-authored-by: GilmarCorreia <gilmarcorreiajeronimo@gmail.com>
  • Loading branch information
SENAI-GilmarCorreia and GilmarCorreia authored Oct 30, 2024
1 parent f0cede3 commit 11af426
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/thread_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@

#include "realtime_tools/thread_priority.hpp"

#ifdef _WIN32
#include <windows.h>
#else
#include <sched.h>
#endif

#include <sys/capability.h>
#include <sys/mman.h>

Expand All @@ -49,10 +54,15 @@ bool has_realtime_kernel()

bool configure_sched_fifo(int priority)
{
#ifdef _WIN32
HANDLE thread = GetCurrentThread();
return SetThreadPriority(thread, priority);
#else
struct sched_param schedp;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = priority;
return !sched_setscheduler(0, SCHED_FIFO, &schedp);
#endif
}

bool is_capable(cap_value_t v)
Expand Down

0 comments on commit 11af426

Please sign in to comment.