Exemplo n.º 1
0
/* rebuild all active rows without reordering jobs:
 * - attempt to preserve running jobs
 * - suspend any jobs that have been "shadowed" (preempted)
 * - resume any "filler" jobs that can be found
 */
static void _update_all_active_rows(void)
{
	ListIterator part_iterator;
 	struct gs_part *p_ptr;

	/* Sort the partitions. This way the shadows of any high-priority
	 * jobs are appropriately adjusted before the lower priority
	 * partitions are updated */
	list_sort(gs_part_list, _sort_partitions);

	part_iterator = list_iterator_create(gs_part_list);
	while ((p_ptr = (struct gs_part *) list_next(part_iterator)))
		_update_active_row(p_ptr, 1);
	list_iterator_destroy(part_iterator);
}
Exemplo n.º 2
0
/* The timeslicer thread */
static void *_timeslicer_thread(void *arg)
{
	/* Write locks on job and read lock on nodes */
	slurmctld_lock_t job_write_lock = {
		NO_LOCK, WRITE_LOCK, READ_LOCK, NO_LOCK };
	ListIterator part_iterator;
	struct gs_part *p_ptr;

	if (gs_debug_flags & DEBUG_FLAG_GANG)
		info("gang: starting timeslicer loop");
	while (!thread_shutdown) {
		_slice_sleep();
		if (thread_shutdown)
			break;

		lock_slurmctld(job_write_lock);
		pthread_mutex_lock(&data_mutex);
		list_sort(gs_part_list, _sort_partitions);

		/* scan each partition... */
		if (gs_debug_flags & DEBUG_FLAG_GANG)
			info("gang: _timeslicer_thread: scanning partitions");
		part_iterator = list_iterator_create(gs_part_list);
		if (part_iterator == NULL)
			fatal("memory allocation failure");
		while ((p_ptr = (struct gs_part *) list_next(part_iterator))) {
			if (gs_debug_flags & DEBUG_FLAG_GANG) {
				info("gang: _timeslicer_thread: part %s: "
				     "run %u total %u", p_ptr->part_name,
				     p_ptr->jobs_active, p_ptr->num_jobs);
			}
			if (p_ptr->jobs_active <
			    (p_ptr->num_jobs + p_ptr->num_shadows)) {
				_cycle_job_list(p_ptr);
			}
		}
		list_iterator_destroy(part_iterator);
		pthread_mutex_unlock(&data_mutex);

		/* Preempt jobs that were formerly only suspended */
		_preempt_job_dequeue();	/* MUST BE OUTSIDE data_mutex lock */
		unlock_slurmctld(job_write_lock);
	}

	timeslicer_thread_id = (pthread_t) 0;
	pthread_exit((void *) 0);
	return NULL;
}
Exemplo n.º 3
0
/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
void
sema_up (struct semaphore *sema) 
{
  enum intr_level old_level;

  ASSERT (sema != NULL);
	struct list_elem *e = NULL;
	struct thread *t;
  old_level = intr_disable ();
  if (!list_empty (&sema->waiters)) {
  list_sort(&sema->waiters, (list_less_func *) &higher_priority,
		NULL);
  	e = list_pop_front(&sema->waiters);
  	t = list_entry(e, struct thread, elem);
  	thread_unblock(t);
  }
extern List acct_gather_conf_values(void)
{
	List acct_list = list_create(destroy_config_key_pair);

	/* get acct_gather.conf in each plugin */
	acct_gather_profile_g_conf_values(&acct_list);
	acct_gather_infiniband_g_conf_values(&acct_list);
	acct_gather_energy_g_conf_values(&acct_list);
	acct_gather_filesystem_g_conf_values(&acct_list);
	/* ADD MORE HERE */
	/******************************************/

	list_sort(acct_list, (ListCmpF) sort_key_pairs);

	return acct_list;
}
Exemplo n.º 5
0
/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
void
sema_up (struct semaphore *sema) 
{
  enum intr_level old_level;

  ASSERT (sema != NULL);

  old_level = intr_disable ();
 
  if (!list_empty (&sema->waiters)) {
     
     list_sort(&sema->waiters, &max_effective_priority_thread, NULL);
     struct thread *t  = list_entry (list_pop_front(&sema->waiters), struct thread, elem);
   
     thread_unblock (t);
    
  }
Exemplo n.º 6
0
/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
    void
sema_up (struct semaphore *sema) 
{
    enum intr_level old_level;
    struct thread *next_thread = NULL; 

    ASSERT (sema != NULL);

    old_level = intr_disable ();
    if (!list_empty (&sema->waiters)) 
    {
        list_sort(&sema->waiters, threadLessSort, NULL);

        next_thread = list_entry(list_pop_front(&sema->waiters), struct thread, elem);

        thread_unblock (next_thread);
    }
Exemplo n.º 7
0
/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
void
sema_up (struct semaphore *sema)
{
  enum intr_level old_level;

  ASSERT (sema != NULL);

  old_level = intr_disable ();
  sema->value++;
  if (!list_empty (&sema->waiters)) {
    list_sort (&sema->waiters, great_priority_thread, (void *)NULL);
    struct thread *t = list_entry (list_pop_front (&sema->waiters),
                                struct thread, elem);
    thread_unblock (t);
    if (t->priority > thread_current ()->priority)
      thread_yield ();
  }
Exemplo n.º 8
0
void list_print( struct node *list)
{
    if(list==NULL)
    {
        printf("\nList was empty!\n");
        return;
    }
    list_sort(&list);//Sort the list before we print it
    int i = 0;
    printf("\n*** List Contents Begin ***\n");
    while (list != NULL)
    {
        printf("List item %d: %d\n", i++, list->value);
        list = list->next;
    }
    printf("*** List Contents End ***\n");
}
Exemplo n.º 9
0
LIST * property_set_create( FRAME * frame, int flags )
{
    LIST * properties = lol_get( frame->args, 0 );
    LIST * sorted = list_sort( properties );
    LIST * unique = list_unique( sorted );
    struct ps_map_entry * pos = ps_map_insert( &all_property_sets, unique );
    list_free( sorted );
    if ( pos->value )
    {
        list_free( unique );
        return list_new( object_copy( pos->value ) );
    }
    else
    {
        OBJECT * rulename = object_new( "new" );
        OBJECT * varname = object_new( "self.raw" );
        LIST * val = call_rule( rulename, frame,
            list_new( object_new( "property-set" ) ), 0 );
        LISTITER iter, end;
        object_free( rulename );
        pos->value = list_front( val );
        var_set( bindmodule( pos->value ), varname, unique, VAR_SET );
        object_free( varname );

        for ( iter = list_begin( unique ), end = list_end( unique ); iter != end; ++iter )
        {
            const char * str = object_str( list_item( iter ) );
            if ( str[ 0 ] != '<' || ! strchr( str, '>' ) )
            {
                string message[ 1 ];
                string_new( message );
                string_append( message, "Invalid property: '" );
                string_append( message, str );
                string_append( message, "'" );
                rulename = object_new( "errors.error" );
                call_rule( rulename, frame,
                    list_new( object_new( message->value ) ), 0 );
                /* unreachable */
                string_free( message );
                object_free( rulename );
            }
        }

        return val;
    }
}
Exemplo n.º 10
0
static void elf_file_read_symbol_table(struct elf_file_t *elf_file)
{
	struct elf_section_t *section;
	int i;

	/* Create symbol table */
	elf_file->symbol_table = list_create();

	/* Load symbols from sections */
	for (i = 0; i < list_count(elf_file->section_list); i++) {
		section = list_get(elf_file->section_list, i);
		if (section->header->sh_type == 2 || section->header->sh_type == 11)
			elf_file_read_symbol_section(elf_file, section);
	}

	/* Sort symbol table */
	list_sort(elf_file->symbol_table, elf_symbol_compare);
}
Exemplo n.º 11
0
/*
 * get info from the storage
 * returns List of job_rec_t *
 * note List needs to be freed when called
 */
extern List jobacct_storage_g_get_jobs_cond(void *db_conn, uint32_t uid,
					    slurmdb_job_cond_t *job_cond)
{
	List ret_list;

	if (slurm_acct_storage_init(NULL) < 0)
		return NULL;
	ret_list = (*(ops.get_jobs_cond))(db_conn, uid, job_cond);

	/* If multiple clusters were requested, the jobs are grouped together by
	 * cluster -- each group sorted by submit time. Sort all the jobs by
	 * submit time */
	if (ret_list && job_cond && job_cond->cluster_list &&
	    (list_count(job_cond->cluster_list) > 1))
		list_sort(ret_list, (ListCmpF)_sort_desc_submit_time);

	return ret_list;
}
Exemplo n.º 12
0
/* Up or "V" operation on a semaphore.  Increments SEMA's value
   and wakes up one thread of those waiting for SEMA, if any.

   This function may be called from an interrupt handler. */
void
sema_up (struct semaphore *sema)
{
    enum intr_level old_level;
    ASSERT (sema != NULL);

    bool should_yield = false;
    old_level = intr_disable ();
    sema->value++;
    if (!list_empty (&sema->waiters)) {
        list_sort (&sema->waiters, &priority_ordering, NULL); //MAYBE THIS'll DO?
        struct thread *t = list_entry (list_pop_front (&sema->waiters),
                                       struct thread, elem);
        thread_unblock (t);
        if (t->priority >= thread_get_priority()) {
            should_yield = true;
        }
    }
Exemplo n.º 13
0
void sort_init(sort_t * sort, board_t * board, const attack_t * attack, int depth, int height, int trans_killer) {

   ASSERT(sort!=NULL);
   ASSERT(board!=NULL);
   ASSERT(attack!=NULL);
   ASSERT(depth_is_ok(depth));
   ASSERT(height_is_ok(height));
   ASSERT(trans_killer==MoveNone||move_is_ok(trans_killer));

   sort->board = board;
   sort->attack = attack;

   sort->depth = depth;
   sort->height = height;

   sort->trans_killer = trans_killer;
   sort->killer_1 = Killer[sort->height][0];
   sort->killer_2 = Killer[sort->height][1];
   if (sort->height > 2){
	  sort->killer_3 = Killer[sort->height-2][0];
      sort->killer_4 = Killer[sort->height-2][1]; 
   }
   else{
      sort->killer_3 = MoveNone;
      sort->killer_4 = MoveNone;
   }

   if (ATTACK_IN_CHECK(sort->attack)) {

      gen_legal_evasions(sort->list,sort->board,sort->attack);
      note_moves(sort->list,sort->board,sort->height,sort->trans_killer);
      list_sort(sort->list);

      sort->gen = PosLegalEvasion + 1;
      sort->test = TEST_NONE;

   } else { // not in check

      LIST_CLEAR(sort->list);
      sort->gen = PosSEE;
   }

   sort->pos = 0;
}
Exemplo n.º 14
0
uint8_t*
lupdate_wfc(uint8_t* bwt,uint32_t size,uint8_t* output,uint64_t* c)
{
    uint32_t chr,j;
    int32_t cost,i;
    list_t* lst;
    lnode_t* found,*tmp;
    int32_t k,start;

    lst = lupdate_createlist();

    *c = 0;
    for (j=0; j<size; j++) {
        chr = bwt[j];

        found = list_find(lst,chr,&cost);

        output[j] = (uint8_t) cost;
        *c += cost;

        /* reset wfreq values */
        tmp = lst->head;
        while (tmp != NULL) {
            tmp->wfreq = 0;
            tmp = tmp->next;
        }

        /* calculate new wfreq values */
        start = MAX(j-512,0);
        for (k=start; k<j; k++) {
            found = list_find(lst,bwt[k],&i);
            found->wfreq = found->wfreq + calc_wfc(j-k,k);
        }

        /* sort list based on wfreq values */
        list_sort(lst,wfc_cmp);
    }

    list_free(lst);

    return output;
}
Exemplo n.º 15
0
/**
 * cs_parser_fini() - clean parser states
 * @parser:	parser structure holding parsing context.
 * @error:	error number
 *
 * If error is set than unvalidate buffer, otherwise just free memory
 * used by parsing context.
 **/
static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error, bool backoff)
{
	unsigned i;

	if (!error) {
		/* Sort the buffer list from the smallest to largest buffer,
		 * which affects the order of buffers in the LRU list.
		 * This assures that the smallest buffers are added first
		 * to the LRU list, so they are likely to be later evicted
		 * first, instead of large buffers whose eviction is more
		 * expensive.
		 *
		 * This slightly lowers the number of bytes moved by TTM
		 * per frame under memory pressure.
		 */
		list_sort(NULL, &parser->validated, cmp_size_smaller_first);

		ttm_eu_fence_buffer_objects(&parser->ticket,
					    &parser->validated,
					    parser->ib.fence);
	} else if (backoff) {
		ttm_eu_backoff_reservation(&parser->ticket,
					   &parser->validated);
	}

	if (parser->relocs != NULL) {
		for (i = 0; i < parser->nrelocs; i++) {
			if (parser->relocs[i].gobj)
				drm_gem_object_unreference_unlocked(parser->relocs[i].gobj);
		}
	}
	kfree(parser->track);
	kfree(parser->relocs);
	kfree(parser->relocs_ptr);
	kfree(parser->vm_bos);
	for (i = 0; i < parser->nchunks; i++)
		drm_free_large(parser->chunks[i].kdata);
	kfree(parser->chunks);
	kfree(parser->chunks_array);
	radeon_ib_free(parser->rdev, &parser->ib);
	radeon_ib_free(parser->rdev, &parser->const_ib);
}
Exemplo n.º 16
0
extern void print_fields_char_list(print_field_t *field, List value, int last)
{
	int abs_len = abs(field->len);
	ListIterator itr = NULL;
	char *print_this = NULL;
	char *object = NULL;

	if (!value || !list_count(value)) {
		if (print_fields_parsable_print)
			print_this = xstrdup("");
		else
			print_this = xstrdup(" ");
	} else {
		list_sort(value, (ListCmpF)slurm_sort_char_list_asc);
		itr = list_iterator_create(value);
		while ((object = list_next(itr))) {
			if (print_this)
				xstrfmtcat(print_this, ",%s", object);
			else
				print_this = xstrdup(object);
		}
		list_iterator_destroy(itr);
	}

	if (print_fields_parsable_print == PRINT_FIELDS_PARSABLE_NO_ENDING
	   && last)
		printf("%s", print_this);
	else if (print_fields_parsable_print && !fields_delimiter)
		printf("%s|", print_this);
	else if (print_fields_parsable_print && fields_delimiter)
		printf("%s%s", print_this, fields_delimiter);
	else if (print_this) {
		if (strlen(print_this) > abs_len)
			print_this[abs_len-1] = '+';

		if (field->len == abs_len)
			printf("%*.*s ", abs_len, abs_len, print_this);
		else
			printf("%-*.*s ", abs_len, abs_len, print_this);
	}
	xfree(print_this);
}
t_nodo *seleccionarNodoMenosCargado(t_list *listaNodosConectados, int posicion)
{

	t_nodo *nodoDevolver;
	reservarListaNodosConectados();
	list_sort(listaNodosConectados,compararCantidadBloquesNodo);
	devolverListaNodosConectados();
	t_list *listaAux = removerNodosDesahabilitadosYSinEspacio(listaNodosConectados);
	if(posicion > 0 && posicion <= list_size(listaAux))
	{
		nodoDevolver = (t_nodo*)list_get(listaAux,(list_size(listaAux) - posicion));
		list_destroy(listaAux);
		return nodoDevolver;
	}
	else
	{
		list_destroy(listaAux);
		return NULL;
	}
}
Exemplo n.º 18
0
Arquivo: alarm.c Projeto: nem0301/OS
void alarm_insert(int64_t tick) {
  struct thread* cur = thread_current();
  struct alarm* al;
  enum intr_level old_level;

  ASSERT(cur->status == THREAD_RUNNING);

  old_level = intr_disable();

  al = (struct alarm*) malloc (sizeof (struct alarm));
  al->expiration = tick;
  al->th = cur;


  list_push_back(&alarms, &al->elem);
  list_sort(&alarms, alarm_sort, NULL);

  thread_block();

  intr_set_level(old_level);
}
Exemplo n.º 19
0
void magic_generateMd5Log(char* path, char* pathToDump) {
	t_list* entries = files_getEntriesOfDirectory(path);
	bool _sortByName(char* str1, char* str2) {
		return strcmp(str1, str2) < 0;
	}
	list_sort(entries, (void*) _sortByName);

	char command[MAX_PATH];
	sprintf(command, "touch %s", pathToDump);
	system(command);
	void _printMd5(char* fileName) {
		chdir(path);
		if (files_directoryExists(fileName)) {
			char* fullPath = files_getFullPath(fileName);
			magic_generateMd5Log(fullPath, pathToDump);
			free(fullPath);
		} else {
			sprintf(command, "md5sum %s >> %s", fileName, pathToDump);
			system(command);
		}
	}
Exemplo n.º 20
0
static void try_delta_loop(struct list *updates)
{
	struct list *iter;
	struct file *file;

	/* need update list in filename order to insure directories are
	 * created before their contents */
	updates = list_sort(updates, file_sort_filename);

	iter = list_head(updates);
	while (iter) {
		file = iter->data;
		iter = iter->next;

		if (!file->is_file) {
			continue;
		}

		try_delta(file);
	}
}
Exemplo n.º 21
0
static void elf_file_read_symbol_table(struct elf_file_t *elf_file)
{
	struct elf_section_t *section;
	struct elf_symbol_t *symbol;
	int i;

	/* Create symbol table */
	elf_file->symbol_table = list_create();

	/* Load symbols from sections */
	elf_debug("Symbol table:\n");
	for (i = 0; i < list_count(elf_file->section_list); i++) {
		section = list_get(elf_file->section_list, i);
		if (section->header->sh_type == 2 || section->header->sh_type == 11)
			elf_file_read_symbol_section(elf_file, section);
	}

	/* Sort symbol table */
	list_sort(elf_file->symbol_table, elf_symbol_compare);

	/* Dump */
	elf_debug("\n");
	elf_debug("%-40s %-15s %-12s %-12s\n", "name", "section", "value", "size");
	for (i = 0; i < 80; i++)
		elf_debug("-");
	elf_debug("\n");
	for (i = 0; i < list_count(elf_file->symbol_table); i++)
	{
		char section_name[15];

		symbol = list_get(elf_file->symbol_table, i);
		section = list_get(elf_file->section_list, symbol->section);
		if (section)
			snprintf(section_name, sizeof(section_name), "%s", section->name);
		else
			snprintf(section_name, sizeof(section_name), "%d", symbol->section);
		elf_debug("%-40s %-15s 0x%-10x %-12d\n", symbol->name, section_name, symbol->value, symbol->size);
	}
	elf_debug("\n");
}
Exemplo n.º 22
0
static int query_consoles(server_conf_t *conf, req_t *req)
{
/*  Queries the server's conf to resolve the console names specified
 *    in the client's request.
 *  Returns 0 on success, or -1 on error.
 *    Upon a successful return, the req->consoles list of strings
 *    is replaced with a list of console obj_t's.
 */
    List matches;
    int rc;

    if (list_is_empty(req->consoles) && (req->command != CONMAN_CMD_QUERY))
        return(0);

    /*  The NULL destructor is used for 'matches' because the matches list
     *    will only contain refs to objs contained in the conf->objs list.
     *    These objs will be destroyed when the conf->objs list is destroyed.
     */
    matches = list_create(NULL);

    if (req->enableRegex)
        rc = query_consoles_via_regex(conf, req, matches);
    else
        rc = query_consoles_via_globbing(conf, req, matches);

    /*  Replace original list of strings with list of obj_t's.
     */
    list_destroy(req->consoles);
    req->consoles = matches;
    list_sort(req->consoles, (ListCmpF) compare_objs);

    /*  If only one console was selected for a broadcast, then
     *    the session is placed into R/W mode instead of W/O mode.
     *    So update the req accordingly.
     */
    if (list_count(req->consoles) == 1)
        req->enableBroadcast = 0;

    return(rc);
}
Exemplo n.º 23
0
//-----------------------------------------------------------------------------
// VLFN_DataBase_Save (void)
// Save VLFN database back to MEKA.FDB file.
//-----------------------------------------------------------------------------
void        VLFN_DataBase_Save (void)
{
    FILE *  f;
    t_list *list;

    if ((f = fopen (VLFN_DataBase.filename, "wt")) == 0)
        return; // FIXME: report that somewhere ?

    // Sort entries by file name before writing, so the output file is more sexy
    list_sort (&VLFN_DataBase.entries, (int (*)(void *, void *))VLFN_Entries_Compare);

    // Write header
    fprintf (f, ";-----------------------------------------------------------------------------\n");
    fprintf (f, "; " MEKA_NAME " " MEKA_VERSION " - User Filenames DataBase\n");
    fprintf (f, "; Associate user filenames with MEKA DataBase entries.\n");
    fprintf (f, "; This information is used by the file loader.\n");
    fprintf (f, "; This file is automatically updated and rewritten by the emulator.\n");
    fprintf (f, ";-----------------------------------------------------------------------------\n\n");

    // Write all entries
    for (list = VLFN_DataBase.entries; list != NULL; list = list->next)
    {
        t_vlfn_entry *entry     = list->elem;
        t_db_entry *db_entry    = entry->db_entry;
        fprintf (f, "%s", entry->filename);
        if (db_entry->crc_crc32 != 0)
            fprintf (f, "/CRC32:%08x", db_entry->crc_crc32);
        // Note: MekaCRC is always written now!
        fprintf (f, "/MEKACRC:%08X%08X\n", db_entry->crc_mekacrc.v[0], db_entry->crc_mekacrc.v[1]);
    }

    fprintf (f, "\n;-----------------------------------------------------------------------------\n\n");

    // Close write
    fclose (f);

    // Free all entries
    list_free_custom (&VLFN_DataBase.entries, VLFN_Entry_Delete);
}
int main(void)
{
	int* num = malloc(sizeof(*num));
	int i, j;
	list_t tmp;
	list_t numList; 
	
	numList = list_new(1);
	resultList = list_new(1);
	scanf("%d", num);
	list_push(numList, num);
	partition(numList);
	list_sort(resultList);
	/*输出*/
	for (i = 0; i < resultList->head; i++)
	{
		printf("%d = ", *num);
		tmp = resultList->elem[i];
		for (j = 0; j < tmp->head; j++)
		{
			printf("%d", *(int*)(tmp->elem[j]));
			if (j != tmp->len - 1)
			{
				printf(" + ");
			}
		}
		printf("\n");
	}

	/*释放内存*/
	for (i = 0; i < resultList->head; ++i)
	{
		tmp = resultList->elem[i];
		free(tmp->elem[0]);
		list_free((list_t*)&(resultList->elem[i]));
	}
	list_free(&resultList);

}
void compactacionBruta()
{
	log_info(SwapLog,"Inicio de compactacion de espacio en memoria de swap");
	list_sort(espacioOcupado,compararUbicaciones);
	uint32_t cantidadOcupados = list_size(espacioOcupado);
    uint32_t comienzo = 0;
	uint32_t indice,indiceNodo;
    int32_t cantidadPaginasNodo;
	t_nodoOcupado* nodoOcupado;
	int32_t ubicacionPagina, nuevaUbicacion;
	char* espacioViejo;
	char* espacioNuevo;
    for(indice = 0;indice < cantidadOcupados;indice++)
    {
    	nodoOcupado = list_get(espacioOcupado,indice);
    	cantidadPaginasNodo = nodoOcupado->paginas;
    	for(indiceNodo = 0; indiceNodo < cantidadPaginasNodo; indiceNodo++)
    	{
    		ubicacionPagina = nodoOcupado->comienzo + indiceNodo;
    		nuevaUbicacion = comienzo + indiceNodo;
    		espacioViejo = archivoMapeado->memoria + ubicacionPagina*configuracion->tamano_pagina;
    		espacioNuevo = archivoMapeado->memoria + nuevaUbicacion*configuracion->tamano_pagina;
    		memcpy(espacioNuevo,espacioViejo,configuracion->tamano_pagina);
    	}
    	nodoOcupado->comienzo = comienzo;
    	comienzo = nodoOcupado->comienzo + cantidadPaginasNodo;

    }
	uint32_t totalLibres;
	totalLibres = contarPaginasLibres();
	uint32_t comienzoLibre = configuracion->cantidad_paginas - totalLibres;
	t_nodoLibre* nodoLibre = malloc(sizeof(t_nodoLibre));
	nodoLibre->comienzo = comienzoLibre;
	nodoLibre->paginas = totalLibres;
	list_clean(espacioLibre);
	list_add(espacioLibre,nodoLibre);
	usleep(deSegundoAMicroSegundos(configuracion->retardo_compactacion));
	log_info(SwapLog,"Finalizacion de compactacion en memoria de swap");
}
Exemplo n.º 26
0
void test_sort(size_t sz)
{
	unsigned i, a;
	int s1=0, s2=0, x1=0, x2=0;
	list_t* l;
	list_node_t* n;

	printf("test_sort(%d) ... ", sz);

	l = list_create();

	for (i = 0; i < sz; i++) {
		a = rnd() % 100;
		if (i % 2)
			list_append(l, (void*)a);
		else
			list_prepend(l, (void*)a);
		s1 += a;
		x1 ^= a;
	}

	list_sort(list_reverse(l), cf);

	for (i = 0, n = l->first; n != NULL; i++, n = n->next) {
		if (n->next)
			assert(cf(n->data, n->next->data) <= 0);

		s2 += (unsigned)n->data;
		x2 ^= (unsigned)n->data;
	}

	assert(s1 == s2);
	assert(x1 == x2);
	assert(i == l->len);

	list_destroy(l);

	printf("ok\n");
}
Exemplo n.º 27
0
static List _create_resv_info_list(reserve_info_msg_t *resv_info_ptr)
{
	static List info_list = NULL;
	int i = 0;
	static reserve_info_msg_t *last_resv_info_ptr = NULL;
	sview_resv_info_t *sview_resv_info_ptr = NULL;
	reserve_info_t *resv_ptr = NULL;

	if (info_list && (resv_info_ptr == last_resv_info_ptr))
		goto update_color;

	last_resv_info_ptr = resv_info_ptr;

	if (info_list)
		list_flush(info_list);
	else
		info_list = list_create(_resv_info_list_del);

	if (!info_list) {
		g_print("malloc error\n");
		return NULL;
	}

	for(i=0; i<resv_info_ptr->record_count; i++) {
		resv_ptr = &(resv_info_ptr->reservation_array[i]);

		sview_resv_info_ptr = xmalloc(sizeof(sview_resv_info_t));
		sview_resv_info_ptr->pos = i;
		sview_resv_info_ptr->resv_ptr = resv_ptr;
		sview_resv_info_ptr->color_inx = i % sview_colors_cnt;
		list_append(info_list, sview_resv_info_ptr);
	}

	list_sort(info_list,
		  (ListCmpF)_sview_resv_sort_aval_dec);

update_color:
	return info_list;
}
int main(void) {
	FILE* personasIN;
	FILE* personasOUT;
	char* line;
	t_list* personasList = list_create();


	personasIN = fopen("/home/utnso/workspace/tp-2015-1c-the-byteless/Ejercicios/Juan/Ejercicio_03-Commons/Personas.txt","r");
    personasOUT = fopen("/home/utnso/workspace/tp-2015-1c-the-byteless/Ejercicios/Juan/Ejercicio_03-Commons/PersonasNuevo.txt","w");
	logFile = log_create("/home/utnso/workspace/tp-2015-1c-the-byteless/Ejercicios/Juan/Ejercicio_03-Commons/log.txt",
						"Ejercicio 3",true,LOG_LEVEL_INFO);
    if (personasIN == NULL)
    {
        printf("No se pudo abrir el archivo");
    	exit(EXIT_FAILURE);
    }

	line = malloc(LINE_SIZE);


	while (fgets(line,LINE_SIZE,personasIN)!=NULL)
	{
		list(line, personasList);
	}

	list_sort(personasList, (isGreater));

	personasList = list_filter(personasList, (isMajor));

	saveToFile(personasList, personasOUT);

	free(line);
	fclose(personasIN);
	fclose(personasOUT);
	log_destroy(logFile);
	list_destroy(personasList);
	return EXIT_SUCCESS;
}
Exemplo n.º 29
0
int		nm(const char * filename)
{
  void		*data;
  t_elf		elf;
  t_sym_list	*list;
  int		msize;

  if ((msize = map_file(&data, filename)) == -1)
    return (1);
  if (init_elf_data(&elf, data) == -1)
    return (1);
  list = extract_symbols(&elf);
  list_sort(list, symcmp);
  list_iter(list, print_symbol);
  delete_list(list);
  if (elf.ehdr->e_ident[EI_CLASS] == ELFCLASS32)
    {
      free(elf.ehdr);
      free(elf.shtab);
    }
  (void)munmap(data, msize);
  return (0);
}
Exemplo n.º 30
0
/* Down or "P" operation on a semaphore.  Waits for SEMA's value
   to become positive and then atomically decrements it.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but if it sleeps then the next scheduled
   thread will probably turn interrupts back on. */
    void
sema_down (struct semaphore *sema) 
{
    enum intr_level old_level;

    //  struct thread *debug_thread;

    ASSERT (sema != NULL);
    ASSERT (!intr_context ());

    old_level = intr_disable ();
    while (sema->value == 0) 
    {
        list_insert_ordered(&sema->waiters, &thread_current()->elem, threadLessSort, NULL);

        // We have to sort Lock's holder's lock list
        list_sort(&thread_current()->lock_list, lockHigherSort, NULL);

        thread_block ();
    }
    sema->value--;
    intr_set_level (old_level);
}