예제 #1
0
파일: ipc.c 프로젝트: const86/rfs
void ipc_init(struct ipc *ipc)
{
	mpool_init(&ipc->mp);
	ipc->rb.pos = 0;
	ipc->rb.size = 0;
	ipc->wb.pos = 0;
}
예제 #2
0
파일: main.c 프로젝트: chenws/codes
void main()
{
	MPOOL_T mpool;
	int i=20;
	char *new_p1, *new_p2, *new_p3;
	void* arr_malloc[MAX_HANDLES];
	char mem_1[500];
	char mem_2[300];
	mpool_init(&mpool, mem_1, sizeof(mem_1), 0, 4);
	new_p1 = mpool_malloc(mpool, 10);
	mpool_print(mpool);
	if (!new_p1) printf("%s", PROMPT_FAILED);

	mpool_grow(mpool,mem_2, sizeof(mem_2));
	mpool_print(mpool);

	new_p2 = mpool_malloc(mpool, 32);
	if (!new_p2) printf("%s", PROMPT_FAILED);
	mpool_free(mpool, new_p2);
	mpool_print(mpool);
	new_p3 = mpool_malloc(mpool, 12);
	mpool_print(mpool);
	if (!new_p3) printf("%s", PROMPT_FAILED);
	mpool_free(mpool, new_p1);
	mpool_print(mpool);
	mpool_free(mpool, new_p2);
	mpool_print(mpool);
	mpool_free(mpool, new_p3);
	mpool_print(mpool);
	random_test(&mpool, arr_malloc, MAX_HANDLES, 10);
	lining_test(&mpool, arr_malloc, MAX_HANDLES);
	fixing_test(&mpool, arr_malloc, MAX_HANDLES);
}
예제 #3
0
/*
 * Release all objects in the pool, and reset the memory context.
 */
void
mpool_reset(MPool *mpool)
{
    Assert(mpool != NULL && mpool->context != NULL);
    Assert(MemoryContextIsValid(mpool->context));

    elog(DEBUG2, "MPool: total_bytes_allocated=" INT64_FORMAT
         ", bytes_used=" INT64_FORMAT ", bytes_wasted=" INT64_FORMAT,
         mpool->total_bytes_allocated, mpool->bytes_used,
         mpool->bytes_wasted);

    MemoryContextReset(mpool->context);
    mpool_init(mpool);
}
예제 #4
0
/*
 * Create a MPool object and initialize its variables.
 */
MPool *
mpool_create(MemoryContext parent,
             const char *name)
{
    MPool *mpool = MemoryContextAlloc(parent, sizeof(MPool));
    Assert(parent != NULL);
    mpool->parent = parent;
    mpool->context = AllocSetContextCreate(parent,
                                           name,
                                           ALLOCSET_DEFAULT_MINSIZE,
                                           ALLOCSET_DEFAULT_INITSIZE,
                                           ALLOCSET_DEFAULT_MAXSIZE);
    mpool_init(mpool);

    return mpool;
}
예제 #5
0
파일: mlxm_ep.c 프로젝트: ddurnov/libfabric
int mlxm_ep_open(struct fid_domain *domain, struct fi_info *info,
                 struct fid_ep **fid, void *context)
{
    struct mlxm_fid_ep     *fid_ep;
    struct mlxm_fid_domain *mlxm_domain;

    if (mlxm_check_mem_tag_format(mlxm_mem_tag_format)) {
        FI_WARN(&mlxm_prov, FI_LOG_CORE,
                "unsupported mem_tag_format: 0x%llx, supported: 0x%llx\n",
                (long long unsigned)mlxm_mem_tag_format,
                MLXM_MEM_TAG_FORMAT);
        return -EINVAL;
    }
    fid_ep = (struct mlxm_fid_ep *) calloc(1, sizeof *fid_ep);
    if (!fid_ep)
        return -ENOMEM;

    mlxm_domain = container_of(domain, struct mlxm_fid_domain, domain);
    fid_ep->ep.fid.fclass   = FI_CLASS_EP;
    fid_ep->ep.fid.context  = context;
    fid_ep->ep.fid.ops      = &mlxm_fi_ops;
    fid_ep->ep.ops          = &mlxm_ep_ops;
    fid_ep->ep.cm           = &mlxm_cm_ops;
    fid_ep->ep.tagged       = &mlxm_tagged_ops;
    fid_ep->domain          = mlxm_domain;

    if (info) {
        if (info->tx_attr)
            fid_ep->flags = info->tx_attr->op_flags;
        if (info->rx_attr)
            fid_ep->flags |= info->rx_attr->op_flags;

        if (info->dest_addr) {
            /* Connected mode: store the address until bind() */
            /* The user passes
             * hints.dest_addr = <address given by mxm_ep_address()>
             * TODO: clarify this flow */
        }
    }
    *fid = &fid_ep->ep;
    mpool_init(&mlxm_globals.req_pool, sizeof(struct mlxm_req), 32*4);
    fid_ep->mxm_mqs = &mlxm_globals.mq_storage;
    return 0;
}
예제 #6
0
/****************************************************************************************
* Function name - heap_init
*
* Description - Performs initialization of an allocated heap.
*
* Input -       *h - pointer to an allocated heap
*               initial_heap_size -  initial size to start
*               increase_step -  size to increase heap, when deciding to do so
*               comparator -  user-function, that compares user-objects, kept by the heap
*               dumper -  user-function, that dumps user-objects, kept by the heap
*               nodes_prealloc -  number of hnodes to be pre-allocated at initialization
*
* Return Code/Output - On success - 0, on error -1
****************************************************************************************/
int heap_init (heap*const h,
               size_t initial_heap_size,
               size_t increase_step,
               heap_cmp_func comparator,
               node_dump_func dumper,
               size_t nodes_prealloc)
{
  size_t i = 0;
	
  if (!h)
    {
      fprintf(stderr, "%s -error: wrong input\n", __func__);
      return -1;
    }
	
  memset ((void*)h, 0, sizeof (*h));
  
  if (! (h->heap = calloc (initial_heap_size, sizeof (hnode*))) )
    {
      fprintf(stderr, "%s - error: alloc heap failed\n", __func__);
      return -1;
    }
	
  /* Alloc array of node-ids */
  if (! (h->ids_arr = calloc (initial_heap_size, sizeof (long))) )
    {
      fprintf(stderr, "%s - error: alloc of nodes-ids array failed\n", __func__);
      return -1;
    }
	
  /* Invalidate node-ids array indexes */
  for (i = 0; i < initial_heap_size; i++)
    {
      h->ids_arr[i] = -1; /* non-valid id is -1 */
    }
	
  h->max_heap_size = initial_heap_size;
  h->heap_increase_step = increase_step;
	
  if (0 == comparator)
    {
      fprintf(stderr, "%s - error: comparator function should be provided.\n", __func__);
      return -1;      
    }
  else
    {
      h->fcomp = comparator;
    }

  h->fndump = dumper; /* If zero, we do not dump nodes. */

  if (!(h->nodes_mpool = cl_calloc (1, sizeof (mpool))))
    {
      fprintf(stderr, "%s - error: mpool allocation failed\n", __func__);
      return -1;
    }
  else
    {
      if (mpool_init (h->nodes_mpool, sizeof (hnode), nodes_prealloc) == -1)
        {
          fprintf(stderr, "%s - error: mpool_init () -  failed\n",  __func__);
          return -1;
        }
    }
  return 0;
}