Beispiel #1
0
static int file_read_cached(const char *file_name, uint8_t **mem, uint32_t beg, uint32_t len, uint32_t socket, struct hash_set *hs)
{
	if (len == 0) {
		*mem = 0;
		return 0;
	}

	uint8_t *data_mem;

	/* Since the configuration can reference the same file from
	   multiple places, use prox_shared infrastructure to detect
	   this and return previously loaded data. */
	char name[256];

	snprintf(name, sizeof(name), "%u-%u:%s", beg, len, file_name);
	*mem = prox_sh_find_socket(socket, name);
	if (*mem)
		return 0;

	/* check if the file has been loaded on the other socket. */
	if (socket == 1 && (data_mem = prox_sh_find_socket(0, name))) {
		uint8_t *data_find = hash_set_find(hs, data_mem, len);
		if (!data_find) {
			data_find = prox_zmalloc(len, socket);
			PROX_PANIC(data_find == NULL, "Failed to allocate memory (%u bytes) to hold header for peer\n", len);

			rte_memcpy(data_find, data_mem, len);
			hash_set_add(hs, data_find, len);
		}
		*mem = data_find;
		prox_sh_add_socket(socket, name, *mem);
		return 0;
	}

	/* It is possible that a file with a different name contains
	   the same data. In that case, search all loaded files and
	   compare the data to reduce memory utilization.*/
	data_mem = malloc(len);
	PROX_PANIC(data_mem == NULL, "Failed to allocate temporary memory to hold data\n");

	if (file_read_content(file_name, data_mem, beg, len)) {
		plog_err("%s\n", file_get_error());
		return -1;
	}

	uint8_t *data_find = hash_set_find(hs, data_mem, len);
	if (!data_find) {
		data_find = prox_zmalloc(len, socket);
		PROX_PANIC(data_find == NULL, "Failed to allocate memory (%u bytes) to hold header for peer\n", len);

		rte_memcpy(data_find, data_mem, len);
		hash_set_add(hs, data_find, len);
	}

	free(data_mem);

	*mem = data_find;
	prox_sh_add_socket(socket, name, *mem);
	return 0;
}
Beispiel #2
0
bool add_graph_to_level(graph_info *new_graph, level *my_level)
{
	unsigned i = new_graph->m - my_level->min_m;
	
	if(priority_queue_num_elems(my_level->queues[i]) >= my_level->p &&
	   graph_compare_gt(new_graph,
						priority_queue_peek(my_level->queues[i])))
		return false;
	
	if(!new_graph->gcan)
	{
		int m = (new_graph->n + WORDSIZE - 1) / WORDSIZE;
		
		DEFAULTOPTIONS_GRAPH(options);
		statsblk stats;
		setword workspace[m * 50];
		int lab[new_graph->n], ptn[new_graph->n], orbits[new_graph->n];
		new_graph->gcan = malloc(new_graph->n * m * sizeof(setword));
		
		options.getcanon = true;
		
		nauty(new_graph->nauty_graph, lab, ptn, NULL, orbits,
			  &options, &stats, workspace, 50 * m, m, new_graph->n, new_graph->gcan);
	}

	if(!hash_set_add(my_level->sets[i], new_graph))
	{
		//this graph already exists
		return false;
	}
	
	_add_graph_to_level(new_graph, my_level);
	
	return true;
}