Exemplo n.º 1
0
hint32 hdata_set_tree(hdata_set_t data_set, hdata_set_tree_key_t key,hdata_set_tree_key_t parent_key,hash_code_t key_hash,equal_t key_equal,list_compare_t comparator,hany param,InvokeTickDeclare){
	data_set_t * ds = (data_set_t *)data_set;
	hany k;
	hany pk;
	hint32 i,c;
	hdata_t items,item;
	data_set_tree_item_t * tree_item,*tree_pitem;
	data_set_tree_item_compare_param_t compare_param;
	if(ds && key && parent_key){
		data_set_tree_item_dealloc(ds->tree_root,InvokeTickArg);
		ds->tree_root = data_set_tree_item_alloc( NULL, ext_data(ds->data),NULL,NULL,NULL,InvokeTickArg);
		ds->tree_level = 0;
		if(ds->tree_cache == NULL){
			ds->tree_cache = map_alloc( key_hash, key_equal);
		}
		else{
			map_clear(ds->tree_cache);
		}
		items = ext_data(ds->data);
		c = hdata_array_size(ext_data_class(ds->data), items);
		for(i=0;i<c;i++){
			item = hdata_array(ext_data_class(ds->data),items,i);
			k = (*key)(data_set,item,param,InvokeTickArg);
			pk = (*parent_key)(data_set,item,param,InvokeTickArg);
			tree_pitem = map_get(ds->tree_cache, pk);
			tree_item = data_set_tree_item_alloc( k, item, tree_pitem == NULL?ds->tree_root:tree_pitem,comparator,param,InvokeTickArg);
			data_set_tree_item_dealloc( map_put(ds->tree_cache, k, tree_item),InvokeTickArg);
			if(ds->tree_level < tree_item->level){
				ds->tree_level = tree_item->level;
			}
		}
		c = list_count(ds->tree_root->childs);
		for(i=0;i<c;i++){
			tree_item = list_get(ds->tree_root->childs, i);
			pk = (*parent_key)(data_set,tree_item->data,param,InvokeTickArg);
			tree_pitem = map_get(ds->tree_cache, pk);
			if(tree_pitem){
				list_remove_at(ds->tree_root->childs, i--);
				c = list_count(ds->tree_root->childs);
				if(tree_pitem->childs==NULL){
					tree_pitem->childs = list_alloc(20, 20);
				}
				if(comparator){
					compare_param.compare = comparator;
					compare_param.param = param;
					list_add_and_order(tree_pitem->childs, tree_item, data_set_tree_item_compare, &compare_param);
				}
				else{
					list_add(tree_pitem->childs,tree_item);
				}
				tree_item->level = tree_pitem->level +1;
				if(ds->tree_level < tree_item->level){
					ds->tree_level = tree_item->level;
				}
			}	
		}
		return ds->tree_level;
	}
	return 0;
}
Exemplo n.º 2
0
void x86_uop_queue_recover(int core, int thread)
{
	struct list_t *uop_queue = X86_THREAD.uop_queue;
	struct x86_uop_t *uop;

	while (list_count(uop_queue))
	{
		uop = list_get(uop_queue, list_count(uop_queue) - 1);
		assert(uop->thread == thread);
		if (!uop->specmode)
			break;
		list_remove_at(uop_queue, list_count(uop_queue) - 1);
		uop->in_uop_queue = 0;

		/* Trace */
		if (x86_tracing())
		{
			x86_trace("x86.inst id=%lld core=%d stg=\"sq\"\n",
				uop->id_in_core, uop->core);
			x86_cpu_uop_trace_list_add(uop);
		}

		/* Free */
		x86_uop_free_if_not_queued(uop);
	}
}
Exemplo n.º 3
0
void chatserver_free(chatserver_t *csrv)
{
    // Prevents undefined behavior
    if (csrv->priv->stopping == FALSE) {
        perror("Cannot free chatserver_t running instance");
        return;
    }

    pthread_mutex_lock(&csrv->priv->m_cli_list);
    int count = list_getcount(csrv->priv->clientwa_list);
    int i;
    for (i = count - 1; i >= 0; --i) {
        clientwa_t *item = (clientwa_t *)list_remove_at(
            csrv->priv->clientwa_list, i);

        if (item->fd >= 0)
            close(item->fd);
        pchar_ll_free(item->read_list);
        pchar_ll_free(item->write_list);
        free(item);
    }

    list_free(csrv->priv->clientwa_list);
    pthread_mutex_unlock(&csrv->priv->m_cli_list);
    if (pthread_mutex_destroy(&csrv->priv->m_cli_list) != 0) {
        perror("Cannot destroy m_cli_list mutex");
        exit(EXIT_FAILURE);
    }

    free(csrv->priv);

    free(csrv);
}
Exemplo n.º 4
0
static int dispatch_thread(int core, int thread, int quant)
{
	struct uop_t *uop;
	enum di_stall_t stall;

	while (quant) {
		
		/* Check if we can decode */
		stall = can_dispatch_thread(core, thread);
		if (stall != di_stall_used) {
			CORE.di_stall[stall] += quant;
			break;
		}
	
		/* Get entry from uop queue */
		uop = list_remove_at(THREAD.uopq, 0);
		assert(uop_exists(uop));
		uop->in_uopq = 0;
		
		/* Rename */
		rf_rename(uop);
		
		/* Insert in ROB */
		rob_enqueue(uop);
		CORE.rob_writes++;
		THREAD.rob_writes++;
		
		/* Non memory instruction into IQ */
		if (!(uop->flags & X86_UINST_MEM)) {
			iq_insert(uop);
			CORE.iq_writes++;
			THREAD.iq_writes++;
		}
		
		/* Memory instructions into the LSQ */
		if (uop->flags & X86_UINST_MEM) {
			lsq_insert(uop);
			CORE.lsq_writes++;
			THREAD.lsq_writes++;
		}
		
		/* Another instruction dispatched */
		uop->di_seq = ++CORE.di_seq;
		CORE.di_stall[uop->specmode ? di_stall_spec : di_stall_used]++;
		THREAD.dispatched[uop->uinst->opcode]++;
		CORE.dispatched[uop->uinst->opcode]++;
		cpu->dispatched[uop->uinst->opcode]++;
		quant--;

		/* Pipeline debug */
		esim_debug("uop action=\"create\", core=%d, seq=%llu, name=\"%s\","
			" mop_name=\"%s\", mop_count=%d, mop_index=%d, spec=%u,"
			" stg_dispatch=1, in_rob=%u, in_iq=%u, in_lsq=%u\n",
			uop->core, (long long unsigned) uop->di_seq, uop->name,
			uop->mop_name, uop->mop_count, uop->mop_index, uop->specmode,
			!!uop->in_rob, !!uop->in_iq, uop->in_lq || uop->in_sq);
	}

	return quant;
}
Exemplo n.º 5
0
static int X86ThreadDispatch(X86Thread *self, int quantum) {
  X86Core *core = self->core;
  X86Cpu *cpu = self->cpu;

  struct x86_uop_t *uop;
  enum x86_dispatch_stall_t stall;

  while (quantum) {
    /* Check if we can decode */
    stall = X86ThreadCanDispatch(self);
    if (stall != x86_dispatch_stall_used) {
      core->dispatch_stall[stall] += quantum;
      break;
    }

    /* Get entry from uop queue */
    uop = list_remove_at(self->uop_queue, 0);
    assert(x86_uop_exists(uop));
    uop->in_uop_queue = 0;

    /* Rename */
    X86ThreadRenameUop(self, uop);

    /* Insert in ROB */
    X86CoreEnqueueInROB(core, uop);
    core->rob_writes++;
    self->rob_writes++;

    /* Non memory instruction into IQ */
    if (!(uop->flags & X86_UINST_MEM)) {
      X86ThreadInsertInIQ(self, uop);
      core->iq_writes++;
      self->iq_writes++;
    }

    /* Memory instructions into the LSQ */
    if (uop->flags & X86_UINST_MEM) {
      X86ThreadInsertInLSQ(self, uop);
      core->lsq_writes++;
      self->lsq_writes++;
    }

    /* Statistics */
    core->dispatch_stall[uop->specmode ? x86_dispatch_stall_spec
                                       : x86_dispatch_stall_used]++;
    self->num_dispatched_uinst_array[uop->uinst->opcode]++;
    core->num_dispatched_uinst_array[uop->uinst->opcode]++;
    cpu->num_dispatched_uinst_array[uop->uinst->opcode]++;
    if (uop->trace_cache) self->trace_cache->num_dispatched_uinst++;

    /* Another instruction dispatched, update quantum. */
    quantum--;

    /* Trace */
    x86_trace("x86.inst id=%lld core=%d stg=\"di\"\n", uop->id_in_core,
              core->id);
  }

  return quantum;
}
Exemplo n.º 6
0
Arquivo: gpu.c Projeto: abhaykadam/vm
void vgpu_uop_list_clear(struct list_t *list)
{
	struct vgpu_uop_t *uop;
	while (list_count(list)) {
		uop = list_remove_at(list, 0);
		if (uop)
			vgpu_uop_free(uop);
	}
}
Exemplo n.º 7
0
void x86_uinst_clear(void)
{
	/* Clear list */
	while (list_count(x86_uinst_list))
		x86_uinst_free(list_remove_at(x86_uinst_list, 0));
	
	/* Forget occurrence of effective address computation in previous inst */
	x86_uinst_effaddr_emitted = 0;
}
Exemplo n.º 8
0
void x86_opengl_vertex_group_free(struct x86_opengl_vertex_group_t *vtxgp)
{
	/* Free vertices in the list */
	while (list_count(vtxgp->vertex_list))
		x86_opengl_vertex_free(list_remove_at(vtxgp->vertex_list, 0));	

	list_free(vtxgp->vertex_list);
	free(vtxgp);
}
Exemplo n.º 9
0
void *list_dequeue(struct list_t *list)
{
	if (!list->count)
	{
		list->error_code = LIST_ERR_EMPTY;
		return NULL;
	}
	return list_remove_at(list, 0);
}
Exemplo n.º 10
0
static void vi_list_popup_destroy_event(GtkWidget *widget, struct vi_list_popup_t *popup)
{
	/* Free item list */
	while (popup->item_list->count)
		vi_list_item_free(list_remove_at(popup->item_list, 0));
	list_free(popup->item_list);

	/* Free pop-up */
	vi_list_popup_free(popup);
}
Exemplo n.º 11
0
void x86_opengl_matrix_stack_free(struct x86_opengl_matrix_stack_t *mtx_stack)
{
	/* Free matrices in the list */
	while (list_count(mtx_stack->stack))
		x86_opengl_matrix_free(list_remove_at(mtx_stack->stack, 0));
	/* Free list */
	list_free(mtx_stack->stack);
	/* Free stack */
	free(mtx_stack);
}
Exemplo n.º 12
0
void si_bin_file_free(struct si_bin_file_t *bin_file)
{
    /* Free encoding dictionary */
    while (list_count(bin_file->enc_dict))
        free(list_remove_at(bin_file->enc_dict, 0));
    list_free(bin_file->enc_dict);

    /* Free rest */
    elf_file_free(bin_file->elf_file);
    free(bin_file);
}
Exemplo n.º 13
0
void amd_opengl_bin_free(struct amd_opengl_bin_t *amd_opengl_bin)
{
	/* Free shader list */
	while (list_count(amd_opengl_bin->shader_list))
		amd_opengl_shader_free(list_remove_at(amd_opengl_bin->shader_list, 0));
	list_free(amd_opengl_bin->shader_list);	

	/* Free rest */
	free(amd_opengl_bin->name);
	free(amd_opengl_bin);
}
Exemplo n.º 14
0
void x86_opengl_vertex_buffer_free(struct x86_opengl_vertex_buffer_t *vtxbf)
{
	if (vtxbf)
	{
		while (list_count(vtxbf->vertex_groups))
			x86_opengl_vertex_group_free(list_remove_at(vtxbf->vertex_groups, 0));

		list_free(vtxbf->vertex_groups);
		free(vtxbf);
	}
}
Exemplo n.º 15
0
void *list_remove(struct list_t *list, void *elem)
{
	int index;
	
	/* Get index of element */
	index = list_index_of(list, elem);
	if (list->error_code)
		return NULL;
	
	/* Delete element at found position */
	return list_remove_at(list, index);
}
Exemplo n.º 16
0
void X86ThreadFreeFetchQueue(X86Thread *self)
{
    struct list_t *fetchq;
    struct x86_uop_t *uop;

    fetchq = self->fetch_queue;
    while (list_count(fetchq)) {
        uop = list_remove_at(fetchq, 0);
        uop->in_fetch_queue = 0;
        x86_uop_free_if_not_queued(uop);
    }
    list_free(fetchq);
}
Exemplo n.º 17
0
/* Free device */
void cuda_device_free(struct cuda_device_t *device)
{
	CUstream default_stream;

	list_remove(device_list, device);

	default_stream = list_remove_at(device->stream_list, 0);
	cuda_stream_free(default_stream);
	list_free(device->stream_list);
	free(device->name);

	free(device);
}
Exemplo n.º 18
0
void elf_file_free(struct elf_file_t *elf_file)
{
	/* Free symbol table */
	while (list_count(elf_file->symbol_table))
		free(list_remove_at(elf_file->symbol_table, 0));
	list_free(elf_file->symbol_table);

	/* Free section list */
	while (list_count(elf_file->section_list))
		free(list_remove_at(elf_file->section_list, 0));
	list_free(elf_file->section_list);

	/* Free program header list */
	while (list_count(elf_file->program_header_list))
		free(list_remove_at(elf_file->program_header_list, 0));
	list_free(elf_file->program_header_list);

	/* Free rest */
	free(elf_file->buffer.ptr);
	free(elf_file->path);
	free(elf_file);
}
Exemplo n.º 19
0
void trace_done(void)
{
	/* Nothing if trace is inactive */
	if (!trace_file)
		return;

	/* Close trace file */
	gzclose(trace_file);

	/* Free categories */
	while (trace_category_list->count)
		free(list_remove_at(trace_category_list, 0));
	list_free(trace_category_list);
}
Exemplo n.º 20
0
void vi_list_free(struct vi_list_t *list)
{
	/* Item list */
	while (list->item_list->count)
		vi_list_item_free(list_remove_at(list->item_list, 0));
	list_free(list->item_list);

	/* List of elements */
	list_free(list->elem_list);

	/* Object */
	free(list->title);
	free(list);
}
Exemplo n.º 21
0
void x86_uop_queue_done()
{
	int core, thread;
	struct list_t *uop_queue;
	struct x86_uop_t *uop;

	X86_CORE_FOR_EACH X86_THREAD_FOR_EACH
	{
		uop_queue = X86_THREAD.uop_queue;
		while (list_count(uop_queue))
		{
			uop = list_remove_at(uop_queue, 0);
			uop->in_uop_queue = 0;
			x86_uop_free_if_not_queued(uop);
		}
		list_free(uop_queue);
	}
}
Exemplo n.º 22
0
/* Given a buffer and buffer size, create list that contains offsets of external ELF magic bytes in the buffer */
static struct list_t *external_elf_file_list_create(void *ptr_buffer, size_t buf_size)
{
	struct list_t *elf_file_list_external;
	int i;
	int elf_file_size;
	int *offset;

	elf_file_list_external = elf_file_list_create(ptr_buffer, buf_size);

	/* Remove internal ELF from list */
	for (i = 0; i < list_count(elf_file_list_external); i++)
	{
		offset = list_get(elf_file_list_external, i);
		elf_file_size = buf_size - *offset;

		if (is_external_elf(ptr_buffer + *offset, elf_file_size) != 0)
			free(list_remove_at(elf_file_list_external, i));
	}

	return elf_file_list_external;
}
Exemplo n.º 23
0
int main(int argc,char **argv) {
	char *zero, *one, *two, *three, *minusone;
	zero = strdup("Zero");
	one  = strdup("One");
	two  = strdup("Two");
	three = strdup("Three");
	minusone = strdup("-1");
	List *list = list_append(NULL,zero);
	list_append(list,one);
	list_append(list,two);
	list_append(list,three);
	list_remove_at(list,1);
	one = strdup("One");
	list_insert_at(list,1,one);
	list = list_prepend(list,minusone);
	int i;
	for(i = 0;i <= 2; i++) {
		printf("%s\n",(char *)list_get_nth(list,i)->data);
	}
	printf("\n%d\n",list_index_of(list,two));
	return 0;
}
Exemplo n.º 24
0
struct x86_uop_t *X86ThreadRemoveFromFetchQueue(X86Thread *self, int index)
{
    struct list_t *fetchq = self->fetch_queue;
    struct x86_uop_t *uop;
    assert(index >= 0 && index < list_count(fetchq));
    uop = list_remove_at(fetchq, index);
    uop->in_fetch_queue = 0;
    if (!uop->trace_cache && !uop->mop_index)
    {
        self->fetchq_occ -= uop->mop_size;
        assert(self->fetchq_occ >= 0);
    }
    if (uop->trace_cache)
    {
        self->trace_cache_queue_occ--;
        assert(self->trace_cache_queue_occ >= 0);
    }
    if (!list_count(fetchq))
    {
        assert(!self->fetchq_occ);
        assert(!self->trace_cache_queue_occ);
    }
    return uop;
}
Exemplo n.º 25
0
static void elf_file_list_free(struct list_t * elf_file_list)
{
	while (list_count(elf_file_list))
		free(list_remove_at(elf_file_list, 0));
	list_free(elf_file_list);
}
Exemplo n.º 26
0
void *list_pop_back(ADTList list) {
    void *value = list_at(list, -1);
    if (list->head)
        list_remove_at(list, -1);
    return value;
}
Exemplo n.º 27
0
void *list_pop_front(ADTList list) {
    void *value = list_at(list, 0);
    if (list->head)
        list_remove_at(list, 0);
    return value;
}
Exemplo n.º 28
0
void net_read_config(void) {
    struct config_t *config;
    struct list_t *net_name_list;
    char *section;
    int i;

    /* Configuration file */
    if (!*net_config_file_name) {
        net_domain_index = esim_new_domain(net_frequency);
        return;
    }

    /* Open network configuration file */
    config = config_create(net_config_file_name);
    if (*net_config_file_name) config_load(config);

    /* Section with generic configuration parameters */
    section = "General";

    /* Frequency */
    net_frequency = config_read_int(config, section, "Frequency", net_frequency);
    if (!IN_RANGE(net_frequency, 1, ESIM_MAX_FREQUENCY))
        fatal("%s: invalid value for 'Frequency'", net_config_file_name);

    /* Create frequency domain */
    net_domain_index = esim_new_domain(net_frequency);

    /* Create a temporary list of network names found in configuration
     * file */
    net_name_list = list_create();
    for (section = config_section_first(config); section;
            section = config_section_next(config)) {
        char *delim = ".";

        char section_str[MAX_STRING_SIZE];
        char *token;
        char *net_name;

        /* Create a copy of section name */
        snprintf(section_str, sizeof section_str, "%s", section);
        section = section_str;

        /* First token must be 'Network' */
        token = strtok(section, delim);
        if (strcasecmp(token, "Network")) continue;

        /* Second token is network name */
        net_name = strtok(NULL, delim);
        if (!net_name) continue;

        /* No third token */
        token = strtok(NULL, delim);
        if (token) continue;

        /* Insert new network name */
        net_name = xstrdup(net_name);
        list_add(net_name_list, net_name);
    }

    /* Print network names */
    net_debug("%s: loading network configuration file\n", net_config_file_name);
    net_debug("networks found:\n");
    for (i = 0; i < net_name_list->count; i++)
        net_debug("\t%s\n", (char *)list_get(net_name_list, i));
    net_debug("\n");

    /* Load networks */
    net_table = hash_table_create(0, 0);
    for (i = 0; i < net_name_list->count; i++) {
        struct net_t *network;
        char *net_name;

        net_name = list_get(net_name_list, i);
        network = net_create_from_config(config, net_name);

        hash_table_insert(net_table, net_name, network);
    }

    /* Free list of network names and configuration file */
    while (net_name_list->count) free(list_remove_at(net_name_list, 0));
    list_free(net_name_list);
    config_free(config);
}
Exemplo n.º 29
0
int main(void)
{
	printf("初始化LinkedList及其正反两个方向的迭代器...");
	al = list_create(string, LinkedList, NULL);
	fwd = list_iterator(al, Forward);
	bwd = list_iterator(al, Reverse);
	printf("Ok!\n");
	printf("TEST1:空列表时的查询\n");
	show();
	cont();
	printf("TEST2: 用append添加一个元素\n");
	appends(1);
	show();
	cont();
	printf("TEST3: 用remove_at删除一个元素\n");
	printf("删除了%zu个元素\n", list_remove_at(al, 0));
	show();
	cont();
	printf("TEST4: 用insert从头部开始连续添加18个元素\n");
	inserts(18, 0);
	show();
	int pos = 0;
	int from = -1;
	while ((pos = list_search(al, from, Forward, "South Korea", string, 11)) != -1) {
		printf("正向搜索所有韩国: %d\n", pos);
		from = pos + 1;
	}
	from = -1;
	while ((pos = list_search(al, from, Reverse, "Brazil", string, 6)) != -1) {
		printf("反向搜索所有巴西: %d\n", pos);
		from = pos - 1;
	}
	cont();
	printf("TEST5: 用remove删除所有Brazil\n");
	list_remove(al, "Brazil", string, 6);
	show();
	cont();
	printf("TEST6: 用removeall删除所有元素\n");
	list_removeall(al);
	show();
	cont();
	printf("TEST7: 用push连续添加12个元素后进行递增快速排序\n");
	int i, j;
	for (i = 0; i < 12; i++) {
		j = rand() % 16;
		list_push(al, nations[j], string, strlen(nations[j]));
	}
	printf("排序前:\n");
	type();
	printf("排序后:\n");
	list_qsort(al, Asc);
	type();
	printf("二分搜索找韩国: %d\n", list_bi_search(al, "South Korea", string, strlen("South Korea")));
	printf("二分搜索找中国: %d\n", list_bi_search(al, "中华人民共和国", string, strlen("中华人民共和国")));
	cont();
	printf("TEST8: 用enqueue连续添加12个元素后进行递减插入排序\n");
	for (i = 0; i < 12; i++) {
		j = rand() % 16;
		list_enqueue(al, nations[j], string, strlen(nations[j]));
	}
	printf("排序前:\n");
	type();
	printf("排序后:\n");
	list_isort(al, Desc);
	type();
	printf("二分搜索找日本: %d\n", list_bi_search(al, "Japan", string, 5));
	printf("二分搜索找台湾: %d\n", list_bi_search(al, "中华民国", string, strlen("中华民国")));
	printf("反向排列所有元素\n");
	list_reverse(al);
	type();
	printf("二分搜索找韩国: %d\n", list_bi_search(al, "South Korea", string, strlen("South Korea")));
	printf("二分搜索找中国: %d\n", list_bi_search(al, "中华人民共和国", string, strlen("中华人民共和国")));
	printf("二分搜索找日本: %d\n", list_bi_search(al, "Japan", string, 5));
	printf("二分搜索找台湾: %d\n", list_bi_search(al, "中华民国", string, strlen("中华民国")));
	cont();
	printf("TEST9: 用迭代器迭代删除所有元素\n");
	Iterator delit = list_iterator(al, Forward);
	Element ele = NULL;
	while ((ele = it_next(delit))) {
		it_remove(delit);
		printf("删除元素:\"%s\"\n", POINTOF(ele, char));
		free(ele);
	}
	type();
	cont();
	printf("TEST10: 模拟堆栈\n");
	printf("连续PUSH三次:\n");
	j = rand() % 16;
	list_push(al, nations[j], string, strlen(nations[j]));
	type();
	j = rand() % 16;
	list_push(al, nations[j], string, strlen(nations[j]));
	type();
	j = rand() % 16;
	list_push(al, nations[j], string, strlen(nations[j]));
	type();
	printf("用stacktop读取栈顶元素:");
	ele = list_stacktop(al);
	printf(" \"%s\"\n", POINTOF(ele, char));
	free(ele);
	printf("用pop弹空堆栈:\n");
	ele = list_pop(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	ele = list_pop(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	ele = list_pop(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	type();
	cont();
	printf("TEST11: 模拟队列\n");
	printf("连续enqueue三次:\n");
	j = rand() % 16;
	list_enqueue(al, nations[j], string, strlen(nations[j]));
	type();
	j = rand() % 16;
	list_enqueue(al, nations[j], string, strlen(nations[j]));
	type();
	j = rand() % 16;
	list_enqueue(al, nations[j], string, strlen(nations[j]));
	type();
	printf("用queuehead读取栈顶元素:");
	ele = list_queuehead(al);
	printf(" \"%s\"\n", POINTOF(ele, char));
	free(ele);
	printf("用dequeue全部出队:\n");
	ele = list_dequeue(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	ele = list_dequeue(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	ele = list_dequeue(al);
	printf("\"%s\"\n", POINTOF(ele, char));
	free(ele);
	type();
	cont();
	printf("TEST12: 两个列表相加\n");
	Container list2 = list_create(string, LinkedList, NULL);
	appends(9);
	printf("原列表:\n");
	type();
	printf("加上一个空列表:\n");
	list_plus(al, list2);
	type();
	printf("加上一个有9个元素的列表:\n");
	for (i = 0; i < 9; i++) {
		j = rand() % 16;
		list_append(list2, nations[j], string, strlen(nations[j]));
	}
	list_plus(al, list2);
	type();
	cont();
	printf("再减去这个列表:\n");
	list_minus(al, list2);
	type();
	printf("再减去一个空列表:\n");
	Container empty = list_create(string, LinkedList, NULL);
	list_minus(al, empty);
	type();
	cont();
	printf("添加到18个元素后再进行retain操作,类似取交集\n");
	appends(18);
	printf("原列表:\n");
	type();
	printf("list2:\n");
	for (i = 0; i < 9; i++) {
		ele = list_get(list2, i);
		printf("%s, ", POINTOF(ele, char));
		free(ele);
	}
	printf("\n");
	list_retain(al, list2);
	printf("retain后:\n");
	type();
	printf("retain一个空列表:\n");
	list_retain(al, empty);
	type();
	printf("FIN: 销毁列表和迭代器...");
	it_destroy(fwd);
	it_destroy(bwd);
	list_destroy(al);
	list_destroy(list2);
	list_destroy(empty);
	printf("Ok!\n");
	return 0;
}
Exemplo n.º 30
0
void dram_system_read_config(void)
{
	int i ;
	struct config_t *config;
	struct list_t *dram_system_list;
	char *section;

	if (!*dram_config_file_name)
	{
		dram_domain_index = esim_new_domain(dram_frequency);
		return;
	}

	config = config_create(dram_config_file_name);
	if (*dram_config_file_name)
		config_load(config);

	/* Section with Generic Configuration Parameters */
	section = "General";

	/* Frequency */
	dram_frequency = config_read_int(config, section, "Frequency", dram_frequency);
	if (!IN_RANGE(dram_frequency, 1, ESIM_MAX_FREQUENCY))
		fatal("%s: Invalid value for 'Frequency'", dram_config_file_name);

	/* Creating the Frequency Domain */
	dram_domain_index = esim_new_domain(dram_frequency);

	/* Create a temporary List of all Dram Systems found in
	 * the configuration file */
	dram_system_list = list_create();
	for (section = config_section_first(config); section;
			section = config_section_next(config))
	{
		char *delim = ".";

		char section_str[MAX_STRING_SIZE];
		char *token;
		char *dram_system_name;

		/*Creating a copy of the name of the section */
		snprintf(section_str, sizeof section_str, "%s", section);
		section = section_str;

		/* First Token Must be 'DRAMsystem' */
		token = strtok(section, delim);
		if (strcasecmp(token, "DRAMsystem"))
			continue;

		/* Second Token must be the system Name */
		dram_system_name = strtok(NULL, delim);
		if (!dram_system_name)
			continue;

		/* No third term is required */
		token = strtok(NULL, delim);
		if (token)
			continue;

		/* Insert the new DRAM system name */
		dram_system_name = xstrdup(dram_system_name);
		list_add(dram_system_list, dram_system_name);
	}

	/* Print DRAM system Names in debug */
	dram_debug("%s: loading DRAM system configuration file \n",
			dram_config_file_name);
	dram_debug("DRAM systems found:\n");
	for (i = 0; i < dram_system_list->count; i++)
		dram_debug("\t%s\n", (char *) list_get(dram_system_list, i));
	dram_debug("\n");

	/* Load DRAM systems */
	dram_system_table = hash_table_create(0, 0);
	for ( i = 0; i < dram_system_list->count; i++)
	{
		struct dram_system_t *system;
		char *dram_system_name;

		dram_system_name = list_get(dram_system_list, i);
		system = dram_system_config_with_file(config, dram_system_name);

		hash_table_insert(dram_system_table, dram_system_name, system);
	}
	while (dram_system_list->count)
		free(list_remove_at(dram_system_list, 0));
	list_free(dram_system_list);
	config_free(config);
}