예제 #1
0
/*
  Initialize a malloc_state struct.

  This is called only from within __malloc_consolidate, which needs
  be called in the same contexts anyway.  It is never called directly
  outside of __malloc_consolidate because some optimizing compilers try
  to inline it at all call points, which turns out not to be an
  optimization at all. (Inlining it in __malloc_consolidate is fine though.)
*/
static void malloc_init_state(mstate av)
{
    int     i;
    mbinptr bin;

    /* Establish circular links for normal bins */
    for (i = 1; i < NBINS; ++i) {
	bin = bin_at(av,i);
	bin->fd = bin->bk = bin;
    }

    av->top_pad        = DEFAULT_TOP_PAD;
    av->n_mmaps_max    = DEFAULT_MMAP_MAX;
    av->mmap_threshold = DEFAULT_MMAP_THRESHOLD;
    av->trim_threshold = DEFAULT_TRIM_THRESHOLD;

#if MORECORE_CONTIGUOUS
    set_contiguous(av);
#else
    set_noncontiguous(av);
#endif


    set_max_fast(av, DEFAULT_MXFAST);

    //av->top            = initial_top(av);
    init_linked_list(&(av->ustate_list));     //init ustate list
    av->pagesize       = malloc_getpagesize;
    
    // add new mstate to the mstate list
    list_insert_tail(&(get_abstate()->mstate_list), (void *)av);
}
예제 #2
0
void init_transition_table(TRANSITIONTABLE* ptt, int m)
{
    int i;
    ptt -> n = m;
    ptt -> parray = (LINKEDLIST*)malloc(m * sizeof(LINKEDLIST));
    for(i = 0; i < m; i++)
	init_linked_list((ptt -> parray) + i);
}
예제 #3
0
static void init_arbiter_thread(struct arbiter_thread *abt)
{
	//initialize the arbiter state

	//client table init
	init_linked_list(&abt->client_list);

	//init socket ipc
	init_arbiter_ipc(abt);
	return;
}
예제 #4
0
파일: gr_bary.c 프로젝트: fd00/genlog
int 
compute_sel_bary_positions(GraphFrame *gf)
{
  int mes = 0;
  int cycle_len = count_llist(gf->list_sel_vertex);
  enumerate_vertices(gf);
  reset_mark_pick_vertices(gf);
  reset_level_vertices(gf);

  if(!gf->the_cycle)
    gf->the_cycle = init_linked_list();
  if(!gf->list_visited_vertex)
    gf->list_visited_vertex = init_linked_list();
  if(!gf->the_rest)
    gf->the_rest = init_linked_list();

  get_sel_cycle(gf);
  /*printing_linked_list(gf->the_cycle);*/
  if(!is_empty_list(gf->the_cycle))
    {
      Delete_hash_table(gf->HV);
      
      circularize(gf,gf->the_cycle, cycle_len);
      get_rest(gf);
      /*printing_linked_list(gf->the_rest);*/
      if(!is_empty_list(gf->the_rest))
	mes = layout_rest(gf, gf->the_rest, gf->count_vertex-cycle_len);

    }
  else
    mes = NO_CYCLE;

  Delete_all_list(gf->the_cycle);
  Delete_all_list(gf->list_visited_vertex);
  Delete_all_list(gf->the_rest);
  gf->the_cycle = init_linked_list();
  gf->list_visited_vertex = init_linked_list();
  gf->the_rest = init_linked_list();
  return mes;
}
예제 #5
0
/* ------------------------- __malloc_consolidate -------------------------

  __malloc_consolidate is a specialized version of free() that tears
  down chunks held in fastbins.  Free itself cannot be used for this
  purpose since, among other things, it might place chunks back onto
  fastbins.  So, instead, we need to use a minor variant of the same
  code.

  Also, because this routine needs to be called the first time through
  malloc anyway, it turns out to be the perfect place to trigger
  initialization code.
*/
void attribute_hidden __malloc_consolidate(mstate av)
{
    mfastbinptr*    fb;                 /* current fastbin being consolidated */
    mfastbinptr*    maxfb;              /* last fastbin (for loop control) */
    mchunkptr       p;                  /* current chunk being consolidated */
    mchunkptr       nextp;              /* next chunk to consolidate */
    mchunkptr       unsorted_bin;       /* bin header */
    mchunkptr       first_unsorted;     /* chunk to link to */
    ustate	    unit;		/*  */

    /* These have same use as in free() */
    mchunkptr       nextchunk;
    size_t size;
    size_t nextsize;
    size_t prevsize;
    int             nextinuse;
    mchunkptr       bck;
    mchunkptr       fwd;

    /*
       If max_fast is 0, we know that av hasn't
       yet been initialized, in which case do so below
       */

    if (av->max_fast != 0) {
	clear_fastchunks(av);

	unsorted_bin = unsorted_chunks(av);

	/*
	   Remove each chunk from fast bin and consolidate it, placing it
	   then in unsorted bin. Among other reasons for doing this,
	   placing in unsorted bin avoids needing to calculate actual bins
	   until malloc is sure that chunks aren't immediately going to be
	   reused anyway.
	   */

	maxfb = &(av->fastbins[fastbin_index(av->max_fast)]);
	fb = &(av->fastbins[0]);
	do {
	    if ( (p = *fb) != 0) {
		*fb = 0;

		do {
		    check_inuse_chunk(p);
		    nextp = p->fd;

		    /* Slightly streamlined version of consolidation code in free() */
		    size = p->size & ~PREV_INUSE;
		    nextchunk = chunk_at_offset(p, size);
		    nextsize = chunksize(nextchunk);

		    if (!prev_inuse(p)) {
			prevsize = p->prev_size;
			size += prevsize;
			p = chunk_at_offset(p, -((long) prevsize));
			unlink(p, bck, fwd);
		    }
		    
		    unit = lookup_ustate_by_mem((void*)p);
		    if (nextchunk != unit->unit_top) {
			nextinuse = inuse_bit_at_offset(nextchunk, nextsize);
			set_head(nextchunk, nextsize);

			if (!nextinuse) {
			    size += nextsize;
			    unlink(nextchunk, bck, fwd);
			}

			first_unsorted = unsorted_bin->fd;
			unsorted_bin->fd = p;
			first_unsorted->bk = p;

			set_head(p, size | PREV_INUSE);
			p->bk = unsorted_bin;
			p->fd = first_unsorted;
			set_foot(p, size);
		    }

		    else {
			size += nextsize;
			set_head(p, size | PREV_INUSE);
			unit->unit_top = p;
		    }

		} while ( (p = nextp) != 0);

	    }
	} while (fb++ != maxfb);
    }
    else {
    	if (get_abstate()->mstate_list.num == 0) {
    		//initialize abheap state
    		init_linked_list(&(get_abstate()->mstate_list));
		init_linked_list(&(get_abstate()->ustate_list));
		init_linked_list(&(get_abstate()->mmapped_ustate_list));
		get_abstate()->ab_top = (mchunkptr)(CHANNEL_ADDR);
		//allocate channel heap space
		mmap((void *) CHANNEL_ADDR, CHANNEL_SIZE, PROT_READ|PROT_WRITE, 
			MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, -1, 0);	
		touch_mem((void *)CHANNEL_ADDR, CHANNEL_SIZE);
    	}
	malloc_init_state(av);
	check_malloc_state();
    }
}
예제 #6
0
/** create a LinkedList
 */
linked_list* create_linked_list () {

    linked_list *list = (linked_list *)os_malloc(sizeof(linked_list));
    init_linked_list(list);
    return list;
}