Skip to content

Commit

Permalink
Update thread_priority.cpp
Browse files Browse the repository at this point in the history
Adding implementation for build on windows.
  • Loading branch information
SENAI-GilmarCorreia committed Aug 21, 2024
1 parent 7bd84f6 commit 47d2901
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/thread_priority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@

#include "realtime_tools/thread_priority.hpp"

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

#include <cstring>
#include <fstream>
Expand All @@ -47,10 +51,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
}

} // namespace realtime_tools

0 comments on commit 47d2901

Please sign in to comment.