| | |
| | | */ |
| | | #include "mm.h" |
| | | #include "sem_util.h" |
| | | |
| | | #include "logger_factory.h" |
| | | |
| | | /* $begin mallocmacros */ |
| | | /* single word (4) or double word (8) alignment */ |
| | |
| | | |
| | | |
| | | void mm_destroy(void) { |
| | | |
| | | struct shmid_ds shmid_ds; |
| | | //detache |
| | | if (shmdt(shmp) == -1) |
| | | err_exit(errno, "mm_init shmdt"); |
| | | if (shmctl(shmid, IPC_RMID, 0) == -1) |
| | | err_exit(errno, "mm_init shmctl IPC_RMID"); |
| | | SemUtil::remove(mutex); |
| | | err_exit(errno, "mm_destroy shmdt"); |
| | | |
| | | |
| | | if(shmctl(shmid, IPC_STAT, &shmid_ds) == -1) { |
| | | err_exit(errno, "mm_destroy shmctl IPC_STAT"); |
| | | } else { |
| | | //LoggerFactory::getLogger().debug("shm_nattch=%d\n", shmid_ds.shm_nattch); |
| | | if(shmid_ds.shm_nattch == 0) { |
| | | //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"); |
| | | |
| | | SemUtil::remove(mutex); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | /* |
| | | * extend_heap - Extend heap with free block and return its block pointer |