예제 #1
0
파일: main.c 프로젝트: zydeon/mosal
void remove_tables(){
	/**
	 * Free all DP tables.
	 */

	int i, j;

	/* Q */
	for( i = 0; i < M+1; ++i )
		for( j = 0; j < N+1; ++j )
			remove_list( Q[i][j] );

	for( i = 0; i < M+1; ++i )
		free(Q[i]);
	free(Q);

	/* T */
	for( i = 0; i < M+1; ++i )
		for( j = 1; j < N+1; ++j )
			remove_list( T[i][j] );
	
	for( i = 0; i < M+1; ++i )
		free(T[i]);
	free(T);		

	/* S */
	for( i = 1; i < M+1; ++i )
		for( j = 0; j < N+1; ++j )
			remove_list( S[i][j] );
	
	for( i = 0; i < M+1; ++i )
		free(S[i]);
	free(S);	

}
예제 #2
0
파일: mm.c 프로젝트: nik-6947/malloc
/*
 * Requires:
 *   "bp" is the address of a newly freed block.
 *
 * Effects:
 *   Perform boundary tag coalescing. 
 */
static void *
coalesce(void *bp)
{
  size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
  size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))) || PREV_BLKP(bp) == bp;
  size_t size = GET_SIZE(HDRP(bp));
  
  /* Next block is free */   
  if (prev_alloc && !next_alloc) {                  
    size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
    remove_list(NEXT_BLKP(bp));
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /* Previous block is free */  
  else if (!prev_alloc && next_alloc) {               
    size += GET_SIZE(HDRP(PREV_BLKP(bp)));
    bp = PREV_BLKP(bp);
    remove_list(bp);
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /* Both blocks are free */ 
  else if (!prev_alloc && !next_alloc) {                
    size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(HDRP(NEXT_BLKP(bp)));
    remove_list(PREV_BLKP(bp));
    remove_list(NEXT_BLKP(bp));
    bp = PREV_BLKP(bp);
    PUT(HDRP(bp), PACK(size, 0));
    PUT(FTRP(bp), PACK(size, 0));
  }
  /*insert bp,free block into free list*/
  insert_list(bp);
  return bp;
}
예제 #3
0
파일: msg.c 프로젝트: herumi/kernel
void sys_close (post_id_t post){

  if(get_current_tid() == Posts[post].owner){
    Posts[post].owner = 0;
    remove_list(Posts[post].received);
  }
}
예제 #4
0
/*!
  \brief Saves the default loggable choices
  \param widget is unused
  \returns FALSE
 */
G_MODULE_EXPORT gboolean save_default_choices(GtkWidget *widget)
{
	GtkWidget *tmpwidget = NULL;
	GList * list = NULL;
	GList * defaults = NULL;
	gconstpointer *object = NULL;
	gchar *name = NULL;
	gint i = 0;

	defaults = get_list("logviewer_defaults");
	if (defaults)
	{
		g_list_foreach(defaults,(GFunc)g_free,NULL);
		g_list_free(defaults);
		defaults = NULL;
		remove_list("logviewer_defaults");
	}
	list = get_list("viewables");
	for (i=0;i<g_list_length(list);i++)
	{
		tmpwidget = g_list_nth_data(list,i);
		object = OBJ_GET(tmpwidget,"object");
		if ((GBOOLEAN)DATA_GET(object,"being_viewed"))
		{
			if (DATA_GET(global_data,"playback_mode"))
				name = DATA_GET(object,"lview_name");
			else
				name = DATA_GET(object,"dlog_gui_name");

			defaults = g_list_append(defaults,g_strdup(name));
		}
	}
	store_list("logviewer_defaults",defaults);
	return FALSE;
}
예제 #5
0
파일: hashtable.c 프로젝트: gideonla/w2014
bool remove_ht(SerialHashTable_t * htable,int key){
	resizeIfNecessary_ht(htable,key);
    if( htable->table[key & htable->mask] != NULL )
      return remove_list(htable->table[key & htable->mask],key);
    else
      return false;

}
예제 #6
0
파일: mm.c 프로젝트: nik-6947/malloc
/*
 * Requires:
 *   "ptr" is either the address of an allocated block or NULL.
 *
 * Effects:
 *   Reallocates the block "ptr" to a block with at least "size" bytes of
 *   payload, unless "size" is zero. If "size" is zero, frees the block "ptr" and returns NULL.  
 *   If the block "ptr" is already a block with at least "size" bytes of payload, then "ptr" may optionally be returned.
 *   If the requested size is greater than the present block size,and next block is free then we can just 
 *	 combine present block and next block to resize them so as to satisfy the requested realloc size. 
 *   If nothing can be done then a new block is allocated (using malloc) and the contents of the old block
 *   "ptr" are copied to that new block.  Returns the address of this new
 *   block if the allocation was successful and NULL otherwise.
 */
void *
mm_realloc(void *ptr, size_t size)
{
	 size_t presize;
     size_t reqsize; 

  /* If size == 0 then this is just free, and we return NULL. */
  if((int)size == 0){ 
    mm_free(ptr); 
    return NULL; 
  } 

  /*any spurious requests*/
  else if((int)size < 0) 
    return NULL; 

/* If oldptr is NULL, then this is just malloc. */
  else if (ptr == NULL)
  {
  	/* code */
  	return mm_malloc(size);
  }
  else if(size > 0){ 

       presize = GET_SIZE(HDRP(ptr)); 
       reqsize = size + 2 * WSIZE;
      
		if (presize >= reqsize)
		{
			/* code */
			return ptr;
		}
      
      /*When the requested size is greater than the present allocated size of that pointer */ 
      else { 
          size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(ptr))); 
          size_t tempSize;

          /* when the next block is free and the combined size of the the next block and current block is more than the required
          size then just join the two blocks*/ 
          if(!next_alloc && ((tempSize = presize + GET_SIZE(HDRP(NEXT_BLKP(ptr))))) >= reqsize){ 
            remove_list(NEXT_BLKP(ptr)); 
            PUT(HDRP(ptr), PACK(tempSize, 1)); 
            PUT(FTRP(ptr), PACK(tempSize, 1)); 
            return ptr; 
          }
          else {  
            void *tempptr = mm_malloc(reqsize);  
            place(tempptr, reqsize);
            memcpy(tempptr, ptr, reqsize); 
            mm_free(ptr); 
            return tempptr; 
          } 
      }
  }else 
    return NULL;
} 
예제 #7
0
파일: mm.c 프로젝트: nik-6947/malloc
/* 
 * Requires:
 *   "bp" is the address of a free block that is at least "asize" bytes.
 * Effects:
 *   Place a block of "asize" bytes at the start of the free block "bp" and
 *   split that block if the remainder would be at least the minimum block
 *   size. 
 */
static void 
place(void *bp, size_t asize)
{
  size_t tempSize = GET_SIZE(HDRP(bp));

  if ((tempSize - asize) >= 4 * WSIZE) {			/*if there is a extra space, split the larger block and then use it*/
    PUT(HDRP(bp), PACK(asize, 1));
    PUT(FTRP(bp), PACK(asize, 1));
    remove_list(bp);
    bp = NEXT_BLKP(bp);
    PUT(HDRP(bp), PACK(tempSize-asize, 0));
    PUT(FTRP(bp), PACK(tempSize-asize, 0));
    insert_list(bp);
   // coalesce(bp);
  }
  else {
    PUT(HDRP(bp), PACK(tempSize, 1));
    PUT(FTRP(bp), PACK(tempSize, 1));
    remove_list(bp);
  }
}
예제 #8
0
void remove_hash(uint32_t block)
{
	int i;

	i = hash_block(block);
	
	//pthread_mutex_lock(&hash_mutex);
	remove_list(&(ht[i].list), block);
	if(ht[i].list == NULL)
		ht[i].active = ht[i].active & (unsigned char)0x00; /* Uuuu....deep magic...I wonder what this does... */
	//pthread_mutex_unlock(&hash_mutex);
}
예제 #9
0
파일: map_data.c 프로젝트: SeHoonYang/SE
void rem_user_from_map(int mid, int uid)
{
  struct list_elem* e;
  for(e = list_begin(&map_data_array[mid].user_data); e != list_end(&map_data_array[mid].user_data); e = list_next(e))
  {
    if(*(int *)(e->conts) == uid)
    {
      free(e->conts);
      remove_list(&map_data_array[mid].user_data, e->conts);
      return;
    }
  }
}
예제 #10
0
void main()
{
	puts("linked list start");

	linked_list *node;

	node = NULL;

	add_list(&node, "list1");
	add_list(&node, "list2");
	add_list(&node, "list3");

	remove_list(&node);

	print_list(node);
}
예제 #11
0
void confirm_seat(char* buf, int bufsize, int seat_id, int customer_id, int customer_priority)
{
    seat_t* curr = seat_header;
    while(curr != NULL)
    {
        if(curr->id == seat_id)
        {
            pthread_mutex_lock(&curr->lock);

            if(curr->state == PENDING && curr->customer_id == customer_id )
            {
                snprintf(buf, bufsize, "Seat confirmed: %d %c\n\n",
                        curr->id, seat_state_to_char(curr->state));
                curr->state = OCCUPIED;

                //remove_list from standby list_se
                standby_node* st = standby_list;

                while(st->next){
                    sem_wait(&list_sem);
                    if(st->next->id == seat_id){
                        remove_list(st);
                    }
                    sem_post(&list_sem);
                    st = st->next;
                }

            }
            else if(curr->customer_id != customer_id )
            {
                snprintf(buf, bufsize, "Permission denied - seat held by another user\n\n");
            }
            else if(curr->state != PENDING)
            {
                snprintf(buf, bufsize, "No pending request\n\n");
            }

            pthread_mutex_unlock(&curr->lock);

            return;
        }
        curr = curr->next;
    }
    snprintf(buf, bufsize, "Requested seat not found\n\n");
    
    return;
}
예제 #12
0
파일: list0.c 프로젝트: DmytroLebediev/cs50
int main(int argc, char **argv)
{
    if (argc != 2)
    {
        printf("usage: ./list0 <valid file path>\n");
        return 1;
    }
    if (argv[1] == NULL)
    {
        printf("can not process empty file name\n");
        return 2;
    }

    FILE* file = fopen(argv[1], "r");
    if (file == NULL)
    {
        printf("can not open file %s\n", argv[1]);
        return 3;
    }

    int_list* list = read_numbers(file, NULL);
    fclose(file);

    print_list(list);

    printf("what number are you looking for?\n");
    int number = get_int();

    if (index_of(list, number) == -1)
    {
        printf("404 Not Found!\n");
    }
    else
    {
        printf("List contains %d\n", number);
    }

    remove_list(list);

    return 0;
}
예제 #13
0
void	resolution(t_lst *lsta, t_lst *lstb)
{
	if (verif_rotate_a(lsta) == 1)
	{
		rev_rotate(&lsta);
		apply_opt_v(lsta, lstb);
	}
	if (verif_rotate_a(lsta) == 2)
	{
		rotate(&lsta);
		apply_opt_v(lsta, lstb);
	}
	while (is_sort(lsta, lstb))
	{
		while (a_is_sort(lsta) == 1)
			resolve_a(&lsta, &lstb);
		while (is_sort(lsta, lstb) == 2)
			resolve_b(&lsta, &lstb);
		remove_list(&lsta, &lstb);
	}
	ft_print_color(MAGENTA, "\n\nEnd:", 1);
	print_lst(lsta, lstb);
}
예제 #14
0
void check_list(char* buf, int bufsize, int seat_id, int customer_id){
    
    standby_node* st  = standby_list;  

    while(st->next != NULL){
        sem_wait(&list_sem);
        if(st->next->id == seat_id){
            
            //find the requested sea
            change_seat_list(buf, bufsize, seat_id, customer_id);
            remove_list(st);
            //snprintf(buf, bufsize, "updated seat\n\n");

            return;
        }
        sem_post(&list_sem);
        st = st->next;
    }
    //snprintf(buf, bufsize, "no request match\n\n");

    return;
    
}
예제 #15
0
int main (void){
	int i;
	region temp_region;
	list* test  = create_list();
	list* lptr;

	for(i = 0; i < 10; i++){
		temp_region.region_start = i;
		temp_region.region_stop = i+1;	
		push_region(temp_region, test);
	}
	
	temp_region.region_start = 100;
	temp_region.region_stop = 200;
	append_region(temp_region, test);

	//printf("top->%d %d\n", top_region(test).region_start, top_region(test).region_stop);

	walknprint(test, lptr);

 	printf("list is %d long\n", get_length(test));
	
	//printf("found important: 0x%x %d %d\n", lptr, lptr->the_region.region_start, lptr->the_region.region_stop);

	temp_region = tail_pull(test);
	printf("pulled tail: %d %d\n", temp_region.region_start, temp_region.region_stop);
	

	for(i = 0; i < 10; i++){
		temp_region = pop_region(test);
		printf("pop->%d %d\n", temp_region.region_start, temp_region.region_stop);
	}

	remove_list(test);

	return(0);
}
예제 #16
0
int main(int argc, char const *argv[]) {
	struct LinkList* list = create_list();

	append_list(list, 1);
	insert_list(list, 2, 0);
	push_list(list, 10);
	show_list(list);

	int data = pop_list(list);
	printf("pop data is %d\n", data);
	show_list(list);

	push_list(list, 10);
	push_list(list, 11);
	push_list(list, 10);
	push_list(list, 11);
	show_list(list);

	remove_list(list, 1);
	show_list(list);

	remove_data_list(list, 10);
	show_list(list);

	remove_all_data_list(list, 11);
	show_list(list);

	struct Node* node = get_node_list(list, 0);
	printf("data is %d\n", node->data);

	int index = search_list(list, 2);
	printf("index is %d\n", index);

	destory_list(list);
	return 0;
}
예제 #17
0
int main(int argc, const char * argv[])
{

    FILE *fp = NULL;  //For writing the lists.
    FILE *fp1 = NULL; //For writing the list ids.

    int i=0;
    int count=0;
    int index=0;
    int data=0;
    int list_number=0;
    int count_lists=0;
    long list_length=0;
    long list_id_length=0;
    int list_count=0;
    int result=0;
    int arr_list_id[MAX_LISTS];
    char ch;
    node *head=NULL;
    node *head_mem[MAX_LISTS];

    count_lists=0;
   
    if (argc == 1)
    {
        printf("\n Enter at least one argument \n");
        exit(1);
    }
    
    //line_count = number_of_lines_count_in_file("list.out");
    list_number = atoi(argv[2]);
    list_id_length = get_list_id(&fp1, arr_list_id, &list_count);
    
    
    if (strcmp(argv[1], "create") == 0)
    {
        printf ("\n creating a list \n");
        if (!check_line_number(arr_list_id, list_number, list_id_length))
        {
            data = atoi(argv[3]);
            head = create(list_number, data);
            write_to_file(head, &fp);
            write_list_number_file(&fp1, list_number, list_length);
        }

    }
    else if (strcmp(argv[1], "insert") == 0)
    {
        printf ("\n inserting into list \n");
    
        // Check to see if the  list_number is in arr_list_id
        if (!check_line_number(arr_list_id, list_number, list_count))
        {
            while (1)
            {
                printf("\n List doesn't exist. \n Do you want to create it? \n Type 'y' for YES or 'n' for NO \n");
                scanf("%c",&ch);
                
                if (ch == 'y' || ch == 'Y')
                {
                    printf("\n Creating... \n");
                    data = atoi(argv[3]);
                    head = create(list_number, data);
                    write_list_number_file(&fp1, list_number, list_length);
                    
                    if (argc == 4)
                        write_to_file(head, &fp);
                    else
                    {
                        for (i = 4; i < argc; i++ )
                        {
                            data = atoi(argv[i]);
                            insert(&head, list_number, data);
                            
                        }
                        write_to_file(head, &fp);
                    }
                    break;
                }
                else if (ch == 'n' || ch == 'Y')
                {
                    exit(1);
                }
                else
                {
                    printf ("\n Type 'y' for YES or 'n' for NO \n");
                }
            }
            
        }
        else
        {
            count = load_in_memory(&fp, head_mem);
            if (count == 1)
            {
                index = 0;
            }
            else if (count == 0)
            {
                while (1)
                {
                    printf("\n List doesn't exist. \n Do you want to create it? \n Type 'y' for YES or 'n' for NO \n");
                    scanf("%c",&ch);
                    
                    if (ch == 'y' || ch == 'Y')
                    {
                        printf("\n Creating... \n");
                        data = atoi(argv[3]);
                        head = create(list_number, data);
                        write_list_number_file(&fp1, list_number, list_length);
                        
                        if (argc == 4)
                            write_to_file(head, &fp);
                        else
                        {
                            for (i = 4; i < argc; i++ )
                            {
                                data = atoi(argv[i]);
                                insert(&head, list_number, data);
                                
                            }
                            write_to_file(head, &fp);
                        }
                        break;
                    }
                    else if (ch == 'n' || ch == 'n')
                    {
                        exit(1);
                    }
                    else
                    {
                        printf ("\n Type 'y' for YES or 'n' for NO \n");
                    }
                }
            }
            for (i = 0; i < count; i++)
            {
                if (head_mem[i]->list_id == list_number)
                {
                    index = i;
                    break;
                }
                
            }
        
            for (i = 3; i < argc; i++)
            {
                head = head_mem[index];
                data = atoi(argv[i]);
                insert(&head, list_number, data);
                head_mem[index] = head;
            }

            rewrite_to_file(head_mem, &fp, list_number, count);
        }
        
    }
    else if (strcmp(argv[1], "display") == 0)
    {
        printf ("\n displaying a list \n");
        if (check_line_number(arr_list_id, list_number, list_count))
        {
            head = read_from_file_and_construct_list(&fp, list_number, &list_length);
            display(head);
        }
        else
        {
            printf("\n List does not exist \n");
        }
    }
    else if (strcmp(argv[1], "remove_node") == 0)
    {
        if (check_line_number(arr_list_id, list_number, list_count))
        {
            printf ("\n Removing a node \n");
            data = atoi(argv[3]);
            count = load_in_memory(&fp, head_mem);
            if (count == 1)
            {
                index = 0;
            }
            else
            {
                for (i = 0; i < count; i++)
                {
                    if (head_mem[i]->list_id == list_number)
                    {
                        index = i;
                        break;
                    }
                }
                
            }
            if (check_node_present(head_mem[index], data))
            {
                
                for (i = 3; i < argc; i++)
                {
                    head = head_mem[index];
                    data = atoi(argv[i]);
                    result = remove_node(&head, data);
                    head_mem[index] = head;
                
                }
                if (head_mem[index] == NULL)
                {
                    remove_from_listid_file(&fp1, list_number);
                }
                
                rewrite_to_file(head_mem, &fp, list_number, count);
            }
            else
            {
                printf ("\n Node not found \n");
            }
        
        }
        else
        {
            printf("\n List does not exist\n");
        }
    
    }
    else if (strcmp(argv[1], "remove_list") == 0)
    {
        printf ("\n Removing a list \n");
        if (check_line_number(arr_list_id, list_number, list_count))
        {
            count = load_in_memory(&fp, head_mem);
            if (count == 1)
            {
                index = 0;
            }
            else if (count == 0)
            {
                printf("file is empty");
                exit(1);
            }
            else
            {
                for (i = 0; i < count; i++)
                {
                    if (head_mem[i]->list_id == list_number)
                    {
                        index = i;
                        break;
                    }
                    
                }
            }
            
            remove_list(head_mem[index]);
            remove_from_listid_file(&fp1, list_number);
            head_mem[index] = NULL;
            rewrite_to_file(head_mem, &fp, list_number, count);
        }
        else
        {
            printf("\n List does not exist\n");
        }
        
    }
    else
    {
        printf ("\n Invalid option \n");
    }
    
    return 0;
}
예제 #18
0
void destroy_projectile(projectile *p)
{
	remove_list(PROJECTILES, p);
}
예제 #19
0
string solve(string command,user*& cur_user)
{
  vector <string> commands;
  string x;

  string sol;
  commands=parse(command);
  x=commands[0];
  if(x=="exit" || x=="disconnect")
    return x;
  if(x=="signup")
    sol=signup(cur_user,commands);
  if(x=="signin")
    sol=signin(cur_user,commands);
  if(x=="signout" && commands.size()==1)
    {
      cur_user=NULL;
      return "signing out completed.\n";
    }
  if(x=="show_boards")
    sol=show_boards(cur_user);
  if(x=="enter_board")
    sol=enter_board(cur_user,commands);
  if(x=="add_user")
    sol=add_user(cur_user,commands);
  if(x=="remove_user_from_board")
    sol=remove_user_from_board(cur_user,commands);
  if(x=="show_lists" && commands.size()==1)
    sol=show_lists(cur_user);
  if(x=="show_cards")
    sol=show_cards(cur_user,commands);
  if(x=="show_card")
    sol=show_card(cur_user,commands);
  if(x=="create_board")
    sol=create_board(cur_user,commands);
  if(x=="remove_board")
    sol=remove_board(cur_user,commands);
  if(x=="add_list")
    sol=add_list(cur_user,commands);
  if(x=="remove_list")
    sol=remove_list(cur_user,commands);
  if(x=="add_card")
    sol=add_card(cur_user,commands);
  if(x=="remove_card")
    sol=remove_card(cur_user,commands);
  if(x=="move_card")
    sol=move_card(cur_user,commands);
  if(x=="rename_card")
    sol=rename_card(cur_user,commands);
  if(x=="edit_card_description")
    sol=edit_card_des(cur_user,commands);
  if(x=="edit_card_due_date")
    sol=edit_card_date(cur_user,commands);
  if(x=="assign_user")
    sol=assign(cur_user,commands);
  if(x=="remove_user")
    sol=remove_user_from_card(cur_user,commands);
  if(x=="comment")
    sol=commenting(cur_user,commands);
  if(x=="filter")
    sol=filter(cur_user,commands);
  if(sol.size()==0)
    sol="Invalid command.\n";
  return sol;
     
}
예제 #20
0
/*!
  \brief present_viewer_choices() presents the user with the a list of 
  variables from EITHER the realtime vars (if in realtime mode) or from a 
  datalog (playback mode)
  */
G_MODULE_EXPORT void present_viewer_choices(void)
{
	GtkWidget *window = NULL;
	GtkWidget *table = NULL;
	GtkWidget *frame = NULL;
	GtkWidget *vbox = NULL;
	GtkWidget *hbox = NULL;
	GtkWidget *button = NULL;
	GtkWidget *label = NULL;
	GtkWidget *sep = NULL;
	GtkWidget *darea = NULL;
	GList *list = NULL;
	gconstpointer * object = NULL;
	gint i = 0;
	gint j = 0;
	gint k = 0;
	gint table_rows = 0;
	gint table_cols = 5;
	gchar * name = NULL;
	gchar * tooltip = NULL;
	gboolean playback = FALSE;
	Rtv_Map *rtv_map = NULL;
	Log_Info *log_info;

	log_info = DATA_GET(global_data,"log_info");
	rtv_map = DATA_GET(global_data,"rtv_map");
	darea = lookup_widget("logviewer_trace_darea");
	lv_data->darea = darea;
	playback = (GBOOLEAN)DATA_GET(global_data,"playback_mode");

	if (!darea)
	{
		MTXDBG(CRITICAL,_("Pointer to drawing area was NULL, returning!!!\n"));
		return;
	}

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget("main_window")));
	gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
	/* Playback mode..... */
	if (playback)
	{
		gtk_window_set_title(GTK_WINDOW(window),
				_("Playback Mode: Logviewer Choices"));
		frame = gtk_frame_new(_("Select Variables to playback from the list below..."));
		max_viewables = log_info->field_count;
	}
	else
	{
		/* Realtime Viewing mode... */
		gtk_window_set_title(GTK_WINDOW(window),
				_("Realtime Mode: Logviewer Choices"));
		frame = gtk_frame_new(_("Select Realtime Variables to view from the list below..."));
		max_viewables = rtv_map->derived_total;

	}
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(reenable_select_params_button),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(save_default_choices),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"destroy_event",
			G_CALLBACK(gtk_widget_destroy),
			(gpointer)window);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(reenable_select_params_button),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(save_default_choices),
			NULL);
	g_signal_connect_swapped(G_OBJECT(window),"delete_event",
			G_CALLBACK(gtk_widget_destroy),
			(gpointer)window);

	gtk_container_set_border_width(GTK_CONTAINER(window),5);
	gtk_container_add(GTK_CONTAINER(window),frame);

	vbox = gtk_vbox_new(FALSE,0);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
	gtk_container_add(GTK_CONTAINER(frame),vbox);

	table_rows = ceil((float)max_viewables/(float)table_cols);
	table = gtk_table_new(table_rows,table_cols,TRUE);
	gtk_table_set_row_spacings(GTK_TABLE(table),2);
	gtk_table_set_col_spacings(GTK_TABLE(table),5);
	gtk_container_set_border_width(GTK_CONTAINER(table),0);
	gtk_box_pack_start(GTK_BOX(vbox),table,FALSE,FALSE,0);

	j = 0;
	k = 0;
	if(get_list("viewables"))
	{
		g_list_free(get_list("viewables"));
		remove_list("viewables");
	}

	for (i=0;i<max_viewables;i++)
	{
		if (playback)
			list = g_list_prepend(list,(gpointer)g_ptr_array_index(log_info->log_list,i));
		else
			list = g_list_prepend(list,(gpointer)g_ptr_array_index(rtv_map->rtv_list,i));
	}
	if (playback)
		list=g_list_sort_with_data(list,list_object_sort,(gpointer)"lview_name");
	else
		list=g_list_sort_with_data(list,list_object_sort,(gpointer)"dlog_gui_name");

	for (i=0;i<max_viewables;i++)
	{
		object = NULL;
		name = NULL;
		tooltip = NULL;

		object = g_list_nth_data(list,i);

		if (playback)
			name = g_strdup(DATA_GET(object,"lview_name"));
		else
		{
			name = g_strdup(DATA_GET(object,"dlog_gui_name"));
			tooltip = g_strdup(DATA_GET(object,"tooltip"));
		}

		button = gtk_check_button_new();
		label = gtk_label_new(NULL);
		gtk_label_set_markup(GTK_LABEL(label),name);
		gtk_container_add(GTK_CONTAINER(button),label);
		store_list("viewables",g_list_prepend(
					get_list("viewables"),(gpointer)button));
		if (tooltip)
			gtk_widget_set_tooltip_text(button,tooltip);

		if (object)
		{
			OBJ_SET(button,"object",(gpointer)object);
			/* so we can set the state from elsewhere...*/
			DATA_SET(object,"lview_button",(gpointer)button);
			if ((GBOOLEAN)DATA_GET(object,"being_viewed"))
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE);
		}
		g_signal_connect(G_OBJECT(button),"toggled",
				G_CALLBACK(view_value_set),
				NULL);
		gtk_table_attach (GTK_TABLE (table), button, j, j+1, k, k+1,
				(GtkAttachOptions) (GTK_FILL),
				(GtkAttachOptions) (0), 0, 0);
		j++;

		if (j == table_cols)
		{
			k++;
			j = 0;
		}
		g_free(name);
	}
	g_list_free(list);

	sep = gtk_hseparator_new();
	gtk_box_pack_start(GTK_BOX(vbox),sep,FALSE,TRUE,20);

	hbox = gtk_hbox_new(FALSE,20);
	gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,TRUE,0);
	button = gtk_button_new_with_label("Select All");
	gtk_box_pack_start(GTK_BOX(hbox),button,TRUE,TRUE,15);
	OBJ_SET(button,"state",GINT_TO_POINTER(TRUE));
	g_signal_connect(G_OBJECT(button),"clicked",
			G_CALLBACK(set_all_lview_choices_state),
			GINT_TO_POINTER(TRUE));
	button = gtk_button_new_with_label("De-select All");
	gtk_box_pack_start(GTK_BOX(hbox),button,TRUE,TRUE,15);
	OBJ_SET(button,"state",GINT_TO_POINTER(FALSE));
	g_signal_connect(G_OBJECT(button),"clicked",
			G_CALLBACK(set_all_lview_choices_state),
			GINT_TO_POINTER(FALSE));

	button = gtk_button_new_with_label("Close");
	gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,TRUE,0);
	g_signal_connect_swapped(G_OBJECT(button),"clicked",
			G_CALLBACK(reenable_select_params_button),
			NULL);
	g_signal_connect_swapped(G_OBJECT(button),"clicked",
			G_CALLBACK(save_default_choices),
			NULL);
	g_signal_connect_swapped(G_OBJECT(button),"clicked",
			G_CALLBACK(gtk_widget_destroy),
			(gpointer)window);

	set_default_lview_choices_state();
	gtk_widget_show_all(window);
	return;
}
예제 #21
0
파일: kheap.c 프로젝트: oridb/PhotonOS
void free(void *p, heap_t *heap)
{
    // Exit gracefully for null pointers.
    if (p == 0)
	   return;

    // Get the header and footer associated with this pointer.
    header_t *header = (header_t*) ( (uint32_t)p - sizeof(header_t) );
    footer_t *footer = (footer_t*) ( (uint32_t)header + header->size - sizeof(footer_t) );

    // Sanity checks.
    ASSERT(header->magic == HEAP_MAGIC);
    ASSERT(footer->magic == HEAP_MAGIC);

    // Make us a hole.
    header->is_hole = 1;

    // Do we want to add this header into the 'free holes' index?
    char do_add = 1;

    // Unify left
    // If the thing immediately to the left of us is a footer...
    footer_t *test_footer = (footer_t*) ( (uint32_t)header - sizeof(footer_t) );
    if (test_footer->magic == HEAP_MAGIC &&
	   test_footer->header->is_hole == 1)
    {
	   uint32_t cache_size = header->size; // Cache our current size.
	   header = test_footer->header;	// Rewrite our header with the new one.
	   footer->header = header;		// Rewrite our footer to point to the new header.
	   header->size += cache_size;	  // Change the size.
	   do_add = 0;				   // Since this header is already in the index, we don't want to add it again.
    }

    // Unify right
    // If the thing immediately to the right of us is a header...
    header_t *test_header = (header_t*) ( (uint32_t)footer + sizeof(footer_t) );
    if (test_header->magic == HEAP_MAGIC &&
	   test_header->is_hole)
    {
	   header->size += test_header->size; // Increase our size.
	   test_footer = (footer_t*) ( (uint32_t)test_header + // Rewrite it's footer to point to our header.
							 test_header->size - sizeof(footer_t) );
	   footer = test_footer;
	   // Find and remove this header from the index.
	   uint32_t iterator = 0;
	   while ( (iterator < heap->index.size) &&
			 (lookup_list(iterator, &heap->index) != (void*)test_header) )
		  iterator++;

	   // Make sure we actually found the item.
	   ASSERT(iterator < heap->index.size);
	   // Remove it.
	   remove_list(iterator, &heap->index);
    }

    // If the footer location is the end address, we can contract.
    if ( (uint32_t)footer+sizeof(footer_t) == heap->end_address)
    {
	   uint32_t old_length = heap->end_address-heap->start_address;
	   uint32_t new_length = contract( (uint32_t)header - heap->start_address, heap);
	   // Check how big we will be after resizing.
	   if (header->size - (old_length-new_length) > 0)
	   {
		  // We will still exist, so resize us.
		  header->size -= old_length-new_length;
		  footer = (footer_t*) ( (uint32_t)header + header->size - sizeof(footer_t) );
		  footer->magic = HEAP_MAGIC;
		  footer->header = header;
	   }
	   else
	   {
		  // We will no longer exist :(. Remove us from the index.
		  uint32_t iterator = 0;
		  while ( (iterator < heap->index.size) &&
				(lookup_list(iterator, &heap->index) != (void*)test_header) )
			 iterator++;
		  // If we didn't find ourselves, we have nothing to remove.
		  if (iterator < heap->index.size)
			 remove_list(iterator, &heap->index);
	   }
    }

    // If required, add us to the index.
    if (do_add == 1)
	   insert_list((void*)header, &heap->index);

}
예제 #22
0
파일: kheap.c 프로젝트: oridb/PhotonOS
void *alloc(uint32_t size, uint8_t page_align, heap_t *heap)
{
	uint32_t new_size = size + sizeof(header_t) + sizeof(footer_t);
	int32_t iterator = find_hole(new_size, page_align, heap);
	
	if (iterator == (int32_t) -1) {
		uint32_t old_length = heap->end_address - heap->start_address;
		uint32_t old_end_address = heap->end_address;

		expand(old_length+new_size, heap);
		uint32_t new_length = heap->end_address-heap->start_address;

		iterator = 0;

		int32_t idx = -1;
		uint32_t value = 0x0;
		while (iterator < (int32_t) heap->index.size)
		{
		    uint32_t tmp = (uint32_t)lookup_list(iterator, &heap->index);
		    if (tmp > value)
		    {
			 value = tmp;
			 idx = iterator;
		    }
		    iterator++;
		}

		if (idx == -1)
		{
		    header_t *header = (header_t *)old_end_address;
		    header->magic = HEAP_MAGIC;
		    header->size = new_length - old_length;
		    header->is_hole = 1;
		    footer_t *footer = (footer_t *) (old_end_address + header->size - sizeof(footer_t));
		    footer->magic = HEAP_MAGIC;
		    footer->header = header;
		    insert_list((void*)header, &heap->index);
		}
		else
		{
		    header_t *header = lookup_list(idx, &heap->index);
		    header->size += new_length - old_length;
		    footer_t *footer = (footer_t *) ( (uint32_t)header + header->size - sizeof(footer_t) );
		    footer->header = header;
		    footer->magic = HEAP_MAGIC;
		}
		
		return alloc(size, page_align, heap);
	}
	
	header_t *orig_hole_header = (header_t *)lookup_list(iterator, &heap->index);
	uint32_t orig_hole_pos = (uint32_t) orig_hole_header;
	uint32_t orig_hole_size = orig_hole_header->size;
		
	if (orig_hole_size - new_size < sizeof(header_t) + sizeof(footer_t)) {
		size += orig_hole_size - new_size;
		new_size = orig_hole_size;
	}
	
	if (page_align && (orig_hole_pos & 0xFFFFF000)) {
		uint32_t new_location = orig_hole_pos + 0x1000 - (orig_hole_pos & 0xFFF) - sizeof(header_t);
		header_t *hole_header = (header_t*) orig_hole_pos;
		hole_header->size = 0x1000;
		hole_header->magic = HEAP_MAGIC;
		hole_header->is_hole = 1;
		footer_t *hole_footer = (footer_t*) ((uint32_t) new_location - sizeof(footer_t));
		hole_footer->magic = HEAP_MAGIC;
		hole_footer->header = hole_header;
		orig_hole_pos = new_location;
		orig_hole_size = orig_hole_size - hole_header->size;
	} else {
		remove_list(iterator, &heap->index);
	}
	
	header_t *block_header = (header_t*) orig_hole_pos;
	block_header->magic = HEAP_MAGIC;
	block_header->is_hole = 0;
	block_header->size = new_size;
	
	footer_t *block_footer = (footer_t*) (orig_hole_pos + sizeof(header_t) + size);
	block_footer->header = block_header;
	
	if (orig_hole_size - new_size > 0) {
		header_t *hole_header = (header_t*) (orig_hole_pos + sizeof(header_t) + size + sizeof(footer_t));
		hole_header->magic = HEAP_MAGIC;
		hole_header->is_hole = 1;
		hole_header->size = orig_hole_size - new_size;
		footer_t *hole_footer = (footer_t*) ((uint32_t) hole_header + orig_hole_size - new_size - sizeof(footer_t));
		
		if ((uint32_t) hole_footer < heap->end_address) {
			hole_footer->magic = HEAP_MAGIC;
			hole_footer->header = hole_header;			
		}
		insert_list((void*)hole_header, &heap->index);
	}
	return (void*) ((uint32_t) block_header + sizeof(header_t));
}