Fu Juntang
2021-09-17 acbf282b23b4cbdebca562d67132573de3902f94
src/shm/shm_mm.h
@@ -1,9 +1,14 @@
#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
#define SHM_QUEUE_ST_SET    50
struct shm_queue_status_t {
@@ -24,8 +29,20 @@
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);
  if(ptr == NULL || ptr == (void *)1 ) {
    ptr = mm_malloc(sizeof(T));
    hashtable_put(hashtable, key, ptr);
    new(ptr) T;
  }
  return (T*)ptr;
}
void shm_mm_free_by_key(int key) ;
@@ -34,4 +51,6 @@
int shm_mm_alloc_key();
#endif
typedef std::map<SHMString, int, std::less<SHMString>, SHM_STL_Allocator<std::pair<const SHMString, int> > > ProcDataZone;
#endif