Пример #1
0
static void traverse_elements(void)
{
	struct ht_element *el;
	int c=0;
	struct ast_hashtab_iter *it = ast_hashtab_start_write_traversal(glob_hashtab);
#ifdef DEBUG
	printf("Traverse hashtab\n");
#endif
	while ((el = ast_hashtab_next(it))) {
		c++;
	}
	ast_hashtab_end_traversal(it);
	els_traversals++; /* unprotected, sometimes off, but, not really important, either */
}
Пример #2
0
/*! Continuously iterate through all the entries in the hash */
static void *hash_test_count(void *d)
{
	const struct hash_test *data = d;
	int count = 0;
	int last_count = 0;

	while (count < data->max_grow) {
		struct ast_hashtab_iter *it = ast_hashtab_start_write_traversal(data->to_be_thrashed);
		char *ht = ast_hashtab_next(it);
		last_count = count;
		count = 0;
		while (ht) {
			/* only count keys added by grow thread */
			if (strncmp(ht, "key0", 4) == 0) {
				++count;
			}
			ht = ast_hashtab_next(it);
		}
		ast_hashtab_end_traversal(it);

		if (last_count == count) {
			/* Give other threads ample chance to run, note that using sched_yield here does not
			 * provide enough of a chance and can cause this thread to starve others.
			 */
			usleep(1);
		} else if (last_count > count) {
			/* Make sure the hashtable never shrinks */
			return "hashtab unexpectedly shrank";
		}

		if (is_timed_out(data)) {
			return "Count timed out";
		}
	}

	/* Successfully iterated over all of the expected elements */
	return NULL;
}