From 08f25e576c34f447cb60870d037d9146b2113d66 Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期一, 25 十月 2021 11:53:47 +0800
Subject: [PATCH] Optimize the lock operate logic.

---
 src/shm/mm.cpp |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/shm/mm.cpp b/src/shm/mm.cpp
index 3cdd3a2..13ec443 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)
@@ -148,7 +147,7 @@
    *}
    */
 
-  SemUtil::dec(mutex);
+  SemUtil::dec_uni(mutex);
   size_t size = GET_SIZE(HDRP(ptr));
   PUT(HDRP(ptr), PACK(size, 0));
   PUT(FTRP(ptr), PACK(size, 0));
@@ -238,7 +237,7 @@
 {
   
   //鍚屼竴杩涚▼鍐呭凡缁忓垵濮嬪寲杩囦簡
-  SemUtil::dec(mutex);
+  SemUtil::dec_uni(mutex);
   if (shmid != -1){
     hashtable = (hashtable_t *)shmp;
     SemUtil::inc(mutex);
@@ -257,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);
@@ -311,7 +311,7 @@
 bool mm_destroy(void) {
   struct shmid_ds shmid_ds;
   
-  SemUtil::dec(mutex);
+  SemUtil::dec_uni(mutex);
   
   if(shmctl(shmid, IPC_STAT, &shmid_ds) == 0) {
     //LoggerFactory::getLogger()->debug("shm_nattch=%d\n", shmid_ds.shm_nattch);
@@ -336,10 +336,6 @@
       //remove shared memery
       if (shmctl(shmid, IPC_RMID, 0) == -1)
         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);
@@ -364,6 +360,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