fujuntang
2021-08-11 68d23225a38a35f1325eb39fa4ed5a005d5de473
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)
@@ -123,7 +122,8 @@
    return aptr;
  } else {
    SemUtil::inc(mutex);
    err_msg(0, "mm_malloc : out of memery\n");
    // abort();
    err_exit(0, "mm_malloc : out of memery\n");
    return NULL;
  }
@@ -228,6 +228,7 @@
/*
 * mm_init - Initialize the memory manager, M unit
 * @return 是否第一次创建
 */
bool mm_init(size_t heap_size)
{
@@ -300,16 +301,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);
    // 只有当前一个进程attach到共享内存上
    // 多个进程attach在共享内存上
    if (shmid_ds.shm_nattch > 1) {
      //detache
      if (shmdt(shmp) == -1) {
@@ -318,7 +320,7 @@
      SemUtil::inc(mutex);
      return false;
    } else  {
      // 只有当前一个进程attach到共享内存上
      hashtable_destroy(hashtable);
      //detache
      if (shmdt(shmp) == -1) {