46#define MAX_HASH_ENTRIES 30000
47#define MAX_TEST_SECONDS 60
70 now.tv_sec, (
long)now.tv_usec,
79 const int buflen = 12;
85 needed = snprintf(keybuf, buflen,
"key%08x", (
unsigned)i);
102 for (i = 0; i < data->
max_grow; ++i) {
105 return "Growth timed out";
109 return "Allocation failed";
122 unsigned seed = time(
NULL);
133 return "Lookup timed out";
143 i = rand_r(&seed) %
max;
146 return "Allocation failed.";
150 if (!is_in_hashtab) {
151 return "key unexpectedly missing";
164 for (i = 1; i < data->
preload; ++i) {
170 return "Allocation failed";
173 deleted = from_hashtab !=
NULL;
178 return "could not delete object";
181 return "Shrink timed out";
201 if (strncmp(ht,
"key0", 4) == 0) {
208 if (last_count == count) {
213 }
else if (last_count > count) {
215 return "hashtab unexpectedly shrank";
219 return "Count timed out";
231 pthread_t grow_thread, count_thread, lookup_thread, shrink_thread;
232 void *thread_results;
237 info->name =
"thrash";
238 info->category =
"/main/hashtab/";
239 info->summary =
"Testing hashtab concurrency";
240 info->description =
"Test hashtab concurrency correctness.";
263 for (i = 1; i < data.
preload; ++i) {
282 pthread_join(grow_thread, &thread_results);
283 if (thread_results !=
NULL) {
285 (
char *)thread_results);
289 pthread_join(count_thread, &thread_results);
290 if (thread_results !=
NULL) {
292 (
char *)thread_results);
296 pthread_join(lookup_thread, &thread_results);
297 if (thread_results !=
NULL) {
299 (
char *)thread_results);
303 pthread_join(shrink_thread, &thread_results);
304 if (thread_results !=
NULL) {
306 (
char *)thread_results);
312 "Invalid hashtab size. Expected: %d, Actual: %d\n",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_malloc(len)
A wrapper for malloc()
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
unsigned int ast_hashtab_hash_string_nocase(const void *obj)
Hashes a string to a number ignoring case.
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
#define ast_hashtab_start_write_traversal(tab)
int ast_hashtab_compare_strings_nocase(const void *a, const void *b)
Compares two strings for equality, ignoring case.
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
#define ast_hashtab_insert_immediate(tab, obj)
Insert without checking.
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
void * ast_hashtab_next(struct ast_hashtab_iter *it)
Gets the next object in the list, advances iter one step returns null on end of traversal.
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
#define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking)
Create the hashtable list.
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
void * ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj)
Looks up the object, removes the corresponding bucket.
Asterisk locking-related definitions:
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
an iterator for traversing the buckets
struct ast_hashtab * to_be_thrashed
struct ao2_container * to_be_thrashed
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
static void * hash_test_lookup(void *d)
static void * hash_test_shrink(void *d)
static int is_timed_out(struct hash_test const *data)
static void ht_delete(void *obj)
Free test element.
static void * hash_test_count(void *d)
AST_TEST_DEFINE(hash_test)
static char * ht_new(int i)
Create test element.
static int load_module(void)
static int unload_module(void)
static void * hash_test_grow(void *d)
Grow the hash data as specified.
Time-related functions and macros.
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
#define ast_pthread_create(a, b, c, d)