fixed a few corner case bugs
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 0413072..40909c2 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -139,8 +139,9 @@
type_cache::Get(message.structure.type_id).name.c_str());
}
fprintf(output, BASE_FORMAT "%.*s: %.*s\n", BASE_ARGS,
- static_cast<int>(message.message_length), message.message,
- static_cast<int>(output_length), buffer);
+ static_cast<int>(message.structure.string_length),
+ message.structure.serialized,
+ static_cast<int>(sizeof(buffer) - output_length), buffer);
break;
}
}
diff --git a/aos/common/queue_types.cc b/aos/common/queue_types.cc
index e321b8e..e2310fc 100644
--- a/aos/common/queue_types.cc
+++ b/aos/common/queue_types.cc
@@ -201,26 +201,35 @@
return cache.at(type_id).type;
}
- // No need to lock because the only thing that happens is somebody adds on to
- // the end, and they shouldn't be adding the one we're looking for.
- const volatile ShmType *c = static_cast<volatile ShmType *>(
- global_core->mem_struct->queue_types.pointer);
- while (c != nullptr) {
- if (c->id == type_id) {
- size_t bytes = c->serialized_size;
- MessageType *type = MessageType::Deserialize(
- const_cast<const char *>(c->serialized), &bytes);
- cache.emplace(::std::piecewise_construct,
- ::std::forward_as_tuple(type_id),
- ::std::forward_as_tuple(*type, true));
- return *type;
+ if (aos_core_is_init()) {
+ // No need to lock because the only thing that happens is somebody adds on
+ // to the end, and they shouldn't be adding the one we're looking for.
+ const volatile ShmType *c = static_cast<volatile ShmType *>(
+ global_core->mem_struct->queue_types.pointer);
+ while (c != nullptr) {
+ if (c->id == type_id) {
+ size_t bytes = c->serialized_size;
+ MessageType *type = MessageType::Deserialize(
+ const_cast<const char *>(c->serialized), &bytes);
+ cache.emplace(::std::piecewise_construct,
+ ::std::forward_as_tuple(type_id),
+ ::std::forward_as_tuple(*type, true));
+ return *type;
+ }
+ c = c->next;
}
- c = c->next;
+ } else {
+ LOG(INFO, "FYI: no shm. going to LOG(FATAL) now\n");
}
+
LOG(FATAL, "MessageType for id 0x%" PRIx32 " not found\n", type_id);
}
void AddShm(uint32_t type_id) {
+ if (!aos_core_is_init()) {
+ LOG(FATAL, "can't AddShm(%" PRIu32 ") without shm!\n", type_id);
+ }
+
::aos::MutexLocker locker(&cache_lock);
CacheEntry &cached = cache.at(type_id);
if (cached.in_shm) return;
diff --git a/aos/linux_code/ipc_lib/shared_mem.c b/aos/linux_code/ipc_lib/shared_mem.c
index da91b68..069fe19 100644
--- a/aos/linux_code/ipc_lib/shared_mem.c
+++ b/aos/linux_code/ipc_lib/shared_mem.c
@@ -130,3 +130,7 @@
}
return 0;
}
+
+int aos_core_is_init(void) {
+ return global_core != NULL;
+}
diff --git a/aos/linux_code/ipc_lib/shared_mem.h b/aos/linux_code/ipc_lib/shared_mem.h
index c1b1f9c..4d5e88e 100644
--- a/aos/linux_code/ipc_lib/shared_mem.h
+++ b/aos/linux_code/ipc_lib/shared_mem.h
@@ -69,6 +69,9 @@
int aos_core_create_shared_mem(enum aos_core_create to_create);
int aos_core_free_shared_mem(void);
+// Returns whether or not the shared memory system is active.
+int aos_core_is_init(void);
+
#ifdef __cplusplus
}
#endif