Make ^C kill shm event loops
This is done unconditinally. There are very few times when we don't
want ^C to kill the loop nicely, so just do it until someone complains.
Also, graceful exit is much better than getting terminated and
potentially core dumping.
Change-Id: Ib156ca779c1c5a8d1597c1531a4b12ec14ae0314
diff --git a/aos/ipc_lib/shared_mem.cc b/aos/ipc_lib/shared_mem.cc
index 93ced7d..3bb7267 100644
--- a/aos/ipc_lib/shared_mem.cc
+++ b/aos/ipc_lib/shared_mem.cc
@@ -123,16 +123,17 @@
}
void aos_core_free_shared_mem() {
- void *shm_address = global_core->shared_mem;
- PCHECK(munmap((void *)SHM_START, SIZEOFSHMSEG) != -1)
- << ": munmap(" << shm_address << ", 0x" << std::hex
- << (size_t)SIZEOFSHMSEG << ") failed";
- if (global_core->owner) {
- PCHECK(shm_unlink(global_core->shm_name) == 0)
- << ": shared_mem: shm_unlink(" << global_core->shm_name << ") failed";
+ if (global_core != nullptr) {
+ void *shm_address = global_core->shared_mem;
+ PCHECK(munmap((void *)SHM_START, SIZEOFSHMSEG) != -1)
+ << ": munmap(" << shm_address << ", 0x" << std::hex
+ << (size_t)SIZEOFSHMSEG << ") failed";
+ if (global_core->owner) {
+ PCHECK(shm_unlink(global_core->shm_name) == 0)
+ << ": shared_mem: shm_unlink(" << global_core->shm_name << ") failed";
+ }
+ global_core = nullptr;
}
}
-int aos_core_is_init(void) {
- return global_core != NULL;
-}
+int aos_core_is_init(void) { return global_core != NULL; }