Ejemplo n.º 1
0
Int RcmClient_Instance_finalize(RcmClient_Object *obj)
{
    SemThread_Handle semH;
    Int status = RcmClient_S_SUCCESS;


    Log_print1(Diags_ENTRY, "--> "FXNN": (obj=0x%x)", (IArg)obj);

    if (NULL != obj->newMail) {
        List_delete(&obj->newMail);
    }

    if (NULL != obj->recipients) {
        List_delete(&obj->recipients);
    }

    if (NULL != obj->queueLock) {
        semH = SemThread_Handle_downCast(obj->queueLock);
        SemThread_delete(&semH);
        obj->queueLock = NULL;
    }

    if (NULL != obj->mbxLock) {
        semH = SemThread_Handle_downCast(obj->mbxLock);
        SemThread_delete(&semH);
        obj->mbxLock = NULL;
    }

    if (MessageQ_INVALIDMESSAGEQ != obj->serverMsgQ) {
        MessageQ_close((MessageQ_QueueId *)(&obj->serverMsgQ));
    }

    if (NULL != obj->errorMsgQue) {
        MessageQ_delete(&obj->errorMsgQue);
    }

    if (NULL != obj->msgQue) {
        MessageQ_delete(&obj->msgQue);
    }

    if (NULL != obj->sync) {
        SyncSemThread_delete((SyncSemThread_Handle *)(&obj->sync));
    }

    /* destruct the instance gate */
    GateThread_destruct(&obj->gate);

    Log_print1(Diags_EXIT, "<-- "FXNN": %d", (IArg)status);
    return(status);
}
Ejemplo n.º 2
0
void Section_delete(Section *s) {
	Node *i;
	for(i = s->entities->head->next; i != s->entities->head; i = i->next)
		Enemy_delete(i->item);
	List_delete(s->entities);
	free(s);
}
Ejemplo n.º 3
0
/**
 * Merged two linked list together
 * 
 * Arguments:
 * head1      A pointer pointing to linked list 1
 * head2      A pointer pointing to linked list 2
 *
 * Returns:
 * A merged sparse array
 *
 * This function will merge two linked lists. Before merging, you 
 * should make a copy of "head1" so that you will still have the 
 * original array while modifying (merging) the second linked list. 
 *
 * Please refer to the README file for detailed instructions on how to
 * merge two lists.
 *
 * This function should not modify either "head1" or "head2". You only
 * need to make a clone of "head1".
 */
Node * List_merge(Node * head1, Node * head2)
{
  Node * head3 = List_copy(head1); //copy of list1
   
  while (head2 != NULL)
    {
      head3 = List_insert_ascend(head3,head2->value,head2->index);
      head2 = head2->next;
    }
  Node * copy = head3; //maintains pointer to top of list while deleting zero values
  Node * copy2 = head3;
  
  while(head3 != NULL)
    {
      if(head3->value == 0)
	{
	  if(head3 == copy)
	    {
	      copy2 = head3->next;
	    }
	  head3 = List_delete(head3,head3->index);
	}
	  
      head3 = head3->next;
    }
  if(head3 == NULL)
    {
      return copy2;    
    }
  else
    {
      return head3;
    }
}
Ejemplo n.º 4
0
static void
_delete_event_connection_fd(int fd)
{
  struct cerebrod_event_connection_data *ecd;
  ListIterator eitr;
#if CEREBRO_DEBUG
  int rv;
#endif /* CEREBRO_DEBUG */

  assert(fd >= 0);

#if CEREBRO_DEBUG
  /* Should be called with lock already set */
  rv = Pthread_mutex_trylock(&event_connections_lock);
  if (rv != EBUSY)
    CEREBROD_EXIT(("mutex not locked: rv=%d", rv));
#endif /* CEREBRO_DEBUG */
  
  eitr = List_iterator_create(event_connections);
  while ((ecd = list_next(eitr)))
    {
      if (ecd->fd == fd)
        {
          List connections;
          if ((connections = Hash_find(event_connections_index, 
                                       ecd->event_name)))
            {
              ListIterator citr;
              int *fdPtr;

              citr = List_iterator_create(connections);
              while ((fdPtr = list_next(citr)))
                {
                  if (*fdPtr == fd) 
                    {
                      List_delete(citr);
                      break;
                    }
                }
              List_iterator_destroy(citr);
            }
          List_delete(eitr);
          break;
        }
    }
  List_iterator_destroy(eitr);
}
Ejemplo n.º 5
0
int main(int argc, char * argv[])
{
  Node * head = NULL; /* must initialize it to NULL */
  head = List_insert(head, 917);
  head = List_insert(head, -504);
  head = List_insert(head, 326);
  List_print(head);
  head = List_delete(head, -504);
  List_print(head);
  head = List_insert(head, 138);
  head = List_insert(head, -64);
  head = List_insert(head, 263);
  List_print(head);

  if (List_search(head, 138) != NULL)
    {
      printf("138 is in the list\n");
    }
  else
    {
      printf("138 is not in the list\n");
    }

  if (List_search(head, 987) != NULL)
    {
      printf("987 is in the list\n");
    }
  else
    {
      printf("987 is not in the list\n");
    }
    

  /* delete the first Node */
  head = List_delete(head, 263);
  List_print(head);

  /* delete the last Node */
  head = List_delete(head, 917);
  List_print(head);

  /* delete all Nodes */
  List_destroy(head);
  return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
void drawWindow(window* cur_window, unsigned char use_current_blit, List* window_list) {

	unsigned int rect_count;
	List* splitrect_list;
	Rect winrect;
	int i;

	//prints("[WYG] Drawing window ");
	//printDecimal(cur_window->handle);
	//pchar('\n');

	if (cur_window->flags & WIN_VISIBLE) {

		cur_window->needs_redraw = 0;

		//Start by drawing this window
		//prints("[WYG] Drawing window frame\n");

		//Create a rectangle for the window to be drawn
		if (use_current_blit) {

			//prints("[WYG] Setting base rectangle using winrect\n");
			//Convert the current blit window to desktop space
			winrect.top = cur_window->y + cur_window->context->top;
			winrect.left = cur_window->x + cur_window->context->left;
			winrect.bottom = cur_window->y + cur_window->context->bottom;
			winrect.right = cur_window->x + cur_window->context->right;
		}
		else {

			//prints("[WYG] Setting base rectangle using whole ctx\n");
			winrect.top = cur_window->y;
			winrect.left = cur_window->x;
			winrect.bottom = cur_window->y + cur_window->context->height - 1;
			winrect.right = cur_window->x + cur_window->context->width - 1;
		}


		if (!(splitrect_list = getOverlappingWindows(List_get_index(window_list, (void*)cur_window) + 1, &winrect))) { //build the rects

			return;
		}

		drawOccluded(cur_window, &winrect, splitrect_list);
		//prints("[WYG] Finished doing occluded draw\n");    

		//getch();

		List_delete(splitrect_list, Rect_deleter);
	}

	//prints("[WYG] Finished drawing window ");
	//printDecimal(cur_window->handle);
	//pchar('\n');

	return;
}
Ejemplo n.º 7
0
Archivo: set.c Proyecto: bjhua/dragon
void Set_delete (T set, Poly_t x)
{
  List_t p;

  Assert_ASSERT(set);

  List_delete (set->list, x, set->equals);
  return;
}
/*!
 *  @brief      Free resources allocated in setup part
 *
 *  @sa         _SysLinkMemUtils_init
 */
static Void
_SysLinkMemUtils_exit (Void)
{
    GT_0trace (curTrace, GT_ENTER, "_SysLinkMemUtils_exit");

    List_delete (&SysLinkMemUtils_module->addrTable);
    OsalSemaphore_delete (&SysLinkMemUtils_module->semList);

    GT_0trace (curTrace, GT_LEAVE, "_SysLinkMemUtils_exit");
}
Ejemplo n.º 9
0
/**
 * Merged two linked list together
 * 
 * Arguments:
 * head1      A pointer pointing to linked list 1
 * head2      A pointer pointing to linked list 2
 *
 * Returns:
 * A merged sparse array
 *
 * This function will merge two linked lists. Before merging, you 
 * should make a copy of "head1" so that you will still have the 
 * original array while modifying (merging) the second linked list. 
 *
 * Please refer to the README file for detailed instructions on how to
 * merge two lists.
 *
 * This function should not modify either "head1" or "head2". You only
 * need to make a clone of "head1".
 */
Node * List_merge(Node * head1, Node * head2)
{
  Node * headcopy = NULL;
  headcopy = List_copy(head1);
  //Node * head1copy = List_copy(head1);//why is it unused?
  while(head2 != NULL)
    {
      if(head2->value != 0)
	{
      /*
      if((headcopy -> index) == (head2 -> index))
	{
	  //Node * headmerged =, should i make a new variable headmerged? 
	  headcopy->value = (headcopy->value) + (head2->value);
	  if ((headcopy -> value) == 0)
	    {
	      List_delete(headcopy, (headcopy->index));
	    }
	}
      else if (headcopy->index != head2->index)
	{
	  if(head2->value != 0)
	    {
	      headcopy = List_insert_ascend(headcopy, head2->value, head2->index);
	    }
	  //headcopy->next = List_create(head2->index, head2->
	  //if((headcopy->value) == 0)
	  //  {
	  //    List_delete(headcopy, headcopy->index);
	  //  }
	}
      
      else if(head2 == NULL)
	{
	  headcopy = List_copy(head1);
	  if(headcopy->value == 0)
	    {
	      List_delete(headcopy, headcopy->index);
	    }
	}
      */
	  headcopy = List_insert_ascend(headcopy, head2->value, head2->index);
	  if(headcopy->value == 0)
	    {
	      headcopy = List_delete(headcopy, headcopy->index);
	    }
	}      
      //head1 = head1 ->next;
      head2 = head2 ->next;
    }

    return headcopy;
}
Ejemplo n.º 10
0
void freePath(List path)
{
	List_head(path);

	while(!List_isEmpty(path))
	{
		Position_delete(List_getCurrent(path));
		List_remove(path);
	}

	List_delete(path);
}
Ejemplo n.º 11
0
void TokenTree_delete(TokenTree* token_tree) {
	
	if(token_tree->type)
	    free((void*)token_tree->type);
	
	if(token_tree->value)
	    free((void*)token_tree->value);
	
	if(token_tree->children)	
	    List_delete(token_tree->children, TokenTree_deleter);
		
	free((void*)token_tree);
}
Ejemplo n.º 12
0
/**
 * Recomputes the distance map.
 * @param map The map.
 * @param cars The cars on the track.
 */
void recomputeDistances(Map map, Car cars[3])
{
	int i;
	List takenPositions = List_new();

	for(i = 0; i < 3; i++)
		if(Car_hasArrived(cars[i]))
			List_insert(takenPositions, Car_getPosition(cars[i]));

	Map_recomputeDistances(map, takenPositions);

	List_empty(takenPositions);
	List_delete(takenPositions);
}
Ejemplo n.º 13
0
Archivo: 0709.c Proyecto: kuos/ECE264
void List_print(Node * front)
{
	if(front == NULL)
	{
		return;
	}
	printf("%d \n", front->data);
	List_print(front->next);

NOde * List_delete(Node * front, int val)
{
  if(front == NULL)
    {
      return NULL;
    }
  if((front->val) == val)
    {
      Node * p = front->next; //p may be NULL
      free(front);
      return p;
    }
  front->next = List_delete(front->next, val);
  return front;
}

void List_destroy

  /*
 List_insert4 (Node ** front, ....)
{
  *front = ...
  */


main
{
	front = List_insert(front, 5);
	front = List_insert(front, 8);
	front = List_insert(front, 9);
	front = List_insert(front, 11);

	front2 = List_insert2(front2, 5);
	front2 = List_insert2(front2, 8);
	front2 = List_insert2(front2, 9);
	front2 = List_insert2(front2, 11);
       
       return EXIT_SUCCESS;
}
Ejemplo n.º 14
0
/**
 * This function deletes the node with the passed "index"
 * 
 * Arguments: 
 * head      A pointer pointing to the first element of the sparse array.
 * index     The index to be deleted
 *
 * Returns: 
 * A sparse array with the node removed (the one with index)
 */
Node * List_delete(Node * head, int index)
{
	if(head == NULL)
	{
		return head;
	}
	if(head->index == index)
	{
		Node * tmp = head;
		head = head->next;
		free(tmp);
		return(head);
	}
	head->next = List_delete(head->next, index);

	return(head);
}
Ejemplo n.º 15
0
Archivo: sleep.c Proyecto: jserv/Taunix
int sleep(unsigned clk_tck)
{
	taskSleepNodes[current_task].prio = clk_tck;
	disable_sched
		_sleepq_processing = 1;
		diffList_insert(&sleepq,current_task);
		_sleepq_processing = 0;
		suspend(current_task);
	enable_sched
	
	if(taskSleepNodes[current_task].prio>0){
		/* Sleep time is not expired */
		disable_sched
			_sleepq_processing = 1;
			sleepq.current = current_task;
			List_delete(&sleepq);
			_sleepq_processing = 0;
		enable_sched
		return SLEEP_NOTEXPIRED;
	}
Ejemplo n.º 16
0
int main()
{
    List_t list = List_new();

    List_append(list, "1");
    List_append(list, "-2");
    List_append(list, "3");
    List_append(list, "-1.2");
    List_append(list, "1.1");

    procSequence(list, accmulateSumInt, accmulateSumDouble);
    procSequence(list, accmulateAbsSumInt, accmulateAbsSumDouble);

    printf("%d\n", accmulateSumInt(0));
    printf("%f\n\n", accmulateSumDouble(0));
    printf("%d\n", accmulateAbsSumInt(0));
    printf("%f", accmulateAbsSumDouble(0));

    List_delete(list);
    return 0;
}
Ejemplo n.º 17
0
/**
 * This function deletes the node with the passed "index"
 * 
 * Arguments: 
 * head      A pointer pointing to the first element of the sparse array.
 * index     The index to be deleted
 *
 * Returns: 
 * A sparse array with the node removed (the one with index)
 */
Node * List_delete(Node * head, int index)
{
	if(head == NULL){
		return head;
	}
	if(head->next == NULL){
		if(head->index == index){
			free(head);
			head = NULL;
		}
		return head;
	}
	if(head->next->index == index){
		printf("\nFound the index\n");
		Node* p = head->next->next;
		free(head->next);
		head->next = p;
		return head;
	}

	head = List_delete(head->next, index);
  return head;
}
Ejemplo n.º 18
0
/**
 * Inserting "value" and "index" into the correct location in the 
 * sparse array "head"
 * 
 * Arguments: 
 * head      A pointer pointing to the first element of the linked list.
 * value     The "value" of the value
 * index     The "value" of the index
 *
 * Returns:
 * A sparse array
 *
 * This function inserts the node ["value", "index"] into the sparse
 * array "head", and ensures that the nodes remain in ascending order
 * by their "index".
 *
 * Before and after the call to this function, "head" must be in
 * ASCENDING order by the "index" of each node.
 */
Node * List_insert_ascend(Node * head, int value, int index)
{
	if(head == NULL)
	{
		return(head = List_create(value,index));
	}
	if(head->index > index)
	{
		Node * p = List_create(value, index);
		p->next = head;
		return p;
	}
	if(head->index == index)
	{
		head->value += value;
		if(head->value == 0)
		{
			head = List_delete(head, head->index);
		}
		return(head);
	}
	head->next = List_insert_ascend(head->next, value, index);
	return(head);
}
Ejemplo n.º 19
0
Post_delete(Post_t self){
    List_deepDelete(self->wantedCarEvents, free);
    List_deepDelete(self->transists, Transist_delete);
    List_delete(self->wantedCars);
    free(self);
}
Ejemplo n.º 20
0
List doPathfinding(Map map, Car cars[3])
{
	Heap openSet = Heap_new(State_compare);
	List closedSet = List_new();
	List finalPath = List_new();
	List neighbors;
	Position neighbor;
	State state, newState;
	Vector newSpeed, acceleration;
	int end = 0, i, j, useBoost, positionTaken, distance;
	float cost;

	LOGINFO("A* doin' da werk!");

	state = State_new(Car_getPosition(cars[0]), Car_getSpeed(cars[0]), Car_getBoosts(cars[0]), map);
	Heap_insert(openSet, state);

	while(!Heap_isEmpty(openSet) && !end)
	{
		state = Heap_extractMin(openSet);

		if(Map_getTile(map, State_getPosition(state)->x, State_getPosition(state)->y) == ARRIVAL)
		{
			end = 1;
			break;
		}

		distance = Map_getDistance(map, State_getPosition(state)->x, State_getPosition(state)->y);
		neighbors = Map_getReachablePositions(map, State_getPosition(state), State_getSpeed(state), State_getBoosts(state));

		List_foreach(neighbors, neighbor, i)
		{
			if(Map_getDistance(map, neighbor->x, neighbor->y) > distance)
			{
				Position_delete(neighbor);
				continue;
			}

			cost = State_getRealCost(state) + 1;
			newSpeed = Position_findOffset(State_getPosition(state), neighbor);
			acceleration = Vector_copy(newSpeed);
			Vector_substract(acceleration, State_getSpeed(state));
			useBoost = 0;
			positionTaken = 0;

			if(Vector_squaredLength(acceleration) > 2)
			{
				useBoost = 1;
			}

			for(j = 1; j < 3; j++)
			{
				if(Position_equal(neighbor, Car_getPosition(cars[j])))
				{
					positionTaken = 1;
				}
			}

			if(!positionTaken)
			{
				newState = State_new(neighbor, newSpeed, State_getBoosts(state) - useBoost, map);
				State_setRealCost(newState, cost);
				State_setParent(newState, state);

				Heap_insert(openSet, newState);
			}

			Vector_delete(newSpeed);
			Vector_delete(acceleration);
			Position_delete(neighbor);
		}

		List_insert(closedSet, state);

		List_empty(neighbors);
		List_delete(neighbors);
	}

	while(state != NULL)
	{
		List_insert(finalPath, Position_copy(State_getPosition(state)));

		state = State_getParent(state);
	}

	List_head(closedSet);
	while(!List_isEmpty(closedSet))
	{
		state = List_getCurrent(closedSet);
		List_remove(closedSet);
		State_delete(state);
	}

	List_delete(closedSet);

	while((state = Heap_extractMin(openSet)) != NULL)
	{
		State_delete(state);
	}

	Heap_delete(openSet);

	LOGINFO("A* is done mate");

	return finalPath;
}
Ejemplo n.º 21
0
void Queue_delete(Queue queue)
{
	assert(queue);
	List_delete(queue);
}
Ejemplo n.º 22
0
List* splitRect(Rect* rdest, Rect* rknife) {
	
	Rect baserect;
	List* outrect;
	Rect* new_rect;
	
	baserect.top = rdest->top;
	baserect.left = rdest->left;
	baserect.bottom = rdest->bottom;
	baserect.right = rdest->right;
	
/*
	cons_prints("Splitting rect (");
	cons_printDecimal(rdest->top);
	cons_prints(", ");
	cons_printDecimal(rdest->left);
	cons_prints(", ");
	cons_printDecimal(rdest->bottom);
	cons_prints(", ");
	cons_printDecimal(rdest->right);
	cons_prints(") with (");   
	cons_printDecimal(rknife->top);
	cons_prints(", ");
	cons_printDecimal(rknife->left);
	cons_prints(", ");
	cons_printDecimal(rknife->bottom);
	cons_prints(", ");
	cons_printDecimal(rknife->right);
	cons_prints(")\n");
*/
	
#ifdef RECT_TEST    
    //printf("splitting (%u, %u, %u, %u)", baserect.top, baserect.left, baserect.bottom, baserect.right);
    //printf("against (%u, %u, %u, %u)\n", rknife.top, rknife.left, rknife.bottom, rknife.right);
#endif //RECT_TEST
		
    //prints("Allocating space for ");
     //printDecimal(sizeof(rect)*rect_count);
    //prints(" rect bytes\n");
	outrect = List_new();
    if(!outrect) {
		
        prints("Couldn't allocate rect space\n");
		return outrect;
	}
	
//    cons_prints("Doing left edge split\n");
	//Split by left edge
	if(rknife->left >= baserect.left && rknife->left <= baserect.right) {
		
		new_rect = Rect_new(baserect.top, baserect.left, baserect.bottom, rknife->left - 1);
		
		if(!new_rect) {
			
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		if(!List_add(outrect, new_rect)) {
			
			free((void*)new_rect);
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		baserect.left = rknife->left;
	}

//    cons_prints("Doing top edge split\n");
	//Split by top edge
	if(rknife->top <= baserect.bottom && rknife->top >= baserect.top) {
		
		new_rect = Rect_new(baserect.top, baserect.left, rknife->top - 1, baserect.right);
		
		if(!new_rect) {
			
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		if(!List_add(outrect, new_rect)) {
			
			free((void*)new_rect);
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		baserect.top = rknife->top;
	}

//    cons_prints("Doing right edge split\n");
	//Split by right edge
	if(rknife->right >= baserect.left && rknife->right <= baserect.right) {
		
		new_rect = Rect_new(baserect.top, rknife->right + 1, baserect.bottom, baserect.right);
		
		if(!new_rect) {
			
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		if(!List_add(outrect, new_rect)) {
			
			free((void*)new_rect);
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		baserect.right = rknife->right;
	}

//    cons_prints("Doing bottom edge split\n");
	//Split by bottom edge
	if(rknife->bottom >= baserect.top && rknife->bottom <= baserect.bottom) {
		
		new_rect = Rect_new(rknife->bottom + 1, baserect.left, baserect.bottom, baserect.right);
		
		if(!new_rect) {
			
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		if(!List_add(outrect, new_rect)) {
			
			free((void*)new_rect);
			List_delete(outrect, Rect_deleter);
			return (List*)0;
		}
		
		baserect.bottom = rknife->bottom;
	}

/*    cons_prints("Result: \n");
	
	List_for_each(outrect, new_rect, Rect*) {
	
	    cons_prints("    ");
		cons_printDecimal(new_rect->top);
		cons_prints(", ");
		cons_printDecimal(new_rect->left);
		cons_prints(", ");
		cons_printDecimal(new_rect->bottom);
		cons_prints(", ");
		cons_printDecimal(new_rect->right);
		cons_prints("\n");
	}
	
	scans(10, inbuf);
*/
	return outrect;	
}
Ejemplo n.º 23
0
void drawOccluded(Window* win, Rect* baserect, List* splitrect_list) {

	if (!splitrect_list)
		return;

	int split_count = 0;
	int total_count = 1;
	int working_total = 0;
	List* out_rects;
	Rect* working_rects = (Rect*)0;
	int i, j, k;
	Rect *new_rect, *rect, *split_rect, *out_rect;

	//If there's nothing occluding us, just render the bitmap and get out of here
	if (!splitrect_list->count) {

		drawBmpRect(win, baserect);
		return;
	}

	out_rects = List_new();

	if (!out_rects) {

		return;
	}

	rect = Rect_new(baserect->top, baserect->left, baserect->bottom, baserect->right);

	if (!rect) {

		List_delete(out_rects, Rect_deleter);
		return;
	}

	if (!List_add(out_rects, (void*)rect)) {

		free((void*)rect);
		List_delete(out_rects, Rect_deleter);
		return;
	}

	//For each splitting rect, split each rect in out_rects, delete the rectangle that was split, and add the resultant split rectangles
	List_for_each(splitrect_list, split_rect, Rect*) {

		List_for_each(out_rects, out_rect, Rect*) {

			if ((split_rect->left <= out_rect->right &&
				split_rect->right >= out_rect->left &&
				split_rect->top <= out_rect->bottom &&
				split_rect->bottom >= out_rect->top)) {

				List* clip_list = splitRect(out_rect, split_rect);

				if (!clip_list) {

					List_delete(out_rects, Rect_deleter);
					return;
				}

				//If nothing was returned, we actually want to clip a rectangle in its entirety
				if (!clip_list->count) {

					List_remove(out_rects, (void*)out_rect, Rect_deleter);

					//If we deleted the last output rectangle, we are completely 
					//occluded and can return early
					if (out_rects->count == 0) {

						List_delete(clip_list, Rect_deleter);
						List_delete(out_rects, Rect_deleter);
						return;
					}

					//Otherwise, go back to the top of the loop and test the next out_rect
					continue;
				}

				//Replace the rectangle that got split with the first result rectangle 
				rect = (Rect*)List_get_at(clip_list, 0);
				out_rect->top = rect->top;
				out_rect->left = rect->left;
				out_rect->bottom = rect->bottom;
				out_rect->right = rect->right;

				//Append the rest of the result rectangles to the output collection
				List_for_each_skip(clip_list, rect, Rect*, 1) {

					new_rect = Rect_new(rect->top, rect->left, rect->bottom, rect->right);

					if (!new_rect) {
						List_delete(clip_list, Rect_deleter);
						List_delete(out_rects, Rect_deleter);
						return;
					}

					if (!List_add(out_rects, (void*)new_rect)){

						free((void*)new_rect);
						List_delete(clip_list, Rect_deleter);
						List_delete(out_rects, Rect_deleter);
						return;
					}
				}

				//Free the space that was used for the split 
				List_delete(clip_list, Rect_deleter);

				//Restart the list 
				List_rewind(out_rects);
			}
		}
Ejemplo n.º 24
0
Void ListTest(Void)
{
    List_Params listParams;
    List_Handle listHandle;
    List_Elem *elem;
    ListNode *node;
    UInt32 i, value;
    Bool failed = FALSE;

    IGateProvider_Handle gateHandle;

    List_Params_init(&listParams);

    gateHandle = (IGateProvider_Handle) GateMutex_create();
    if(gateHandle == NULL) {
        Osal_printf("ListTest: GateMutex_create failed.\n");
        goto exit;
    }

    listParams.gateHandle = gateHandle;
    listHandle = List_create(&listParams);
    if(listHandle == NULL) {
        Osal_printf("ListTest: List_create failed.\n");
        goto gateExit;
    }

    node = Memory_alloc(NULL, LIST_SIZE * sizeof(ListNode), 0);
    if(node == NULL) {
        Osal_printf("ListTest: Memory_alloc failed.\n");
        goto listExit;
    }

    // Put some nodes into the list
    for(i = 0; i < LIST_SIZE; i++) {
        node[i].value = i;
        List_put(listHandle, (List_Elem *)&node[i]);
    }

    // Traverse the list
    for(i = 0, elem = List_next(listHandle, NULL);
        elem != NULL && !failed;
        i++, elem = List_next(listHandle, elem)) {
        value = ((ListNode *)elem)->value;

        // Check against expected value
        if(value != i) {
            Osal_printf("ListTest: data mismatch, expected "
                "0x%x, actual 0x%x\n", i, i, value);
            failed = TRUE;
        }
    }

    // Remove nodes
    for(i = 0; i < LIST_SIZE && !List_empty(listHandle); i++) {
        // Get first element and put it back to test List_get and List_putHead
        elem = List_get(listHandle);
        List_putHead(listHandle, elem);

        // Now remove it permanently to test List_remove
        if(elem != NULL) {
            List_remove(listHandle, elem);
        }
    }
    // Did we remove the expected number of nodes?
    if(i != LIST_SIZE)
    {
        Osal_printf("ListTest: removed %d node(s), expected %d\n",
            i, LIST_SIZE);
        failed = TRUE;
    }

    if(!List_empty(listHandle))
    {
        Osal_printf("ListTest: list not empty!\n");
        failed = TRUE;
    }

    if(failed)
        Osal_printf("ListTest: FAILED!\n");
    else
        Osal_printf("ListTest: PASSED!\n");

listExit:
    List_delete(&listHandle);
gateExit:
    GateMutex_delete((GateMutex_Handle *)&gateHandle);
exit:
    return;
}
Ejemplo n.º 25
0
void *
cerebrod_event_queue_monitor(void *arg)
{
  List temp_event_queue;

  _event_queue_monitor_initialize();

  /* Don't bother if there isn't an event queue (i.e. no event modules) */
  if (!event_queue)
    return NULL;

  temp_event_queue = List_create((ListDelF)cerebrod_event_to_send_destroy);

  /* 
   * achu: The listener and thus event update initialization is
   * started after this thread is started.  So the and event_index may
   * not be set up the first time this loop is reached.  
   *
   * However, it must be set after the condition is signaled, b/c the
   * listener (and thus event update code) and event node timeout
   * thread begin after the listener is setup.
   *
   * Thus, we put the event_queue assert inside the loop.
   */
  for (;;)
    {
      struct cerebrod_event_to_send *ets;
      ListIterator eitr;
      ListIterator titr;

      Pthread_mutex_lock(&event_queue_lock);
      assert(event_queue);
      while (list_count(event_queue) == 0)
        Pthread_cond_wait(&event_queue_cond, &event_queue_lock);

      /* Debug dumping in the below loop can race with the debug
       * dumping from the listener, b/c of racing on the
       * event_queue_lock.  To avoid this race, we copy the data off
       * the event_queue, so the event_queue_lock can be freed up.
       */

      eitr = List_iterator_create(event_queue);
      while ((ets = list_next(eitr)))
        {
          List_append(temp_event_queue, ets);
          List_remove(eitr);
        }
      List_iterator_destroy(eitr);
      Pthread_mutex_unlock(&event_queue_lock);

      titr = List_iterator_create(temp_event_queue);
      while ((ets = list_next(titr)))
        {
          List connections;

          _event_dump(ets->event);
          
          Pthread_mutex_lock(&event_connections_lock);
          if ((connections = Hash_find(event_connections_index, ets->event_name)))
            {
              char buf[CEREBRO_MAX_PACKET_LEN];
              int elen;

              if ((elen = _event_marshall(ets->event, 
                                          buf, 
                                          CEREBRO_MAX_PACKET_LEN)) > 0)
                {
                  ListIterator citr;
                  int *fd;

                  citr = List_iterator_create(connections);
                  while ((fd = list_next(citr)))
                    {
                      if (fd_write_n(*fd, buf, elen) < 0)
                        {
                          CEREBROD_DBG(("fd_write_n: %s", strerror(errno)));
                          if (errno == EPIPE
                              || errno == EINVAL
                              || errno == EBADF
                              || errno == ENODEV
                              || errno == ENETDOWN
                              || errno == ENETUNREACH)
                            {
                              if (conf.event_server_debug)
                                {
                                  Pthread_mutex_lock(&debug_output_mutex);
                                  fprintf(stderr, "**************************************\n");
                                  fprintf(stderr, "* Event Connection Died: errno = %d\n", errno);
                                  fprintf(stderr, "**************************************\n");
                                  Pthread_mutex_unlock(&debug_output_mutex);
                                }
                              List_delete(citr);
                            }
                          continue;
                        }
                    }
                  List_iterator_destroy(citr);
                }
            }
          Pthread_mutex_unlock(&event_connections_lock);

          List_delete(titr);
        }
      
      List_iterator_destroy(titr);
    }

  List_destroy(temp_event_queue);

  return NULL;			/* NOT REACHED */
}
Ejemplo n.º 26
0
void Object_delete(Object *object) {
    	    
    List_delete(object->triangles, Triangle_deleter);
    free((void*)object);
}
Ejemplo n.º 27
0
void StringList_delete(StringList *stringList)
{
  assert(stringList != NULL);

  List_delete(stringList,(ListNodeFreeFunction)freeStringNode,NULL);
}
void SentenceList_delete(SentenceList_t list){
    List_delete(list);
}
Ejemplo n.º 29
0
void Room_killEntity(Room self, Entity entity)
{
    List_delete(self->entities, Room_getEntityIdx(self, entity), entity->kill);
}
Ejemplo n.º 30
0
/**
 * Inserting "value" and "index" into the correct location in the 
 * sparse array "head"
 * 
 * Arguments: 
 * head      A pointer pointing to the first element of the linked list.
 * value     The "value" of the value
 * index     The "value" of the index
 *
 * Returns:
 * A sparse array
 *
 * This function inserts the node ["value", "index"] into the sparse
 * array "head", and ensures that the nodes remain in ascending order
 * by their "index".
 *
 * Before and after the call to this function, "head" must be in
 * ASCENDING order by the "index" of each node.
 */
Node * List_insert_ascend(Node * head, int value, int index) /* Should this be adding up values if index is same as some index in list ? */
{
  Node * p = List_create(value, index);
  Node * h = head;

  if (h == NULL)
    {
      return p;
    }

  if ((p -> index) < (h -> index)) /* Check for first position */
    {
      p -> next = h;
      return p;
    }

  // Adding ability to deal with like indices

  if ((p -> index) == (h -> index))
    {
      h -> value += p -> value; 
      if (h -> value == 0)
        {
          head = List_delete(head, h -> index);
	  free(p);
          return head;
        }
      else
        {
          free(p);
	  return head;
        }
    }

  // *************************************

  while ((h -> next) != NULL)
    {
      if ((p -> index) < ((h -> next) -> index))
        {
          p -> next = h -> next;
	  h -> next = p;
	  return head;
        } 
      // New code here
      if ((p -> index) == ((h -> next) -> index))
        {
	  (h -> next) -> value += p -> value;
          if ((h -> next) -> value == 0)
	    {
	      head = List_delete(head, (h -> next) -> index);
	      free(p);
	      return head;
	    }
	  else
	    {
  	      free(p);
	      return head;
	    }
        }
      // ******************************************
      h = h -> next;
    }

  /* We know 100%, that h -> next == NULL, see while loop */
  p -> next = h -> next;
  h -> next = p;
  return head;
}