Do superstructure initialization before going realtime
It does a lot of math in the constructor, which eventually runs into the
realtime resource limit.
Change-Id: Ie57dcc956019ce291f495c1af9a9040b706e7fcf
diff --git a/aos/linux_code/init.cc b/aos/linux_code/init.cc
index 47c7f35..ce557e4 100644
--- a/aos/linux_code/init.cc
+++ b/aos/linux_code/init.cc
@@ -62,6 +62,10 @@
const char *const kNoRealtimeEnvironmentVariable = "AOS_NO_REALTIME";
+bool ShouldBeRealtime() {
+ return getenv(kNoRealtimeEnvironmentVariable) == nullptr;
+}
+
} // namespace
void LockAllMemory() {
@@ -95,9 +99,9 @@
free(heap_data);
}
-void InitNRT() {
+void InitNRT(bool for_realtime) {
InitStart();
- aos_core_create_shared_mem(false, false);
+ aos_core_create_shared_mem(false, for_realtime && ShouldBeRealtime());
logging::RegisterQueueImplementation();
LOG(INFO, "%s initialized non-realtime\n", program_invocation_short_name);
}
@@ -110,8 +114,14 @@
}
void Init(int relative_priority) {
- bool realtime = getenv(kNoRealtimeEnvironmentVariable) == nullptr;
- if (realtime) {
+ InitStart();
+ aos_core_create_shared_mem(false, ShouldBeRealtime());
+ logging::RegisterQueueImplementation();
+ GoRT(relative_priority);
+}
+
+void GoRT(int relative_priority) {
+ if (ShouldBeRealtime()) {
LockAllMemory();
// Only let rt processes run for 3 seconds straight.
@@ -133,9 +143,6 @@
printf("no realtime for %s. see stderr\n", program_invocation_short_name);
}
- InitStart();
- aos_core_create_shared_mem(false, realtime);
- logging::RegisterQueueImplementation();
LOG(INFO, "%s initialized realtime\n", program_invocation_short_name);
}