Skip to content
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

Update thread_priority.cpp #170

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading