From 5c912c70e9333298ff48f7ea15424f72ca977b99 Mon Sep 17 00:00:00 2001
From: Fu Juntang <StrongTiger_001@163.com>
Date: 星期五, 17 九月 2021 09:43:55 +0800
Subject: [PATCH] Add the heartbeat logic feature.

---
 src/shm/mm.cpp |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/shm/mm.cpp b/src/shm/mm.cpp
index d7cc375..e4ef672 100644
--- a/src/shm/mm.cpp
+++ b/src/shm/mm.cpp
@@ -113,7 +113,6 @@
 
   newsize = ALIGN(size +  (SIZE_T_SIZE << 1) +  (PTR_SIZE << 1) );
 
-    //fprintf(stderr, "mm_malloc : size=%u\n", size);
   /* Search the free list for a fit */
   SemUtil::dec(mutex);
   if ((ptr = find_fit(newsize)) != NULL)
@@ -124,6 +123,10 @@
   } else {
     SemUtil::inc(mutex);
     err_msg(0, "mm_malloc : out of memery\n");
+    LoggerFactory::getLogger()->fatal("mm_malloc : out of memery\n");
+    // abort();
+    exit(1);
+    
     return NULL;
   }
 
@@ -228,6 +231,7 @@
 
 /*
  * mm_init - Initialize the memory manager, M unit
+ * @return 鏄惁绗竴娆″垱寤�
  */
 bool mm_init(size_t heap_size)
 {
@@ -252,6 +256,7 @@
     first = false;
     shmid  = shmget(SHM_KEY, 0, 0);
   }
+
   if (shmid == -1)
     err_exit(errno, "mm_init shmget");
   shmp = shmat(shmid, key_addr, 0);
@@ -300,16 +305,17 @@
   return first;
 }
 
-
+/**
+ * @return 鏄惁鐪熸閿�姣佹垚鍔�
+ */
 bool mm_destroy(void) {
   struct shmid_ds shmid_ds;
- 
   
   SemUtil::dec(mutex);
   
   if(shmctl(shmid, IPC_STAT, &shmid_ds) == 0) {
     //LoggerFactory::getLogger()->debug("shm_nattch=%d\n", shmid_ds.shm_nattch);
-    // 鍙湁褰撳墠涓�涓繘绋媋ttach鍒板叡浜唴瀛樹笂
+    // 澶氫釜杩涚▼attach鍦ㄥ叡浜唴瀛樹笂
     if (shmid_ds.shm_nattch > 1) {
       //detache
       if (shmdt(shmp) == -1) {
@@ -318,7 +324,7 @@
       SemUtil::inc(mutex);
       return false;
     } else  {
-      
+      // 鍙湁褰撳墠涓�涓繘绋媋ttach鍒板叡浜唴瀛樹笂
       hashtable_destroy(hashtable);
       //detache
       if (shmdt(shmp) == -1) {
@@ -332,8 +338,6 @@
         err_exit(errno, "mm_destroy shmctl IPC_RMID");
       else 
          LoggerFactory::getLogger()->debug("shared memory destroy\n");
-
-      LoggerFactory::getLogger()->debug( "mm_destroy: real destroy.");
 
       SemUtil::inc(mutex);
       SemUtil::remove(mutex);
@@ -358,6 +362,7 @@
 
 void mm_free_by_key(int key) {
   void *ptr;
+
   ptr = hashtable_get(hashtable, key);
   if(ptr != NULL) {
     mm_free(ptr);

--
Gitblit v1.8.0