From 379f42982b8c57ee6511cb8e498019f454323977 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 07 七月 2020 11:04:39 +0800
Subject: [PATCH] update

---
 squeue/mm.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/squeue/mm.c b/squeue/mm.c
index 4135964..7b39391 100644
--- a/squeue/mm.c
+++ b/squeue/mm.c
@@ -2,7 +2,7 @@
  * 绠$悊鍏变韩鍐呭瓨鐨勫垎閰嶏紝涓庨噴鏀�
  */
 #include "mm.h"
-#include "pcsem.h"
+#include "sem_util.h"
 
 
 /* $begin mallocmacros */
@@ -28,7 +28,7 @@
 #define MIN_BLOCK_SIZE (ALIGN( (SIZE_T_SIZE << 1) + SIZE_T_SIZE + (PTR_SIZE << 1) ))
 
 
-#define MAX(x, y) ((x) > (y)? (x) : (y))
+//#define MAX(x, y) ((x) > (y)? (x) : (y))
 
 /* Pack a size and allocated bit into a word */
 #define PACK(size, alloc)  ((size) | (alloc)) //line:vm:mm:pack
@@ -77,7 +77,8 @@
 
 static  int shmid = -1;
 static  void *shmp;
-static int mutex = pcsem::init(8899, 1);
+//static int mutex = SemUtil::get(8899, 1);
+static int mutex = SemUtil::get(IPC_PRIVATE, 1);
 
 static void *mem_start_brk;  /* points to first byte of heap */
 static void *mem_brk;        /* points to last byte of heap */
@@ -99,11 +100,11 @@
 
     //fprintf(stderr, "mm_malloc : size=%u\n", size);
   /* Search the free list for a fit */
-  pcsem::dec(mutex);
+  SemUtil::dec(mutex);
   if ((ptr = find_fit(newsize)) != NULL)
   {
     aptr = place(ptr, newsize);
-    pcsem::inc(mutex);
+    SemUtil::inc(mutex);
     return aptr;
   } else {
     fprintf(stderr, "mm_malloc : out of memery\n");
@@ -129,11 +130,11 @@
 
   
   size_t size = GET_SIZE(HDRP(ptr));
-  pcsem::dec(mutex);
+  SemUtil::dec(mutex);
   PUT(HDRP(ptr), PACK(size, 0));
   PUT(FTRP(ptr), PACK(size, 0));
   coalesce(ptr);
-  pcsem::inc(mutex);
+  SemUtil::inc(mutex);
 }
 
 
@@ -214,10 +215,10 @@
 {
   
   //宸茬粡鍒濆鍖栬繃浜�
-  pcsem::dec(mutex);
+  SemUtil::dec(mutex);
   if (shmid != -1){
     *addr = shmp;
-    pcsem::inc(mutex);
+    SemUtil::inc(mutex);
     return false;
   }
 
@@ -246,7 +247,7 @@
 
   if(!first) {
     *addr = shmp;
-    pcsem::inc(mutex);
+    SemUtil::inc(mutex);
     return first;
   }
 
@@ -271,19 +272,19 @@
     err_exit(errno, "mm_init extend_heap");
 
   *addr = shmp;
-  pcsem::inc(mutex);
+  SemUtil::inc(mutex);
   return first;
 }
 
  
 
-void mm_deinit(void) {
+void mm_destroy(void) {
 
   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");
-  pcsem::remove(mutex);
+  SemUtil::remove(mutex);
 }
 /*
  * extend_heap - Extend heap with free block and return its block pointer

--
Gitblit v1.8.0