struct evg_compute_unit_t *evg_compute_unit_create() { struct evg_compute_unit_t *compute_unit; char buf[MAX_STRING_SIZE]; /* Initialize */ compute_unit = xcalloc(1, sizeof(struct evg_compute_unit_t)); compute_unit->wavefront_pool = linked_list_create(); /* Local memory */ snprintf(buf, sizeof buf, "LocalMemory[%d]", compute_unit->id); compute_unit->local_memory = mod_create(buf, mod_kind_local_memory, evg_gpu_local_mem_num_ports, evg_gpu_local_mem_block_size, evg_gpu_local_mem_latency); /* Initialize CF Engine */ compute_unit->cf_engine.complete_queue = linked_list_create(); compute_unit->cf_engine.fetch_buffer = xcalloc(evg_gpu_max_wavefronts_per_compute_unit, sizeof(void *)); compute_unit->cf_engine.inst_buffer = xcalloc(evg_gpu_max_wavefronts_per_compute_unit, sizeof(void *)); /* Initialize ALU Engine */ compute_unit->alu_engine.pending_queue = linked_list_create(); compute_unit->alu_engine.finished_queue = linked_list_create(); compute_unit->alu_engine.fetch_queue = linked_list_create(); compute_unit->alu_engine.event_queue = heap_create(10); /* Initialize TEX Engine */ compute_unit->tex_engine.pending_queue = linked_list_create(); compute_unit->tex_engine.finished_queue = linked_list_create(); compute_unit->tex_engine.fetch_queue = linked_list_create(); compute_unit->tex_engine.load_queue = linked_list_create(); /* Return */ compute_unit->work_groups = xcalloc(evg_gpu_max_work_groups_per_compute_unit, sizeof(void *)); return compute_unit; }
struct x86_loader_t *x86_loader_create(void) { struct x86_loader_t *loader; /* Initialize */ loader = xcalloc(1, sizeof(struct x86_loader_t)); loader->args = linked_list_create(); loader->env = linked_list_create(); /* Return */ return loader; }
void frm_emu_init(void) { /* Register architecture */ frm_emu_arch = arch_list_register("Fermi", "frm"); frm_emu_arch->sim_kind = frm_emu_sim_kind; /* Allocate */ frm_emu = xcalloc(1, sizeof(struct frm_emu_t)); if (!frm_emu) fatal("%s: out of memory", __FUNCTION__); /* Initialize */ frm_emu->const_mem = mem_create(); frm_emu->const_mem->safe = 0; frm_emu->global_mem = mem_create(); frm_emu->global_mem->safe = 0; frm_emu->total_global_mem_size = 1 << 31; /* 2GB */ frm_emu->free_global_mem_size = frm_emu->total_global_mem_size; frm_emu->global_mem_top = 0; frm_disasm_init(); frm_isa_init(); /* Create device */ frm_cuda_object_list = linked_list_create(); frm_cuda_device_create(); }
void EvgGpuCreate(EvgGpu *self) { struct evg_compute_unit_t *compute_unit; int compute_unit_id; /* Parent */ TimingCreate(asTiming(self)); /* Frequency */ asTiming(self)->frequency = evg_gpu_frequency; asTiming(self)->frequency_domain = esim_new_domain(evg_gpu_frequency); /* Initialize */ self->trash_uop_list = linked_list_create(); self->compute_units = xcalloc(evg_gpu_num_compute_units, sizeof(void *)); EVG_GPU_FOREACH_COMPUTE_UNIT(compute_unit_id) { self->compute_units[compute_unit_id] = evg_compute_unit_create(); compute_unit = self->compute_units[compute_unit_id]; compute_unit->id = compute_unit_id; DOUBLE_LINKED_LIST_INSERT_TAIL(self, ready, compute_unit); } /* Virtual functions */ asObject(self)->Dump = EvgGpuDump; asTiming(self)->DumpSummary = EvgGpuDumpSummary; asTiming(self)->Run = EvgGpuRun; asTiming(self)->MemConfigCheck = EvgGpuMemConfigCheck; asTiming(self)->MemConfigDefault = EvgGpuMemConfigDefault; asTiming(self)->MemConfigParseEntry = EvgGpuMemConfigParseEntry; }
/** * see section 3.8.3 of TCG TNC IF-IMC Specification 1.3 */ TNC_Result TNC_IMC_BeginHandshake(TNC_IMCID imc_id, TNC_ConnectionID connection_id) { TNC_Result result = TNC_RESULT_SUCCESS; if (!imc_android) { DBG1(DBG_IMC, "IMC \"%s\" has not been initialized", imc_name); return TNC_RESULT_NOT_INITIALIZED; } if (lib->settings->get_bool(lib->settings, "android.imc.send_os_info", TRUE)) { linked_list_t *attr_list; attr_list = linked_list_create(); add_product_info(attr_list); add_string_version(attr_list); result = imc_android->send_message(imc_android, connection_id, FALSE, 0, TNC_IMVID_ANY, attr_list); attr_list->destroy(attr_list); } return result; }
END_TEST START_TEST(test_nested_reset) { linked_list_t *list, *l1, *l2, *l3; enumerator_t *outer, *enumerator; intptr_t x; int count = 0; l1 = linked_list_create_with_items((void*)1, (void*)2, NULL); l2 = linked_list_create(); l3 = linked_list_create_with_items((void*)3, (void*)4, (void*)5, NULL); list = linked_list_create_with_items(l1, l2, l3, NULL); outer = list->create_enumerator(list); enumerator = enumerator_create_nested(outer, (void*)create_inner, (void*)101, destroy_data); while (enumerator->enumerate(enumerator, &x)) { count++; } ck_assert_int_eq(count, 5); list->reset_enumerator(list, outer); ck_assert(enumerator->enumerate(enumerator, &x)); ck_assert_int_eq(x, 1); enumerator->destroy(enumerator); list->destroy(list); l1->destroy(l1); l2->destroy(l2); l3->destroy(l3); }
static void si_gpu_device_init() { struct si_compute_unit_t *compute_unit; int compute_unit_id; /* Create device */ si_gpu = calloc(1, sizeof(struct si_gpu_t)); if (!si_gpu) fatal("%s: out of memory", __FUNCTION__); /* Initialize */ si_gpu->trash_uop_list = linked_list_create(); /* Create compute units */ si_gpu->compute_units = calloc(si_gpu_num_compute_units, sizeof(void *)); if (!si_gpu->compute_units) fatal("%s: out of memory", __FUNCTION__); /* Initialize compute units */ SI_GPU_FOREACH_COMPUTE_UNIT(compute_unit_id) { si_gpu->compute_units[compute_unit_id] = si_compute_unit_create(); compute_unit = si_gpu->compute_units[compute_unit_id]; compute_unit->id = compute_unit_id; DOUBLE_LINKED_LIST_INSERT_TAIL(si_gpu, compute_unit_ready, compute_unit); } /* Trace */ si_trace_header("si.init version=\"%d.%d\" num_compute_units=%d\n", SI_TRACE_VERSION_MAJOR, SI_TRACE_VERSION_MINOR, si_gpu_num_compute_units); }
/* Initialize GPU kernel */ void gk_init() { /* Open report file */ if (gpu_kernel_report_file_name[0]) { gpu_kernel_report_file = open_write(gpu_kernel_report_file_name); if (!gpu_kernel_report_file) fatal("%s: cannot open GPU report file ", gpu_kernel_report_file_name); } /* Initialize kernel */ gk = calloc(1, sizeof(struct gk_t)); gk->const_mem = mem_create(); gk->const_mem->safe = 0; gk->global_mem = mem_create(); gk->global_mem->safe = 0; /* Initialize disassembler (decoding tables...) */ amd_disasm_init(); /* Initialize ISA (instruction execution tables...) */ gpu_isa_init(); /* Create platform and device */ opencl_object_list = linked_list_create(); opencl_platform = opencl_platform_create(); opencl_device_create(); }
int test_list_int() { linked_list_t *list; linked_list_cursor_t *cursor; int i, data; // create a new list list = linked_list_create( NULL, /* original list */ linked_list_int_cmp, /* default int comparator */ LINKED_LIST_SORTED /* sort list */ ); // add 10 entries for (i = 0; i < 10; i++) { linked_list_append(list, (void *)i, (void *)i); } // create a cursor for cycling/searching cursor = linked_list_cursor_create(NULL, list); // walk trough listh for (LINKED_LIST_FORLOOP(cursor, &data)) { printf("%d\n", data); } }
PUBLIC void ui_init(unsigned short screenWidth, unsigned short screenHeight, unsigned short canvasWidth, unsigned short canvasHeight) { ui.linked_view = linked_list_create(NULL); ui.viewWidth = canvasWidth; ui.viewHeight = canvasHeight; ui.sys = NULL; xRaito = ((float)canvasWidth / screenWidth); yRaito = ((float)canvasHeight / screenHeight); return; }
struct linked_list_t *opengl_vertex_array_obj_repo_create() { struct linked_list_t *lst; /* Allocate */ lst = linked_list_create(); opengl_debug("\tCreated VAO repository [%p]\n", lst); /* Return */ return lst; }
int main (int argc, char ** argv) { if (argc != 2) { fprintf (stderr, "usage: %s <N>\n", argv[0]); return 1; } int N = atoi (argv[1]); if (N < 1) return 1; int count = 0; for (int i = 1; i <= N; i++) { cf_sqrt_step_t frac; frac.num = i; frac.step = 0; linked_list_t * fractions = linked_list_create (); // All quadratic irrationals must eventually reach a cycle while (cf_expand_sqrt_continued_fraction (&frac)) { cf_sqrt_step_t * f = NULL; bool cycle_found = false; while ((f = linked_list_next (fractions, cf_sqrt_step_t)) != NULL) if (cf_sqrt_steps_identical (f, &frac)) { cycle_found = true; int cycle_len = frac.step - f->step; if (cycle_len % 2 == 1) count++; linked_list_stop_iteration (fractions); break; } if (!cycle_found) linked_list_add_copy (fractions, &frac, cf_sqrt_step_t); else break; } linked_list_free (fractions); } printf ("%d\n", count); return 0; }
struct arch_t *arch_create(char *name, char *prefix) { struct arch_t *arch; /* Initialize */ arch = xcalloc(1, sizeof(struct arch_t)); arch->name = xstrdup(name); arch->prefix = xstrdup(prefix); arch->mem_entry_mod_list = linked_list_create(); /* Return */ return arch; }
void X86CpuCreate(X86Cpu *self, X86Emu *emu) { X86Core *core; X86Thread *thread; char name[MAX_STRING_SIZE]; int i; int j; /* Parent */ TimingCreate(asTiming(self)); /* Frequency */ asTiming(self)->frequency = x86_cpu_frequency; asTiming(self)->frequency_domain = esim_new_domain(x86_cpu_frequency); /* Initialize */ self->emu = emu; self->uop_trace_list = linked_list_create(); /* Create cores */ self->cores = xcalloc(x86_cpu_num_cores, sizeof(X86Core *)); for (i = 0; i < x86_cpu_num_cores; i++) self->cores[i] = new (X86Core, self); /* Assign names and IDs to cores and threads */ for (i = 0; i < x86_cpu_num_cores; i++) { core = self->cores[i]; snprintf(name, sizeof name, "c%d", i); X86CoreSetName(core, name); core->id = i; for (j = 0; j < x86_cpu_num_threads; j++) { thread = core->threads[j]; snprintf(name, sizeof name, "c%dt%d", i, j); X86ThreadSetName(thread, name); thread->id_in_core = j; thread->id_in_cpu = i * x86_cpu_num_threads + j; } } /* Virtual functions */ asObject(self)->Dump = X86CpuDump; asTiming(self)->DumpSummary = X86CpuDumpSummary; asTiming(self)->Run = X86CpuRun; asTiming(self)->MemConfigCheck = X86CpuMemConfigCheck; asTiming(self)->MemConfigDefault = X86CpuMemConfigDefault; asTiming(self)->MemConfigParseEntry = X86CpuMemConfigParseEntry; /* Trace */ x86_trace_header("x86.init version=\"%d.%d\" num_cores=%d num_threads=%d\n", X86_TRACE_VERSION_MAJOR, X86_TRACE_VERSION_MINOR, x86_cpu_num_cores, x86_cpu_num_threads); }
int test_list_char() { linked_list_t *list; linked_list_cursor_t *cursor; int i; char *data; // create a new list list = linked_list_create( NULL, /* original list */ linked_list_char_cmp, /* default char comparator */ LINKED_LIST_SORTED /* sort list */ ); // add 5 entries for (i = 0; i < 5; i++) { data = (char *)malloc(10); sprintf(data, "item %i", i); linked_list_append(list, (void *)data, (void *)data); } // create a cursor for cycling/searching cursor = linked_list_cursor_create(NULL, list); // walk trough listh for (LINKED_LIST_FORLOOP(cursor, &data)) printf("%s\n", data); // scroll to item 4 printf("finding 'item 4'\n"); if (linked_list_cursor_find(cursor, "item 4") != 1) { printf("didn't find item item 4\n"); return; } printf("replacing item 'item 4' with 'item 4 (new)'\n"); // replace it linked_list_cursor_replace(cursor, "item 4", "item 4 (new)"); printf("done\n"); // show it again for (LINKED_LIST_FORLOOP(cursor, &data)) printf("%s\n", data); printf("deleting 'item 2'\n"); linked_list_cursor_find(cursor, "item 2"); linked_list_cursor_delete(cursor); // and again for (LINKED_LIST_FORLOOP(cursor, &data)) printf("%s\n", data); }
struct si_work_item_t *si_work_item_create() { struct si_work_item_t *work_item; /* Initialize */ work_item = xcalloc(1, sizeof(struct si_work_item_t)); work_item->write_task_list = linked_list_create(); work_item->lds_oqa = list_create(); work_item->lds_oqb = list_create(); /* Return */ return work_item; }
/* Create a command queue */ struct evg_opencl_command_queue_t *evg_opencl_command_queue_create() { struct evg_opencl_command_queue_t *command_queue; /* Initialize */ command_queue = xcalloc(1, sizeof(struct evg_opencl_command_queue_t)); command_queue->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo, evg_opencl_object_command_queue); command_queue->ref_count = 1; command_queue->command_list = linked_list_create(); /* Return */ evg_opencl_repo_add_object(evg_emu->opencl_repo, command_queue); return command_queue; }
static void* testing(void *thread) { int i; host_t *addr[ALLOCS]; identification_t *id[ALLOCS]; linked_list_t *pools; /* prepare identities */ for (i = 0; i < ALLOCS; i++) { char buf[256]; snprintf(buf, sizeof(buf), "*****@*****.**", (uintptr_t)thread, i); id[i] = identification_create_from_string(buf); } pools = linked_list_create(); pools->insert_last(pools, "test"); /* allocate addresses */ for (i = 0; i < ALLOCS; i++) { addr[i] = hydra->attributes->acquire_address(hydra->attributes, pools, id[i], NULL); if (!addr[i]) { pools->destroy(pools); return (void*)FALSE; } } /* release addresses */ for (i = 0; i < ALLOCS; i++) { hydra->attributes->release_address(hydra->attributes, pools, addr[i], id[i]); } pools->destroy(pools); /* cleanup */ for (i = 0; i < ALLOCS; i++) { addr[i]->destroy(addr[i]); id[i]->destroy(id[i]); } return (void*)TRUE; }
int main() { linked_list_cell *pos; linked_list *lista; char *ptr = NULL; char *hauki = "hauki!!!"; register unsigned int beta = 0; lista = linked_list_create(); linked_list_add_data(lista, hauki); linked_list_add_data(lista, "kissa"); linked_list_add_data(lista, "haukka"); // An example shuffling through the values of the list while((pos = linked_list_cycle(lista, pos)) != NULL) { printf("%d. %s\n", beta, pos->Data); beta++; } // get "precise" data printf("yksitellen: %s\n", (char *) linked_list_get_pos(lista, 0)); printf("yksitellen: %s\n", (char *) linked_list_get_pos(lista, 2)); printf("yksitellen: %s\n", (char *) linked_list_get_pos(lista, 1)); linked_list_delete_data(lista, hauki); linked_list_add_data(lista, hauki); linked_list_add_pos(lista, "lehmä",2); beta = 0; while(1) { ptr = linked_list_cycle(lista, ptr); if(ptr == NULL) break; printf("%d. %s\n", beta, ptr); beta++; } linked_list_delete(lista); return 0; }
void sim_node_define_context(int count, ...){ va_list context_vars; va_start(context_vars, count); while(count--){ uint8_t *context_var; context_var = va_arg(context_vars, uint8_t *); if(sim_node_context_vars_g == NULL) sim_node_context_vars_g = linked_list_create(context_var); else sim_node_context_vars_g = linked_list_add(sim_node_context_vars_g, context_var); } va_end(context_vars); }
void GlutDriverCreate(GlutDriver *self, X86Emu *emu) { /* Parent */ DriverCreate(asDriver(self), emu); /* Assign driver to host emulator */ emu->glut_driver = self; /* Initialize GLUT global mutex */ pthread_mutex_init(&glut_mutex, NULL); /* Frame buffer */ glut_frame_buffer_init(); /* List of events */ glut_event_list = linked_list_create(); }
event_list_t * event_check(event_t * event, SYSTEMTIME * ntime, SYSTEMTIME * otime) { linked_list_node_t * node = linked_list_first(event->all_event); linked_list_free(event->el.list); linked_list_create(&event->el.list); for(node; node; node = linked_list_next(node)) { struct event_em_t * em = (struct event_em_t *)linked_list_data(node); if(event_em_compare(em, ntime, otime)) linked_list_insert(event->el.list, 0, em); } return &event->el; }
/** * Get a TCP or UDP port list from strongswan.conf */ static linked_list_t* get_port_list(char *label) { char key[40], *value; linked_list_t *list; chunk_t port_list, port_item, port_start; port_range_t *port_range; list = linked_list_create(); snprintf(key, sizeof(key), "libimcv.plugins.imv-scanner.%s_ports", label); value = lib->settings->get_str(lib->settings, key, NULL); if (!value) { DBG1(DBG_IMV, "%s not defined", key); return list; } port_list = chunk_create(value, strlen(value)); DBG2(DBG_IMV, "list of %s ports that %s:", label, closed_port_policy ? "are allowed to be open" : "must be closed"); while (eat_whitespace(&port_list)) { if (!extract_token(&port_item, ' ', &port_list)) { /* reached last port item */ port_item = port_list; port_list = chunk_empty; } port_range = malloc_thing(port_range_t); port_range->start = atoi(port_item.ptr); if (extract_token(&port_start, '-', &port_item) && port_item.len) { port_range->stop = atoi(port_item.ptr); } else { port_range->stop = port_range->start; } DBG2(DBG_IMV, "%5u - %5u", port_range->start, port_range->stop); list->insert_last(list, port_range); } return list; }
linked_list_t *sim_nodes_alloc(int count){ linked_list_t *sim_nodes = NULL; sim_node_t *sim_node = NULL; while(count--){ if(!(sim_node = malloc(sizeof(sim_node_t)))){ puts("unable to allocate memory for sim_node_t"); exit(1); } // TODO // node could be abstracted by building // a node_init function // (having nodes with different hardware...) // brightness fifo fifo_init(&sim_node->node.brightness_buffer); // data fifos fifo_init(&sim_node->node.data_rx_buffer); fifo_init(&sim_node->node.data_tx_buffer); // address sim_node->node.address = count; sim_node->node.address_max = PIXEL_COUNT; // animation register // sim node context... sim_node->node_context = sim_node_alloc_context(); // run node setup sim_node_load_context(sim_node->node_context); node_setup(&sim_node->node); sim_node_save_context(sim_node->node_context); if(sim_nodes == NULL) sim_nodes = linked_list_create(sim_node); else sim_nodes = linked_list_add(sim_nodes, sim_node); } return sim_nodes; }
void esim_init() { /* Create structures */ esim_event_info_list = list_create(); esim_event_heap = heap_create(20); esim_end_event_list = linked_list_create(); /* List of frequency domains */ esim_domain_list = list_create(); list_add(esim_domain_list, NULL); /* Initialize global timer */ esim_timer = m2s_timer_create(NULL); m2s_timer_start(esim_timer); /* Register special events */ ESIM_EV_INVALID = esim_register_event_with_name(NULL, 0, "Invalid"); ESIM_EV_NONE = esim_register_event_with_name(NULL, 0, "None"); }
/* Create a command queue */ struct evg_opencl_command_queue_t *evg_opencl_command_queue_create() { struct evg_opencl_command_queue_t *command_queue; /* Allocate */ command_queue = calloc(1, sizeof(struct evg_opencl_command_queue_t)); if (!command_queue) fatal("%s: out of memory", __FUNCTION__); /* Initialize */ command_queue->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo, evg_opencl_object_command_queue); command_queue->ref_count = 1; command_queue->command_list = linked_list_create(); /* Return */ evg_opencl_repo_add_object(evg_emu->opencl_repo, command_queue); return command_queue; }
int main (int argc, char ** argv) { if (argc != 2) { fprintf (stderr, "usage: %s <N>\n", argv[0]); return 1; } int N = atoi (argv[1]); bool * sieve = eratosthenes_sieve (PRIMES_PRODUCT_LIMIT); size_t primes_count = count_primes (sieve, N); if (primes_count == 0) { printf ("0\n"); return 0; } int primes[primes_count]; int powers[primes_count]; fill_factor_arrays (primes, powers, sieve, primes_count); free (sieve); linked_list_t * pseudo_fortunates = linked_list_create (); int prime = 0; while ((prime = next_prime (primes, powers, primes_count, N)) > 0) { int val = find_pseudo_fortunate (prime); linked_list_add_sorted (pseudo_fortunates, copy_int (val), int_cmp, true); } int sum = linked_list_sum_int (pseudo_fortunates); printf ("%d\n", sum); linked_list_free (pseudo_fortunates); return 0; }
/* Initialization */ void x86_cpu_init() { int core; /* Trace */ x86_trace_category = trace_new_category(); /* Register architecture */ x86_emu_arch->mem_config_check_func = x86_mem_config_check; x86_emu_arch->mem_config_default_func = x86_mem_config_default; x86_emu_arch->mem_config_parse_entry_func = x86_mem_config_parse_entry; /* Analyze CPU configuration file */ x86_cpu_config_check(); /* Initialize */ x86_cpu = xcalloc(1, sizeof(struct x86_cpu_t)); x86_cpu->uop_trace_list = linked_list_create(); /* Initialize cores */ x86_cpu->core = xcalloc(x86_cpu_num_cores, sizeof(struct x86_core_t)); X86_CORE_FOR_EACH x86_cpu_core_init(core); /* Components of an x86 CPU */ x86_reg_file_init(); x86_bpred_init(); x86_trace_cache_init(); x86_fetch_queue_init(); x86_uop_queue_init(); x86_rob_init(); x86_iq_init(); x86_lsq_init(); x86_event_queue_init(); x86_fu_init(); /* Trace */ x86_trace_header("x86.init version=\"%d.%d\" num_cores=%d num_threads=%d\n", X86_TRACE_VERSION_MAJOR, X86_TRACE_VERSION_MINOR, x86_cpu_num_cores, x86_cpu_num_threads); }
/** * Create a list of currently loaded pools */ static linked_list_t* list_pools(vici_conn_t *conn, command_format_options_t format) { linked_list_t *list; vici_res_t *res; list = linked_list_create(); res = vici_submit(vici_begin("get-pools"), conn); if (res) { if (format & COMMAND_FORMAT_RAW) { vici_dump(res, "get-pools reply", format & COMMAND_FORMAT_PRETTY, stdout); } vici_parse_cb(res, list_pool, NULL, NULL, list); vici_free_res(res); } return list; }
END_TEST START_TEST(test_insert_before_empty) { enumerator_t *enumerator; intptr_t x; list->destroy(list); list = linked_list_create(); enumerator = list->create_enumerator(list); list->insert_before(list, enumerator, (void*)1); ck_assert_int_eq(list->get_count(list), 1); ck_assert(list->get_first(list, (void*)&x) == SUCCESS); ck_assert_int_eq(x, 1); ck_assert(list->get_last(list, (void*)&x) == SUCCESS); ck_assert_int_eq(x, 1); ck_assert(enumerator->enumerate(enumerator, &x)); ck_assert_int_eq(x, 1); ck_assert(!enumerator->enumerate(enumerator, NULL)); enumerator->destroy(enumerator); }