Exemplo n.º 1
0
int linked_list_contains(LinkedList *list, void *pattern){
	/**
	 * Checks to see if any entry in the provided list matches the data in
	 * the memory indicated by the provided pointer.
	 */
	return linked_list_find(list, pattern) != -1;
}
Exemplo n.º 2
0
void events_battery_state_service_unsubscribe(EventHandle handle) {
  int16_t index = linked_list_find(s_handler_list, handle);
  if (index == -1) {
    return;
  }
  free(linked_list_get(s_handler_list, index));
  linked_list_remove(s_handler_list, index);
  if (linked_list_count(s_handler_list) == 0) {
    battery_state_service_unsubscribe();
  }
}
Exemplo n.º 3
0
void events_app_message_unsubscribe(EventHandle handle) {
  int16_t index = linked_list_find(s_handler_list, handle);
  if (index == -1) {
    return;
  }
  free(linked_list_get(s_handler_list, index));
  linked_list_remove(s_handler_list, index);
  if (linked_list_count(s_handler_list) == 0) {
    app_message_deregister_callbacks();
  }
}
Exemplo n.º 4
0
void evg_opencl_command_queue_submit(struct evg_opencl_command_queue_t *command_queue,
	struct evg_opencl_command_t *command)
{
	struct linked_list_t *command_list;

	/* Check that command is not enqueued */
	command_list = command_queue->command_list;
	linked_list_find(command_list, command);
	if (!command_list->error_code)
		fatal("%s: command already enqueued", __FUNCTION__);
	
	/* Enqueue command */
	linked_list_add(command_list, command);
}
Exemplo n.º 5
0
void evg_opencl_command_queue_complete(struct evg_opencl_command_queue_t *command_queue,
	struct evg_opencl_command_t *command)
{
	struct linked_list_t *command_list;

	/* Check that command is in command queue */
	command_list = command_queue->command_list;
	linked_list_find(command_list, command);
	if (command_list->error_code)
		fatal("%s: command is not in command queue", __FUNCTION__);
	
	/* Remove command */
	linked_list_remove(command_list);

	/* x86 contexts might be waiting for the command queue to get empty
	 * (e.g., suspended in a 'clFinish' call. Check events. */
	x86_emu_process_events_schedule();
}
Exemplo n.º 6
0
int opengl_vertex_array_obj_repo_remove(struct linked_list_t *vao_repo, struct opengl_vertex_array_obj_t *vao)
{
	if (vao->ref_count != 0)
	{
		opengl_debug("\tVAO #%d [%p] cannot be removed immediately as reference counter = %d\n", 
			vao->id, vao, vao->ref_count);
		return -1;
	}
	else 
	{
		/* Check that VAO exists */
		linked_list_find(vao_repo, vao);
		if (vao_repo->error_code)
			fatal("%s: VAO does not exist", __FUNCTION__);
		linked_list_remove(vao_repo);
		opengl_debug("\tVAO #%d [%p] removed from VAO table [%p]\n", 
			vao->id, vao, vao_repo);
		return 1;
	}
}
Exemplo n.º 7
0
static struct gpu_wavefront_t *gpu_schedule_greedy(struct gpu_compute_unit_t *compute_unit)
{
	struct gpu_wavefront_t *wavefront, *temp_wavefront;
	struct linked_list_t *wavefront_pool = compute_unit->wavefront_pool;

	/* Check all candidates */
	temp_wavefront = NULL;
	LINKED_LIST_FOR_EACH(wavefront_pool)
	{
		/* Get wavefront from list */
		wavefront = linked_list_get(wavefront_pool);
		
		/* Wavefront must be running,
		 * and the corresponding slot in fetch buffer must be free. */
		assert(wavefront->id_in_compute_unit < gpu->wavefronts_per_compute_unit);
		if (!DOUBLE_LINKED_LIST_MEMBER(wavefront->work_group, running, wavefront) ||
			compute_unit->cf_engine.fetch_buffer[wavefront->id_in_compute_unit])
			continue;

		/* Select current wavefront temporarily */
		if (!temp_wavefront || temp_wavefront->sched_when < wavefront->sched_when)
			temp_wavefront = wavefront;
	}

	/* No wavefront found */
	wavefront = NULL;
	if (!temp_wavefront)
		return NULL;

	/* Wavefront found, remove from pool and return. */
	assert(temp_wavefront->clause_kind == GPU_CLAUSE_CF);
	linked_list_find(wavefront_pool, temp_wavefront);
	assert(!wavefront_pool->error_code);
	linked_list_remove(wavefront_pool);
	temp_wavefront->sched_when = gpu->cycle;
	return temp_wavefront;
}
Exemplo n.º 8
0
/* Event handler for EV_MEM_SYSTEM_END_COMMAND.
 * The event data is a string of type 'char *' that needs to be deallocated
 * after processing this event. */
void mem_system_end_command_handler(int event, void *data)
{
	char *command_line = data;
	char command[MAX_STRING_SIZE];

	char msg[MAX_STRING_SIZE];
	char msg_detail[MAX_STRING_SIZE];

	char *msg_str = msg;
	int msg_size = sizeof msg;

	char *msg_detail_str = msg_detail;
	int msg_detail_size = sizeof msg_detail;

	int test_failed;

	struct list_t *token_list;

	/* Split command in tokens, skip command */
	token_list = str_token_list_create(command_line, " ");
	assert(list_count(token_list));

	/* Get command */
	mem_system_command_get_string(token_list, command_line, command, sizeof command);

	/* Messages */
	test_failed = 0;
	*msg_str = '\0';
	*msg_detail_str = '\0';

	/* Command 'SetBlock' */
	if (!strcasecmp(command, "CheckBlock"))
	{
		struct mod_t *mod;

		int set;
		int way;
		int tag;
		int tag_check;

		int state;
		int state_check;

		mod = mem_system_command_get_mod(token_list, command_line);
		mem_system_command_get_set_way(token_list, command_line, mod, &set, &way);
		tag = mem_system_command_get_hex(token_list, command_line);
		state = mem_system_command_get_state(token_list, command_line);
		mem_system_command_end(token_list, command_line);

		/* Check that module serves address */
		if (!mod_serves_address(mod, tag))
			fatal("%s: %s: module does not serve address 0x%x.\n\t> %s",
				__FUNCTION__, mod->name, tag, command_line);

		/* Output */
		str_printf(&msg_str, &msg_size,
			"check module %s, set %d, way %d - state %s, tag 0x%x",
			mod->name, set, way, str_map_value(&cache_block_state_map, state), tag);

		/* Check */
		cache_get_block(mod->cache, set, way, &tag_check, &state_check);
		if (tag != tag_check)
		{
			test_failed = 1;
			str_printf(&msg_detail_str, &msg_detail_size,
				"\ttag 0x%x found, but 0x%x expected\n",
				tag_check, tag);
		}
		if (state != state_check)
		{
			test_failed = 1;
			str_printf(&msg_detail_str, &msg_detail_size,
				"\tstate %s found, but %s expected\n",
				str_map_value(&cache_block_state_map, state_check),
				str_map_value(&cache_block_state_map, state));
		}
	}

	/* Command 'CheckOwner' */
	else if (!strcasecmp(command, "CheckOwner"))
	{
		struct mod_t *mod;
		struct mod_t *owner;
		struct mod_t *owner_check = NULL;

		struct net_node_t *net_node;

		struct dir_entry_t *dir_entry;

		int set;
		int way;

		int sub_block;

		/* Read fields */
		mod = mem_system_command_get_mod(token_list, command_line);
		mem_system_command_get_set_way(token_list, command_line, mod, &set, &way);
		sub_block = mem_system_command_get_sub_block(token_list, command_line, mod, set, way);
		owner = mem_system_command_get_mod(token_list, command_line);
		mem_system_command_end(token_list, command_line);

		/* Get actual owner */
		owner_check = NULL;
		if (mod->dir)
		{
			dir_entry = dir_entry_get(mod->dir, set, way, sub_block);
			if (dir_entry->owner >= 0)
			{
				assert(mod->high_net);
				net_node = list_get(mod->high_net->node_list, dir_entry->owner);
				owner_check = net_node->user_data;
			}
		}

		/* Message */
		str_printf(&msg_str, &msg_size,
			"check owner at module %s, set %d, way %d, subblock %d - %s",
			mod->name, set, way, sub_block, owner ? owner->name : "None");

		/* Check match */
		if (owner != owner_check)
		{
			test_failed = 1;
			str_printf(&msg_detail_str, &msg_detail_size,
				"\towner %s found, but %s expected\n",
				owner_check ? owner_check->name : "None",
				owner ? owner->name : "None");
		}
	}

	/* Command 'CheckSharers' */
	else if (!strcasecmp(command, "CheckSharers"))
	{
		struct mod_t *mod;
		struct mod_t *sharer;

		struct net_node_t *node;

		int set;
		int way;

		int sub_block;
		int node_index;

		struct linked_list_t *sharers_list;
		struct linked_list_t *sharers_check_list;

		/* Read fields */
		mod = mem_system_command_get_mod(token_list, command_line);
		mem_system_command_get_set_way(token_list, command_line, mod, &set, &way);
		sub_block = mem_system_command_get_sub_block(token_list, command_line, mod, set, way);
		mem_system_command_expect(token_list, command_line);

		/* Construct list of expected sharers */
		sharers_list = linked_list_create();
		while (list_count(token_list))
		{
			sharer = mem_system_command_get_mod(token_list, command_line);
			linked_list_add(sharers_list, sharer);
		}

		/* Output */
		str_printf(&msg_str, &msg_size,
			"check sharers at module %s, set %d, way %d, subblock %d - { ",
			mod->name, set, way, sub_block);
		LINKED_LIST_FOR_EACH(sharers_list)
		{
			sharer = linked_list_get(sharers_list);
			if (sharer)
				str_printf(&msg_str, &msg_size, "%s ", sharer->name);
		}
		str_printf(&msg_str, &msg_size, "}");

		/* Construct list of actual sharers */
		sharers_check_list = linked_list_create();
		assert(mod->high_net);
		for (node_index = 0; node_index < mod->high_net->node_count; node_index++)
		{
			if (!dir_entry_is_sharer(mod->dir, set, way, sub_block, node_index))
				continue;
			node = list_get(mod->high_net->node_list, node_index);
			sharer = node->user_data;
			linked_list_add(sharers_check_list, sharer);
		}

		/* Remove in actual sharers everything from expected sharers */
		LINKED_LIST_FOR_EACH(sharers_list)
		{
			/* Get expected sharer */
			sharer = linked_list_get(sharers_list);
			if (!sharer)
				continue;

			/* Check that it's an actual sharer */
			linked_list_find(sharers_check_list, sharer);
			if (sharers_check_list->error_code)
			{
				test_failed = 1;
				str_printf(&msg_detail_str, &msg_detail_size,
					"\tsharer %s expected, but not found\n",
					sharer->name);
			}

			/* Remove from actual sharers */
			linked_list_remove(sharers_check_list);
		}

		/* Check that there is no actual sharer left */
		LINKED_LIST_FOR_EACH(sharers_check_list)
		{
			sharer = linked_list_get(sharers_check_list);
			test_failed = 1;
			str_printf(&msg_detail_str, &msg_detail_size,
				"\tsharer %s found, but not expected\n",
				sharer->name);
		}

		/* Free lists */
		linked_list_free(sharers_list);
		linked_list_free(sharers_check_list);
	}

	/* Command 'CheckLink' */
	else if (!strcasecmp(command, "CheckLink"))
Exemplo n.º 9
0
static char* find_invalid(void) {
  Object* object = create_object(1);
  mu_assert(-1 == linked_list_find(root, object), "Found index for unknown object.");
  return 0;
}
Exemplo n.º 10
0
static char* find_valid(void) {
  Object* object = create_object(1);
  linked_list_append(root, object);
  mu_assert(0 == linked_list_find(root, object), "Could not find object index.");
  return 0;
}