From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Masterarbeit/src/XorayaPluginExecutor/main.cpp | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp (limited to 'Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp') diff --git a/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp b/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp new file mode 100644 index 0000000..c2e131c --- /dev/null +++ b/Master/Masterarbeit/src/XorayaPluginExecutor/main.cpp @@ -0,0 +1,108 @@ +/*! + * \file main.cpp + * \author S. Eisenhauer + * \date 31.08.2011 + * \brief Application startup + */ + +/*! + * \mainpage XORAYA Plugin executor + * This is the main application running on the XORAYA connect to integrate with CanEasy. +*/ + +#include +#include +#include +#include +#include + +#include "CPluginExecutor.h" +#include "global.h" + +/*! +* \brief Allocates a safe stack +*/ +void prefault_stack() +{ + unsigned char aucDummy[nMAX_SAFE_STACK]; + + memset(aucDummy, 0, nMAX_SAFE_STACK); + return; +} + +/*! +* \brief Prevents memory of this process to be swapped to disc +* \warning process needs root privileges for this to work correctly +*/ +void lockmem() +{ + int res = 0; + if( (res = mlockall(MCL_CURRENT|MCL_FUTURE)) != 0) + { + ERROR_PRINT("mlockall failed: %d errno: %d",res,errno); + //exit(-2); + } +} + +/*! +* \brief initialization code +*/ +void init() +{ + lockmem(); + prefault_stack(); +} + +/*! +* \brief application starts here +* \param[in] argc number of arguments passed to process +* \param[in] argv the arguments +* \return exit code, 0 on success +*/ +int main(int argc, char* argv[]) +{ + int res = 0; + int schedulerPolicy; + sched_param sp; + + init(); + + static CPluginExecutor xPluginExec; + boost::thread xExecThread( + boost::function( + boost::bind(&CPluginExecutor::vRun,boost::ref(xPluginExec)) + ) + ); + + if( argc == 2) + { + if( strcmp(argv[1],"RT") == 0 ) + { + schedulerPolicy = SCHED_FIFO; + sp.sched_priority = tenPrio::nenRT ; // rt priority + if(pthread_setschedparam(xExecThread.native_handle(), schedulerPolicy, &sp)) + { + ERROR_PRINT("pthread_setschedparam failed. Errno: %d",errno); + } + } + } + + if( (res = pthread_getschedparam(xExecThread.native_handle(),&schedulerPolicy,&sp)) != 0 ) + { + ERROR_PRINT("pthread_getschedparam failed: %d errno: %d",res,errno); + } + else + { + DEBUG_PRINT("executor thread prio: %d scheduler: %s" + ,sp.sched_priority + ,(schedulerPolicy==SCHED_OTHER)?"SCHED_OTHER": + (schedulerPolicy==SCHED_FIFO)?"SCHED_FIFO": + (schedulerPolicy==SCHED_RR)?"SCHED_RR":"other"); + } + + xExecThread.join(); + DEBUG_PRINT("exiting"); + return 0; +} + + -- cgit v1.2.3