mirror of
https://github.com/nasa/trick.git
synced 2025-01-29 15:43:57 +00:00
Move the lock_memory function out of the Executive to RealtimeSync
Moved the lock memory function to the real time sync directory. It doesn't need to be part of the RealTimeSync class either so I left the lock/unlock code in the C language calls for real time functions. refs #195
This commit is contained in:
parent
d5f6d201c6
commit
26dfb3a000
@ -1114,15 +1114,6 @@ namespace Trick {
|
||||
*/
|
||||
virtual int set_thread_cpu_affinity(unsigned int thread_id , int cpu_num) ;
|
||||
|
||||
/**
|
||||
@userdesc Commmand to lock all of the process's memory into RAM, preventing it from being swapped out.
|
||||
@par Python Usage:
|
||||
@code trick.exec_set_lock_memory(<yes_no>) @endcode
|
||||
@param yes_no - boolean (C integer 0/1) indicating if we lock memory
|
||||
@return the return code of system lock call
|
||||
*/
|
||||
virtual int set_lock_memory(bool yes_no) ;
|
||||
|
||||
/**
|
||||
@userdesc Command to run the simulation (after a freeze). Set exec_command to RunCmd.
|
||||
@par Python Usage:
|
||||
|
@ -48,7 +48,6 @@ extern "C" {
|
||||
int exec_set_enable_freeze( int on_off ) ;
|
||||
int exec_set_job_cycle(const char * job_name, int instance_num, double in_cycle) ;
|
||||
int exec_set_job_onoff(const char * job_name , int instance_num, int on) ;
|
||||
int exec_set_lock_memory(int yes_no) ;
|
||||
int exec_set_rt_nap(int on_off) ;
|
||||
int exec_set_sim_object_onoff(const char * sim_object_name , int on) ;
|
||||
int exec_set_software_frame(double) ;
|
||||
|
@ -19,7 +19,10 @@ int real_time_restart(long long ref_time ) ;
|
||||
int is_real_time() ;
|
||||
const char * real_time_clock_get_name() ;
|
||||
int real_time_set_rt_clock_ratio(double in_clock_ratio) ;
|
||||
int real_time_lock_memory(int yes_no) ;
|
||||
|
||||
// Deprecated
|
||||
int exec_set_lock_memory(int yes_no) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -887,18 +887,6 @@ extern "C" int exec_set_job_cycle(const char * job_name, int instance, double in
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @relates Trick::Executive
|
||||
* @copydoc Trick::Executive::set_lock_memory
|
||||
* C wrapper for Trick::Executive::set_lock_memory
|
||||
*/
|
||||
extern "C" int exec_set_lock_memory(int yes_no) {
|
||||
if ( the_exec != NULL ) {
|
||||
return the_exec->set_lock_memory((bool)yes_no) ;
|
||||
}
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
/**
|
||||
* @relates Trick::Executive
|
||||
* @copydoc Trick::Executive::add_depends_on_job
|
||||
|
@ -1,52 +0,0 @@
|
||||
|
||||
#include "trick/Executive.hh"
|
||||
#include "trick/message_proto.h"
|
||||
#include "trick/message_type.h"
|
||||
|
||||
#if __linux
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
|
||||
int Trick::Executive::set_lock_memory(bool yes_no) {
|
||||
|
||||
/** @par Detailed Design */
|
||||
int ret = 0 ;
|
||||
|
||||
/** @li lock or unlock memory based on yes_no parameter */
|
||||
if ( yes_no ) {
|
||||
if ((ret = mlockall(MCL_CURRENT | MCL_FUTURE)) != 0 ) {
|
||||
perror("Error locking memory.");
|
||||
message_publish(MSG_ERROR, "Error %d when requesting memory lock.\n", errno);
|
||||
} else {
|
||||
message_publish(MSG_INFO, "Sim locked memory\n");
|
||||
}
|
||||
} else {
|
||||
if ( (ret = munlockall()) != 0 ) {
|
||||
perror("Error unlocking memory.");
|
||||
message_publish(MSG_ERROR, "Error %d when requesting memory unlock.\n", errno);
|
||||
} else {
|
||||
message_publish(MSG_INFO, "Sim unlocked memory\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** @li return result of mlockall or munlockall */
|
||||
return(ret) ;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if __APPLE__
|
||||
|
||||
int Trick::Executive::set_lock_memory(bool yes_no __attribute__((unused)) ) {
|
||||
|
||||
message_publish(MSG_WARNING, "Warning: Trick on Darwin does not yet support memory locking.\n");
|
||||
|
||||
return(0) ;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -785,20 +785,6 @@ object_${TRICK_HOST_CPU}/Executive_set_thread_rt_semaphore.o: \
|
||||
${TRICK_HOME}/include/trick/Threads.hh \
|
||||
${TRICK_HOME}/include/trick/ThreadBase.hh \
|
||||
${TRICK_HOME}/include/trick/sim_mode.h
|
||||
object_${TRICK_HOST_CPU}/Executive_set_lock_memory.o: Executive_set_lock_memory.cpp \
|
||||
${TRICK_HOME}/include/trick/Executive.hh \
|
||||
${TRICK_HOME}/include/trick/Scheduler.hh \
|
||||
${TRICK_HOME}/include/trick/ScheduledJobQueue.hh \
|
||||
${TRICK_HOME}/include/trick/JobData.hh \
|
||||
${TRICK_HOME}/include/trick/InstrumentBase.hh \
|
||||
${TRICK_HOME}/include/trick/SimObject.hh \
|
||||
${TRICK_HOME}/include/trick/ScheduledJobQueue.hh \
|
||||
${TRICK_HOME}/include/trick/SimObject.hh \
|
||||
${TRICK_HOME}/include/trick/Threads.hh \
|
||||
${TRICK_HOME}/include/trick/ThreadBase.hh \
|
||||
${TRICK_HOME}/include/trick/sim_mode.h \
|
||||
${TRICK_HOME}/include/trick/message_proto.h \
|
||||
${TRICK_HOME}/include/trick/message_type.h
|
||||
object_${TRICK_HOST_CPU}/Executive_shutdown.o: Executive_shutdown.cpp \
|
||||
${TRICK_HOME}/include/trick/Executive.hh \
|
||||
${TRICK_HOME}/include/trick/Scheduler.hh \
|
||||
|
@ -13,4 +13,6 @@ object_${TRICK_HOST_CPU}/RealtimeSync_c_intf.o: RealtimeSync_c_intf.cpp \
|
||||
${TRICK_HOME}/include/trick/Timer.hh \
|
||||
${TRICK_HOME}/include/trick/realtimesync_proto.h \
|
||||
${TRICK_HOME}/include/trick/exec_proto.h \
|
||||
${TRICK_HOME}/include/trick/sim_mode.h
|
||||
${TRICK_HOME}/include/trick/sim_mode.h \
|
||||
${TRICK_HOME}/include/trick/message_proto.h \
|
||||
${TRICK_HOME}/include/trick/message_type.h
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include "trick/RealtimeSync.hh"
|
||||
#include "trick/realtimesync_proto.h"
|
||||
#include "trick/exec_proto.h"
|
||||
#include "trick/message_proto.h"
|
||||
#include "trick/message_type.h"
|
||||
|
||||
|
||||
/* Global singleton pointer to the real-time synchronization */
|
||||
extern Trick::RealtimeSync * the_rts ;
|
||||
@ -85,3 +88,47 @@ int real_time_change_timer(Trick::Timer * in_sleep_timer ) {
|
||||
extern "C" int real_time_set_rt_clock_ratio(double in_clock_ratio) {
|
||||
return the_rts->set_rt_clock_ratio(in_clock_ratio) ;
|
||||
}
|
||||
|
||||
// The lock memory functions are most closely related to real-time but are
|
||||
// not required for syncing. Therefore keep the routines as stand
|
||||
// alone C functions.
|
||||
|
||||
#if __linux
|
||||
#include <sys/mman.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
extern "C" int real_time_lock_memory(int yes_no) {
|
||||
/* lock or unlock memory based on yes_no parameter */
|
||||
int ret = 0 ;
|
||||
#if __linux
|
||||
if ( yes_no ) {
|
||||
if ((ret = mlockall(MCL_CURRENT | MCL_FUTURE)) != 0 ) {
|
||||
perror("Error locking memory.");
|
||||
message_publish(MSG_ERROR, "Error %d when requesting memory lock.\n", errno);
|
||||
} else {
|
||||
message_publish(MSG_INFO, "Sim locked memory\n");
|
||||
}
|
||||
} else {
|
||||
if ( (ret = munlockall()) != 0 ) {
|
||||
perror("Error unlocking memory.");
|
||||
message_publish(MSG_ERROR, "Error %d when requesting memory unlock.\n", errno);
|
||||
} else {
|
||||
message_publish(MSG_INFO, "Sim unlocked memory\n");
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
#if __APPLE__
|
||||
(void)yes_no ;
|
||||
message_publish(MSG_WARNING, "Warning: Trick on Darwin does not yet support memory locking.\n");
|
||||
#endif
|
||||
return ret ;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int exec_set_lock_memory(int yes_no) {
|
||||
message_publish(MSG_WARNING, "Warning: exec_set_lock_memory deprecated. Use real_time_lock_memory (auto-called)\n");
|
||||
return real_time_lock_memory(yes_no) ;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user