Skip to content

Commit

Permalink
AP_Scripting: add define option to disable interupts for the duration…
Browse files Browse the repository at this point in the history
… of script run
  • Loading branch information
IamPete1 authored and tridge committed Feb 2, 2022
1 parent da35216 commit 427e8d1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/AP_Scripting/lua_scripts.cpp
Expand Up @@ -19,6 +19,8 @@

#include <AP_Scripting/lua_generated_bindings.h>

#define DISABLE_INTERRUPTS_FOR_SCRIPT_RUN 0

extern const AP_HAL::HAL& hal;

bool lua_scripts::overtime;
Expand Down Expand Up @@ -471,13 +473,22 @@ void lua_scripts::run(void) {
// copy name for logging, cant do it after as script reschedule moves the pointers
const char * script_name = scripts->name;

#if DISABLE_INTERRUPTS_FOR_SCRIPT_RUN
void *istate = hal.scheduler->disable_interrupts_save();
#endif

const int startMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);
const uint32_t loadEnd = AP_HAL::micros();

run_next_script(L);

const uint32_t runEnd = AP_HAL::micros();
const int endMem = lua_gc(L, LUA_GCCOUNT, 0) * 1024 + lua_gc(L, LUA_GCCOUNTB, 0);

#if DISABLE_INTERRUPTS_FOR_SCRIPT_RUN
hal.scheduler->restore_interrupts(istate);
#endif

if ((_debug_options.get() & uint8_t(DebugLevel::RUNTIME_MSG)) != 0) {
gcs().send_text(MAV_SEVERITY_DEBUG, "Lua: Time: %u Mem: %d + %d",
(unsigned int)(runEnd - loadEnd),
Expand Down

0 comments on commit 427e8d1

Please sign in to comment.