wangzhengquan
2021-02-20 b5ae34d4422399c5d5458d071cca8c9bc89d20bb
src/shm/shm_mm.h
@@ -1,9 +1,12 @@
#ifndef __SHM_MM_H__
#define __SHM_MM_H__
#include "usg_common.h"
#include "shm_allocator.h"
#include "key_def.h"
#define SHM_QUEUE_ST_OPENED 0
#define SHM_QUEUE_ST_CLOSED 1
#define SHM_QUEUE_ST_RECYCLED 2
struct shm_queue_status_t {
@@ -24,8 +27,22 @@
void shm_mm_free (void *ptr);
template <typename T>
T* shm_mm_attach(int key) ;
T* shm_mm_attach(int key) {
   void *ptr;
   // T* tptr;
   hashtable_t *hashtable = mm_get_hashtable();
  ptr = hashtable_get(hashtable, key);
// printf("shm_mm_malloc_by_key  malloc before %d, %p\n", key, ptr);
  if(ptr == NULL || ptr == (void *)1 ) {
    ptr = mm_malloc(sizeof(T));
    hashtable_put(hashtable, key, ptr);
    new(ptr) T;
// printf("shm_mm_malloc_by_key  use new %d, %p\n", key, ptr);
  }
  return (T*)ptr;
}
void shm_mm_free_by_key(int key) ;