Exemple #1
0
void free_list_node(list_t *list, free_list_func func)
{
  node_t *node = list->head;
  node_t *next = NULL;

  list->len = 0;
  list->head = NULL;
  list->tail = NULL;
  if (func != NULL)
    {
      while (node)
        {
          next = NEXT_NODE(node);
          func(node->addr);
          free(node);
          node = next;
        }
    }
  else
    while (node)
      {
        next = NEXT_NODE(node);
        free(node);
        node = next;
      }
}
Exemple #2
0
void* RBPoolAllctor::alloc(void** header,size_t single_size)
{
	if(NULL==NEXT_NODE(*header))
	{
		expand_free_list(single_size,&NEXT_NODE(*header));
#ifdef _DEBUG
		printf("NOTE:Memory pool expanded at %p\n",NEXT_NODE(*header));
#endif
	}
	void *r_header = *header;
	*header = NEXT_NODE(*header);
	return r_header;
}
Exemple #3
0
void RBPoolAllctor::free(void** header,void *p,size_t single_size)
{
	//删掉之后要防止p被非法使用
	NEXT_NODE(p) = *header;
	*header = p;
	
}
Exemple #4
0
void fill_node_data_structures( int tr,
				int type)
 {/* Init fill_node_data_structures */
  Node_p list = NULL;
  Node_p node_ptr = NULL;

  list = node_ptr = get_place_list(tr,type);
  for( ; node_ptr != NULL ; node_ptr = NEXT_NODE(node_ptr))
   {/* Per ogni nodo della lista */
#ifdef SWN
    node_ptr->type = get_node_type(node_ptr,tr);
    node_ptr->fun_card = get_node_cardinality(node_ptr,tr);
    node_ptr->skip = is_independent_from_instance(node_ptr);
#endif
    if(type==INPUT || type==OUTPUT)
     node_ptr->test_arc = is_test_arc(node_ptr,type,tr);
#ifdef SWN
    if(!node_ptr->skip && type == INHIBITOR)
     node_ptr->type = COMPLEX;
#endif
   }/* Per ogni nodo della lista */
#ifdef SWN
  order_nodes(list,type);
#endif
 }/* End fill_node_data_structures */
Exemple #5
0
static int is_test_arc( Node_p my_node_ptr,
			int type,
			int tr)
 {/* Init is_test_arc */
  int ret_value = FALSE;
  int my_pl,other_pl;
  Node_p list,other_ptr;
  Coeff_p my_function,other_function;

  if(type==INPUT)
   list = get_place_list(tr,OUTPUT);
  else
   list = get_place_list(tr,INPUT);
  my_pl= GET_PLACE_INDEX(my_node_ptr);
  my_function = GET_PLACE_FUNCTION(my_node_ptr);
  for(other_ptr = list; other_ptr != NULL; other_ptr=NEXT_NODE(other_ptr))
   {
    other_pl = GET_PLACE_INDEX(other_ptr);
    if(my_pl == other_pl)
     {
      if(GET_ARC_MOLTEPLICITY(my_node_ptr) == GET_ARC_MOLTEPLICITY(other_ptr))
       {
        other_function = GET_PLACE_FUNCTION(other_ptr);
        if(are_the_same_function(my_function,other_function,my_pl,tr))
         {
          ret_value = TRUE;
	  goto ret;
         }
       }
     }
   }
ret:return(ret_value);
 }/* End is_test_arc */
Exemple #6
0
void
main(int argc, char *argv[]) {
	int	i;
	/* char *s; */
	p3dc_LIST *link = p3dc_new_list(P3DC_UNKNOWN, P3DC_LIST_SORTED);
	p3dc_LIST other;
	p3dc_NODE *n;

	p3dc_log_open((argc > 1) ? argv[1] : "list002.log");
	if (link == NULL) {
		fprintf(stderr, "Couldn't allocate a list.\n");
		exit(1);
	}

	for (i = 0; payloads[i] != NULL; i++) {
		n = p3dc_new_node(payloads[i], payloads[i], 0);
		if (n == NULL) {
			fprintf(stderr, "Couldn't allocate node %d.\n", i+1);
			exit(1);
		}
		p3dc_add_node(link, n, P3DC_LIST_BYNAME, n->name);
	}

	for (n = FIRST_NODE(link); n != NULL; n = NEXT_NODE(link)) {
		p3dc_log("Node : %s\n", (char *)(n->data.p));
	}
	p3dc_log("--------\n");
	p3dc_rbprint_list(link);
	p3dc_log("--------\n");

	p3dc_init_list(&other, P3DC_UNKNOWN, P3DC_LIST_LINKED);
	while(1) {
		n = p3dc_get_node(link, P3DC_NODE_FIRST);
		if (n == NULL)
			break;
		p3dc_log("REMOVE -- %s\n", n->name);
		p3dc_remove_node(link, P3DC_NODE_FIRST);
		p3dc_rbprint_list(link);
		p3dc_add_node(&other, n, P3DC_LIST_HEAD);
	}

	for (n = FIRST_NODE(&other); n != NULL; n = NEXT_NODE(&other)) {
		p3dc_log("Node : %s\n", (char *)(n->data.p));
	}

	exit(0);
}
Exemple #7
0
//4/single_size/4
void RBPoolAllctor::expand_free_list(int single_size,void** header,int n /* = g_pool_expand_node_number = 32 */)
{
	
	CHECK(*header == NULL );
	/*     p    
	//XXX4/XXXXXXXXXXXXXXXX.../XXXX
	*/
	void* p = NEW_NODE(single_size);
	*header = (void*)p;
	//*(void**)&p[-4] = p;

	for(int i = 0;i<n-1;++i)
	{
		NEXT_NODE(p) = NEW_NODE(single_size);
		p = NEXT_NODE(p);
	}
	NEXT_NODE(p) = NULL;
}
Exemple #8
0
static int merge(struct w_heap* heap){

	uint32 brk = 0;
	struct w_listnode* it1 = FIRST_NODE(heap->block_list_head);
	struct w_listnode* it2 = it1;

	while(it1->next){

		struct w_block* b1 = LIST_ENTRY(it1, struct w_block, block_node);
		it2 = it1->next;

		while(it2){

			struct w_block* b2 = LIST_ENTRY(it2, struct w_block, block_node);

			/* List is unsorted... figure out block order */

			if(b2->start > b1->start){

				/* block 1 then block 2 */

				if(b1->end + HEAP_OVERHEAD + 1 >= b2->start){
					printf("HEAP MERGE\n");
					b1->end = b2->end;
					list_remove( &heap->block_list_head, it2);
					zero(b2, sizeof(struct w_block));
					brk = 1;
					break;
				}
			}
			else{

				/* block 2 then block 1 */

				if(b2->end + HEAP_OVERHEAD + 1 >= b1->start){
					printf("HEAP MERGE\n");
					b2->end = b1->end;
					list_remove( &heap->block_list_head, it1);
					zero(b1, sizeof(struct w_block));
					brk = 1;
					break;
				}
			}

			it2 = it2->next;
		}

		if(brk){
			heap_dump(heap);
			return 1;
		}

		it1 = NEXT_NODE(it1);
	}

	return 0;
}
Exemple #9
0
void
outlist(p3dc_LIST *list) {
    int i = 0;
    p3dc_NODE *n;

    for (n = FIRST_NODE(list); n != NULL; n = NEXT_NODE(list)) {
        p3dc_log("%d - %s\n", i+1, n->name);
        i++;
    }
}
Exemple #10
0
void foreach_list_node(list_t *list, list_func func, void *args)
{
  node_t *node = list->head;

  while (node)
    {
      func(node->addr, args);
      node = NEXT_NODE(node);
    }
}
Exemple #11
0
/*
 * This function sets *ALL* of the colors in the model to have the 
 * passed in color value.
 * 
 * Returns -1 if the name wasn't found.
 *			-2 if the name wasn't a color.
 *			-3 if the name was ill formed.
 *			-4 texture could not be loaded.
 *		0 on success.
 */
int
p3dc_model_set_all_colors(p3dc_MODEL *m, p3dc_CLR *color) {
	p3dc_NODE *n;
	p3dc_CLR *cc;

	for (n = FIRST_NODE(&(m->parts)); n != NULL; n = NEXT_NODE(&(m->parts))) {
		if (n->data.t == P3DC_CLR) {
			cc = (p3dc_CLR *)(n->data.p);
			*cc = *color;
		}
	}
	return 0;
}
Exemple #12
0
/*
 * This function sets *ALL* of the textures in the model to have the value
 * passed as a texture.
 * 
 * Returns -1 if the name wasn't found.
 *			-2 if the name wasn't a color.
 *			-3 if the name was ill formed.
 *			-4 texture could not be loaded.
 *		0 on success.
 */
int
p3dc_model_set_all_textures(p3dc_MODEL *m, char *texture) {
	p3dc_NODE *n;
	p3dc_TDATA *cc;

	for (n = FIRST_NODE(&(m->parts)); n != NULL; n = NEXT_NODE(&(m->parts))) {
		if (n->data.t == P3DC_TDATA) {
			cc = (p3dc_TDATA *)(n->data.p);
			if (p3dc_load_texture(texture, cc))
				return -1;
		}
	}
	return 0;
}
Exemple #13
0
static void heap_dump(struct w_heap* heap){

	printf("HEAP DUMP:\n");

	struct w_listnode* it = FIRST_NODE(heap->block_list_head);

	uint32 count = 0;

	while(it){

		struct w_block* data = LIST_ENTRY(it, struct w_block, block_node);
		printf("    %p. node: 0x%p, start: 0x%p, end:0x%p\n",count++, it, data->start, data->end);
		it = NEXT_NODE(it);
	}
}
Exemple #14
0
void
p3dc_draw_model_bbox(p3dc_VIEW *vp, p3dc_CLR *cc, int flags, p3dc_MODEL *m) {
	int i;
	p3dc_NODE *t;
	p3dc_LINE *tL;

	if (m->box.head == NULL) {
		for (i = 0; i < 12; i++) {
			if (cc == NULL) cc = &(m->color);	
			tL = p3dc_new_line(cc, &(m->corners[mboxx[i]].v), 
									&(m->corners[mboxy[i]].v));
			p3dc_add_node(&(m->box), p3dc_new_node(tL, NULL, 0), P3DC_LIST_TAIL);
		}
	} else if (cc != NULL) {
		for (t = FIRST_NODE(&(m->box)); t != NULL; t = NEXT_NODE(&(m->box))) {
			tL = (p3dc_LINE *)(t->data.p);
			*(tL->color) = *(cc);
		}
	}
	p3dc_draw_list(vp, &(m->V), flags, &(m->box));
}
Exemple #15
0
PTR
MEreqmem(
	u_i2	tag,
	SIZE_TYPE size,
	bool	zero,
	STATUS	*status)
{
    PTR	block=NULL;
    register ME_NODE *node;		/* the node to return */
    register ME_NODE *start;		/* for searching free list */
    register ME_NODE *this;		/* block to get node from */
    register ME_NODE *frag;		/* fragment block */
    
    ME_NODE 	*tmp;			/* not register for MEadd */
    SIZE_TYPE	nsize;			/* nsize node to obtain */
    SIZE_TYPE	fsize;			/* size of 'this' fragment block */
    SIZE_TYPE	newstuff;		/* size to add to process, or  0 */
    SIZE_TYPE	prev_actual;		/* rescan free list? */
    SIZE_TYPE	alloc_pages;
    CL_ERR_DESC	err_code;

    STATUS	MEstatus = OK;
    
    i_meuser += size;
    
    if (!size)
	MEstatus = ME_NO_ALLOC;
    
    if( !MEsetup )
        MEinitLists();
    
    /*
    **	Try to do the allocation.
    */
    if( MEstatus == OK )
    {
	nsize = SIZE_ROUND( size );
	/*
	** Get memory with malloc().
	*/
	if( MEadvice == ME_USER_ALLOC )
	{
	    if( (node = (ME_NODE *)malloc( nsize )) == NULL )
	    	MEstatus = ME_GONE;
	}
	/*
	** Get block from private free list.
	*/
	else
	{
# ifdef OS_THREADS_USED
	    CS_synch_lock( &MEfreelist_mutex );
# endif /* OS_THREADS_USED */

	    /*
	    **  Look on free list for 1st block big enough
	    **  to hold request.  This linear search can be slow.
	    */
	    start = (ME_NODE *)&MEfreelist;
	    this = MEfreelist.MEfirst;
	    while ( this != NULL && this != start && this->MEsize < nsize )
		this = this->MEnext;
	    
	    if( this == NULL )
	        MEstatus = ME_CORRUPTED;
	    
	    /*
	    ** At this point, we are in one of three states:
	    ** 1)  Corrupted memory; MEstatus != OK
	    ** 2)  this is good node, this != start
	    ** 3)  No good node; this == start;
	    */
	    if ( MEstatus == OK )
	    {
		/*
		** If nothing on free list is big enough
		** get one or more standard blocks from system,
		** take what is needed and add remainder
		** to free list.
		*/
		if (this != start)
		{
		    /* take right off the free list */
		    newstuff = 0;
		}
		else	/* this == start */
		{
		    /*
		     * Expand the free list by calling getpages
		     * newstuff holds the number of pages needed
		     */
		    newstuff = (nsize + ME_MPAGESIZE-1)/ME_MPAGESIZE;
		    /* if first time allocation, get enough for MO overhead */
		    if ( (prev_actual = i_meactual) == (SIZE_TYPE) 0 )
			newstuff += 4;
# ifdef OS_THREADS_USED
	            CS_synch_unlock( &MEfreelist_mutex );
# endif /* OS_THREADS_USED */
		    MEstatus = MEget_pages(ME_SPARSE_MASK, newstuff, NULL, 
			(PTR *)&tmp, &alloc_pages, &err_code);
# ifdef OS_THREADS_USED
	            CS_synch_lock( &MEfreelist_mutex );
# endif /* OS_THREADS_USED */
		    if (MEstatus == OK)
		    {
			/* now we need to find where to put this new memory
			   on the sorted free list - we search in reverse */
			tmp->MEsize = newstuff * ME_MPAGESIZE;
			this = MEfreelist.MElast;
			while (start != this && this != NULL &&
			       this > tmp)
			    this = this->MEprev;
			if (this != start && NEXT_NODE(this) == tmp)
			{
			    this->MEsize += tmp->MEsize;
			}
			else
			{
			    (void)QUinsert( (QUEUE *) tmp, (QUEUE *)this );
			    this = tmp;
			}
			if (this->MEnext != start &&
			    NEXT_NODE(this) == this->MEnext)
			{
			    this->MEsize += this->MEnext->MEsize;
			    (void)QUremove( (QUEUE *) this->MEnext);
			}
			/*
			** While the free list mutex was released, another
			** thread may have freed up a big enough piece of
			** memory for our needs, or may have extended the
			** free list.
			** If that's the case, research the free list;
			** we'll find either a right-sized node or 
			** the new memory we just added to the free list.
			*/
			if ( prev_actual != i_meactual )
			{
			    this = MEfreelist.MEfirst;
			    while ( this != NULL && this != start && this->MEsize < nsize )
				this = this->MEnext;
		
			    if( this == NULL )
				MEstatus = ME_CORRUPTED;
			}
		    }
		    else
			if (MEstatus == ME_OUT_OF_MEM)
			    MEstatus = ME_GONE;
		}

		/*
		** At this point, we can be in two states.
		** 1)  Corrupted memory, MEstatus != OK
		** 2)  'this' is an OK node from the free list.
		*/
		
		if ( MEstatus == OK )
		{
		    node = this;
		    
		    /*
		    ** if this is correct size or would
		    **   leave useless block in chain
		    **	just move block to allocated list
		    ** else
		    **	grab what is needed from 'this'
		    **	  block and then update 'this'
		    */
		    
		    fsize = node->MEsize - nsize;
		    if ( fsize <= sizeof(ME_NODE) )
		    {
			(void)QUremove( (QUEUE *) node );
			
			/* fudge size in node to eat leftover amount. */
			fsize = 0;
			nsize = node->MEsize;
		    }
		    else	/* make fragment block */
		    {
			/*
			** Make a leftover block after the
			** allocated space in node, in 'this'
			*/
			frag = (ME_NODE *)((char *) node + nsize );
			frag->MEsize = fsize;
			frag->MEtag = 0;
			
			/* remove node, add fragment to free list */
			(void)QUremove( (QUEUE *) node );
			MEstatus = MEfadd( frag, FALSE );
			
		    }  /* fragment left over */
		    /* Increment meactual while mutex held */
		    i_meactual += nsize;
		}  /* Got a node */
	    }  /* free list search OK */
# ifdef OS_THREADS_USED
	    CS_synch_unlock( &MEfreelist_mutex );
# endif /* OS_THREADS_USED */
	}  /* ME_USER_ALLOC */
	
	/*
	** At this point we are in one of two states:
	** 1.  Corrupted, MEstatus != OK.
	** 2.  Have a 'node' to use, from freelist or malloc.
	**     The freelist is consistant, but the allocated list is
	**     not setup for the node. "nsize" is the actual size of "node".
	*/
	
	if( MEstatus == OK )
	{
	    /* splice into allocated object queue */
	    if (0 == tag)
	    {
# ifdef OS_THREADS_USED
	    	CS_synch_lock( &MElist_mutex );
# endif /* OS_THREADS_USED */
	    	(void)QUinsert( (QUEUE *) node, (QUEUE *) MElist.MElast );
# ifdef OS_THREADS_USED
		CS_synch_unlock( &MElist_mutex );
# endif /* OS_THREADS_USED */
	    }
	    else
	    {
		IIME_atAddTag(tag, node);
	    }
	    /* Set values in block to be returned */
	    node->MEtag = tag;
	    node->MEsize = nsize;
	    node->MEaskedfor = size;
	    
	    /* Fill in the returned pointer */
	    block = (PTR)((char *)node + sizeof(ME_NODE));
	    
	    if (zero)
		MEfill( (nsize - sizeof(ME_NODE)), 0, block);
	}  /* got node OK */
    }
    if (status != NULL)
	*status = MEstatus;
    if (MEstatus != OK)
	return((PTR)NULL);
    else
	return(block);
}
Exemple #16
0
STATUS
MEfadd(
	ME_NODE	*block,
	i4 releasep)
{
    register ME_NODE *this;
    register ME_NODE *start;
    register ME_NODE *nextblk;	/* 1st address after end of 'block' */
    STATUS  MEstatus;

    MEstatus = OK;

    if ( block == NULL )
    {
	MEstatus = ME_00_PTR;
    }
    else if ( OUT_OF_DATASPACE(block) )
    {
	MEstatus = ME_OUT_OF_RANGE;
    }
    else
    {

	nextblk = NEXT_NODE(block);

	/*
	** The freelist IS sorted.  We might be able to take
	** advantage of this to speed up this linear search.
	** In practice the freelist is usually much
	** smaller than the allocated list, so it might not
	** really matter (daveb).
	*/

	/* adding inside existing freelist */
	start = (ME_NODE *)&MEfreelist;
	this = MEfreelist.MEfirst;

	while ( this != NULL && this != start && this < nextblk )
	    this = this->MEnext;

	if( this == NULL )
	    MEstatus = ME_CORRUPTED;

	/*
	** this->MEprev points to free node before 'block', the one
	** to free.  this points to the block in the free
	** list following 'block' to free.
	*/
	if ( MEstatus == OK )
	{
	    block->MEaskedfor = 0;
	    (void)QUinsert( (QUEUE *) block, (QUEUE *) this->MEprev );

	    /* Coalesce backwards until this is the start of the queue */
	    this = block;
	    while( this->MEprev != start &&
                 this->MEprev != this && NEXT_NODE(this->MEprev) == this )
	    {
		block = this->MEprev;
		block->MEsize += this->MEsize;
		(void)QUremove( (QUEUE *) this );
		this = block;
	    }

	    /* Coalesce forwards until the queue goes back to the start */
	    while( this->MEnext != start && NEXT_NODE(this) == this->MEnext )
	    {
		this->MEsize += this->MEnext->MEsize;
		(void)QUremove( (QUEUE *) this->MEnext );
	    }
	}
    }
			
    return(MEstatus);
}