Example #1
0
static char* clear_multiple(void) {
  linked_list_append(root, create_object(1));
  linked_list_append(root, create_object(2));
  linked_list_append(root, create_object(3));
  linked_list_clear(root);
  mu_assert(0 == linked_list_count(root), "List is not empty after clearing multiple item list.");
  return 0;
}
void localize_deinit(){
  if(s_root){
    linked_list_foreach(s_root, prv_destroy_element, NULL);
    linked_list_clear(s_root);
    free(s_root);
  }
  s_previous_locale = 0;
}
Example #3
0
File: game.c Project: odrevet/GE
void game_free(game* p_game)
{
  free(p_game->name);
  free(p_game->context);
  unit_free(p_game->p_unit);
  map_free_all(p_game->p_map, p_game->nb_maps);
  ennemie_free_all(p_game->p_ennemie, p_game->ennemie_nb);
  NPC_free_all(p_game->p_NPC, p_game->NPC_nb);
  linked_list_clear(&p_game->vars);
}
Example #4
0
void suffix_mng_clear(suffix_mng_t *p) {
  if (p) {
    p->num_seeds = 0;
    if (p->suffix_lists) {
      for (unsigned int i = 0; i < p->num_chroms; i++) {
	if (p->suffix_lists[i]) {
	  linked_list_clear(p->suffix_lists[i], (void *)seed_free);
	}
      }
    }
  }
}
void test_linked_list_clear ()
{
  linked_list *list = create_linked_list ();
  TEST_ASSERT_NOT_NULL (list);
  char *strs1[] = {"test", "content", "random", "word", "code"};
  linked_list_append_all (list, (void **) strs1, 5);
   
  // try to clear the list
  linked_list_clear (list);
  TEST_ASSERT_EQUAL_INT (list->item_count, 0);

  delete_linked_list (list);
}
void test_insert()
{
	// regular insert
	linked_list* ll = linked_list_new();
	linked_list_insert(ll, 2);
	linked_list_insert(ll, 4);
	linked_list_insert(ll, 6);
	assert_equals(linked_list_size(ll), 3);
	assert_true(linked_list_contains(ll, 2));
	assert_true(linked_list_contains(ll, 4));
	assert_true(linked_list_contains(ll, 6));
	assert_false(linked_list_contains(ll, -1));
	assert_false(linked_list_contains(ll, 0));
	linked_list_clear(ll);
	linked_list* ll = linked_list_new();
	assert_equals(linked_list_size(ll), 0);
	assert_false(linked_list_contains(ll, 1));
	linked_list_insert(ll, 1);
	assert_equals(linked_list_size(ll), 1);
	assert_true(linked_list_contains(ll, 1));
	linked_list_clear(ll);
	// insert by index 
	// set by index 
}
void localize_init(uint32_t resource_locale) {

  if(s_previous_locale == resource_locale)
    return;

  if(s_root == NULL){
    s_root = linked_list_create_root();
  }
  else {
    linked_list_foreach(s_root, prv_destroy_element, NULL);
    linked_list_clear(s_root);
  }

  s_previous_locale = resource_locale;
}
Example #8
0
/* Destruction */
void linked_list_free(struct linked_list_t *list)
{
	linked_list_clear(list);
	free(list);
}
Example #9
0
File: main.c Project: odrevet/GE
int state_main_menu(SDL_Surface *screen)
{
    TTF_Font *font_menu = font_load("res/asia.ttf", 50);
    TTF_Font *font_credit = font_load("res/asia.ttf", 20);
    image *bg_image = image_load("res/main.jpg");
    Mix_Chunk *select = sample_load("res/select.wav");

    int i;
    const int item_nb = 2;
    int font_quality = SOLID;
    int choice_current=1;
    SDL_Rect cur_pos;
    bool done = false;
	//bool is_in_game = false;

    cur_pos.x = 10;
    cur_pos.y = 0;
    char sz_choice[20];

    #ifdef GEKKO
    bool timerset = false;
    #endif

    while (!done)
    {
        #ifdef GEKKO
       unsigned int start=0;
       if (!timerset) {
            timerset=true;
            start=SDL_GetTicks();
        }

       unsigned int now=SDL_GetTicks();
       if ((now-start)>50) {
            timerset=false;
            SDL_JoystickUpdate();
            int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0);
            switch (joystate){
                case SDL_HAT_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                break;
                case SDL_HAT_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                break;
            }
       }
       #endif



        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                done = true;
                break;
            case SDL_KEYUP:
                switch ( event.key.keysym.sym )
                {
                case SDLK_DOWN:
                    if (choice_current < item_nb){
                        choice_current++;
                        sample_play(select);
                    }
                    break;
                case SDLK_UP:
                    if (choice_current > 1){
                        choice_current--;
                        sample_play(select);
                    }
                    break;
                case SDLK_RETURN:
                    while (choice_current == IN_GAME)
                    {
                        unit_default_param(g_game.v_unit, g_game.unit_nb);
                        choice_current = state_in_game(screen);
                        if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                        {
                            choice_current = IN_GAME;
                            break;
                        }
                    }
                    if (choice_current == OPTION)state_options(screen);
                    break;

                default:
                    break;
                }
            break;
            case SDL_JOYBUTTONDOWN:
                switch(event.jbutton.button)
                {
                    case 0:
                    break;
                    case 1:
                    break;

                    case 2:
                        while (choice_current == IN_GAME)
                        {
                            unit_default_param(g_game.v_unit, g_game.unit_nb);
                            choice_current = state_in_game(screen);
                            if (choice_current == MAIN_MENU)    //The current state is main menu, select in game as default choice and quit
                            {
                                choice_current = IN_GAME;
                                break;
                            }
                        }
                        if (choice_current == OPTION)state_options(screen);
                    break;

                    case 3:
                    break;

                    case 4:
                    break;

                    case 5:
                    break;

                    case 6:
                        done = true;
                    break;
                }
            break;
            default:
            break;
            }
        }

        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
        image_draw(bg_image, screen, 0, 0);

        int top_shift = 150;

        for (i=1;i<=2;i++)
        {
            if (i == 1)
            {
                strncpy(sz_choice, "Play", 20);
                sz_choice[19] = '\0';
            }
            else if ( i == 2)
            {
                strncpy(sz_choice, "Options", 20);
                sz_choice[19] = '\0';
            }

            if (choice_current == i)
            {
                font_quality = SHADED;
            }
            else font_quality = SOLID;

            cur_pos.y = top_shift + i*50;
            SDL_Surface *font_surface= font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality);
            SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
            SDL_FreeSurface (font_surface);
        }

        cur_pos.y = 450;
        SDL_Surface *font_surface= font_create_surface(font_credit, 250, 120, 35, 10, 100, 100, 100, 0, "2010 - 2015 TheDrev", SOLID);
        SDL_BlitSurface(font_surface, NULL, screen, &cur_pos);
        SDL_FreeSurface (font_surface);

        SDL_Flip(screen);
    }

    //free font
    if(font_menu != NULL)TTF_CloseFont(font_menu);
    if(font_credit != NULL)TTF_CloseFont(font_credit);
    SDL_FreeSurface(bg_image->surface);
    Mix_FreeChunk(select);

    //free ressouces
    element* p_browse = images;
    while (p_browse) {
        ressource *res = p_browse->data;
        free(res->name);
        image_free(res->data);
        p_browse = p_browse->next;
    }

    linked_list_clear(&images);

    return EXIT_SUCCESS;
}
Example #10
0
static char* clear_empty(void) {
  linked_list_clear(root);
  mu_assert(0 == linked_list_count(root), "List is not empty after clearing empty list.");
  return 0;
}
Example #11
0
static  int
bfwork_run_threaded(bam_fwork_t *fwork)
{
	int err;
	bam_region_t *region;
	linked_list_t *regions;
	double times;

	omp_lock_t end_condition_lock;
	int end_condition;

	omp_lock_t reads_lock;
	size_t reads;
	size_t reads_to_write;

	//Init lock
	omp_init_lock(&end_condition_lock);
	omp_init_lock(&reads_lock);
	//#pragma omp parallel private(err, region, regions, times, reads_to_write)
	{
		//#pragma omp single
		{
			printf("Running in multithreading mode with %d threads\n", omp_get_max_threads());
			end_condition = 1;
			reads = 0;
		}

		#pragma omp parallel sections private(err, region, regions, times, reads_to_write)
		{
			//Region read
			#pragma omp section
			{
				regions = fwork->regions_list;
				while(1)
				{
					//Create new current region
					region = (bam_region_t *)malloc(sizeof(bam_region_t));
					breg_init(region);

					//Fill region
#ifdef D_TIME_DEBUG
					times = omp_get_wtime();
#endif
					err = bfwork_obtain_region(fwork, region);
#ifdef D_TIME_DEBUG
					times = omp_get_wtime() - times;
					omp_set_lock(&region->lock);
					if(fwork->context->time_stats)
					if(region->size != 0)
						time_add_time_slot(D_FWORK_READ, fwork->context->time_stats, times / (double)region->size);
					omp_unset_lock(&region->lock);
#endif
					if(err)
					{
						if(err == WANDER_REGION_CHANGED || err == WANDER_READ_EOF)
						{
							//Until process, this region cant be writed
							omp_test_lock(&region->write_lock);

							//Add region to framework regions
							bfwork_region_insert(fwork, region);

							#pragma omp task untied firstprivate(region) private(err)
							{
								int i;
								size_t pf_l;
								double aux_time;

								//Process region
								omp_set_lock(&region->lock);
#ifdef D_TIME_DEBUG
								times = omp_get_wtime();
#endif
								//Process region
								pf_l = fwork->context->processing_f_l;
								for(i = 0; i < pf_l; i++)
								{
									fwork->context->processing_f[i](fwork, region);
								}
#ifdef D_TIME_DEBUG
								times = omp_get_wtime() - times;
								if(fwork->context->time_stats)
								if(region->size != 0)
									time_add_time_slot(D_FWORK_PROC_FUNC, fwork->context->time_stats, times / (double)region->size);
								aux_time = omp_get_wtime();
#endif
								omp_unset_lock(&region->lock);

								omp_set_lock(&reads_lock);
								reads += region->size;
								printf("Reads processed: %lu\r", reads);
								omp_unset_lock(&reads_lock);

#ifdef D_TIME_DEBUG
								aux_time = omp_get_wtime() - aux_time;
								omp_set_lock(&region->lock);
								if(fwork->context->time_stats)
								if(region->size != 0)
									time_add_time_slot(D_FWORK_PROC, fwork->context->time_stats, (times + aux_time) / (double)region->size);
								omp_unset_lock(&region->lock);
#endif

								//Set this region as writable
								omp_unset_lock(&region->write_lock);
							}

							//End readings
							if(err == WANDER_READ_EOF)
								 break;
						}
						else
						{
							if(err == WANDER_READ_TRUNCATED)
							{
								LOG_WARN("Readed truncated read\n");
							}
							else
							{
								LOG_FATAL_F("Failed to read next region, error code: %d\n", err);
							}
							break;
						}
					}
					else
					{
						//No more regions, end loop
						LOG_INFO("No more regions to read");
						break;
					}
				}

				omp_set_lock(&end_condition_lock);
				end_condition = 0;
				omp_unset_lock(&end_condition_lock);
				//LOG_WARN("Read thread exit\n");
			}//End read section

			//Write section
			#pragma omp section
			{
				regions = fwork->regions_list;
				omp_set_lock(&end_condition_lock);
				while(end_condition || linked_list_size(regions) > 0)
				{
					omp_unset_lock(&end_condition_lock);
#ifdef D_TIME_DEBUG
					times = omp_get_wtime();
#endif

					//Get next region
					omp_set_lock(&fwork->regions_lock);
					region = linked_list_get_first(regions);
					omp_unset_lock(&fwork->regions_lock);
					if(region == NULL)
					{
						omp_set_lock(&end_condition_lock);
						continue;
					}

					//Wait region to be writable
					omp_set_lock(&region->write_lock);

					//Write region
					omp_set_lock(&fwork->output_file_lock);
					reads_to_write = region->size;
					breg_write_n(region, reads_to_write, fwork->output_file);
					omp_unset_lock(&fwork->output_file_lock);

					//Remove from list
					omp_set_lock(&fwork->regions_lock);
					if(linked_list_size(regions) == 1)	//Possible bug?
						linked_list_clear(regions, NULL);
					else
						linked_list_remove_first(regions);

					//Signal read section if regions list is full
					if(linked_list_size(regions) < (FWORK_REGIONS_MAX / 2) )
						omp_unset_lock(&fwork->free_slots);

					omp_unset_lock(&fwork->regions_lock);

#ifdef D_TIME_DEBUG
					times = omp_get_wtime() - times;
					omp_set_lock(&region->lock);
					if(fwork->context->time_stats)
					if(reads_to_write != 0)
						time_add_time_slot(D_FWORK_WRITE, fwork->context->time_stats, times / (double)reads_to_write);
					omp_unset_lock(&region->lock);
#endif

					//Free region
					breg_destroy(region, 1);
					free(region);

					omp_set_lock(&end_condition_lock);
				}
				omp_unset_lock(&end_condition_lock);

				//LOG_WARN("Write thread exit\n");
			}//End write section

		}//End sections

	}//End parallel

	//Lineskip
	printf("\n");

	//Free
	omp_destroy_lock(&end_condition_lock);

	return NO_ERROR;
}
Example #12
0
void persist_clear(void) {
  linked_list_clear(persistence);
}