#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
Go to the source code of this file.
Data Structures | |
struct | __priv_data |
struct | ao2_container |
struct | astobj2 |
struct | bucket |
struct | bucket_list |
Defines | |
#define | AO2_MAGIC 0xa570b123 |
#define | EXTERNAL_OBJ(_p) ((_p) == NULL ? NULL : (_p)->user_data) |
convert from a pointer _p to an astobj2 object | |
Functions | |
void * | __ao2_link (struct ao2_container *c, void *user_data, int iax2_hack) |
void * | ao2_alloc (size_t data_size, ao2_destructor_fn destructor_fn) |
void | ao2_bt (void) |
void * | ao2_callback (struct ao2_container *c, const enum search_flags flags, ao2_callback_fn cb_fn, void *arg) |
ao2_container * | ao2_container_alloc (const unsigned int n_buckets, ao2_hash_fn hash_fn, ao2_callback_fn cmp_fn) |
int | ao2_container_count (struct ao2_container *c) |
void * | ao2_find (struct ao2_container *c, void *arg, enum search_flags flags) |
ao2_iterator | ao2_iterator_init (struct ao2_container *c, int flags) |
void * | ao2_iterator_next (struct ao2_iterator *a) |
int | ao2_lock (void *user_data) |
int | ao2_match_by_addr (void *user_data, void *arg, int flags) |
another convenience function is a callback that matches on address | |
int | ao2_ref (void *user_data, const int delta) |
int | ao2_trylock (void *user_data) |
void * | ao2_unlink (struct ao2_container *c, void *user_data) |
int | ao2_unlock (void *user_data) |
int | astobj2_init (void) |
static int | cb_true (void *user_data, void *arg, int flags) |
special callback that matches all | |
static int | cd_cb (void *obj, void *arg, int flag) |
static void | container_destruct (void *c) |
static int | hash_zero (const void *user_obj, const int flags) |
always zero hash function | |
static struct astobj2 * | INTERNAL_OBJ (void *user_data) |
convert from a pointer _p to a user-defined object |
#define AO2_MAGIC 0xa570b123 |
#define EXTERNAL_OBJ | ( | _p | ) | ((_p) == NULL ? NULL : (_p)->user_data) |
convert from a pointer _p to an astobj2 object
Definition at line 126 of file astobj2.c.
Referenced by ao2_alloc(), and ao2_callback().
void* __ao2_link | ( | struct ao2_container * | c, | |
void * | user_data, | |||
int | iax2_hack | |||
) |
Definition at line 383 of file astobj2.c.
References ao2_lock(), ao2_ref(), ao2_unlock(), ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, bucket_list::entry, and INTERNAL_OBJ().
Referenced by set_config().
00384 { 00385 int i; 00386 /* create a new list entry */ 00387 struct bucket_list *p; 00388 struct astobj2 *obj = INTERNAL_OBJ(user_data); 00389 00390 if (!obj) 00391 return NULL; 00392 00393 if (INTERNAL_OBJ(c) == NULL) 00394 return NULL; 00395 00396 p = ast_calloc(1, sizeof(*p)); 00397 if (!p) 00398 return NULL; 00399 00400 i = c->hash_fn(user_data, OBJ_POINTER); 00401 00402 ao2_lock(c); 00403 i %= c->n_buckets; 00404 p->astobj = obj; 00405 p->version = ast_atomic_fetchadd_int(&c->version, 1); 00406 if (iax2_hack) 00407 AST_LIST_INSERT_HEAD(&c->buckets[i], p, entry); 00408 else 00409 AST_LIST_INSERT_TAIL(&c->buckets[i], p, entry); 00410 ast_atomic_fetchadd_int(&c->elements, 1); 00411 ao2_ref(user_data, +1); 00412 ao2_unlock(c); 00413 00414 return p; 00415 }
void* ao2_alloc | ( | size_t | data_size, | |
ao2_destructor_fn | destructor_fn | |||
) |
Definition at line 250 of file astobj2.c.
References AO2_MAGIC, ast_atomic_fetchadd_int(), ast_calloc, ast_mutex_init(), and EXTERNAL_OBJ.
Referenced by ao2_container_alloc(), build_peer(), build_user(), conf_run(), create_queue_member(), get_filestream(), moh_class_malloc(), new_iax(), and xml_translate().
00251 { 00252 /* allocation */ 00253 struct astobj2 *obj; 00254 00255 if (data_size < sizeof(void *)) 00256 data_size = sizeof(void *); 00257 00258 obj = ast_calloc(1, sizeof(*obj) + data_size); 00259 00260 if (obj == NULL) 00261 return NULL; 00262 00263 ast_mutex_init(&obj->priv_data.lock); 00264 obj->priv_data.magic = AO2_MAGIC; 00265 obj->priv_data.data_size = data_size; 00266 obj->priv_data.ref_counter = 1; 00267 obj->priv_data.destructor_fn = destructor_fn; /* can be NULL */ 00268 00269 #ifdef AO2_DEBUG 00270 ast_atomic_fetchadd_int(&ao2.total_objects, 1); 00271 ast_atomic_fetchadd_int(&ao2.total_mem, data_size); 00272 ast_atomic_fetchadd_int(&ao2.total_refs, 1); 00273 #endif 00274 00275 /* return a pointer to the user data */ 00276 return EXTERNAL_OBJ(obj); 00277 }
void* ao2_callback | ( | struct ao2_container * | c, | |
const enum search_flags | flags, | |||
ao2_callback_fn | cb_fn, | |||
void * | arg | |||
) |
Browse the container using different stategies accoding the flags.
Definition at line 452 of file astobj2.c.
References ao2_lock(), ao2_ref(), ao2_unlock(), ast_atomic_fetchadd_int(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), bucket_list::astobj, ao2_container::buckets, cb_true(), ao2_container::elements, bucket_list::entry, EXTERNAL_OBJ, free, ao2_container::hash_fn, INTERNAL_OBJ(), last, LOG_WARNING, match(), ao2_container::n_buckets, and ao2_container::version.
Referenced by ao2_find(), ao2_unlink(), ast_moh_destroy(), container_destruct(), delete_users(), load_module(), load_moh_classes(), and unload_module().
00455 { 00456 int i, last; /* search boundaries */ 00457 void *ret = NULL; 00458 00459 if (INTERNAL_OBJ(c) == NULL) /* safety check on the argument */ 00460 return NULL; 00461 00462 if ((flags & (OBJ_MULTIPLE | OBJ_NODATA)) == OBJ_MULTIPLE) { 00463 ast_log(LOG_WARNING, "multiple data return not implemented yet (flags %x)\n", flags); 00464 return NULL; 00465 } 00466 00467 /* override the match function if necessary */ 00468 #if 0 00469 /* Removing this slightly changes the meaning of OBJ_POINTER, but makes it 00470 * do what I want it to. I'd like to hint to ao2_callback that the arg is 00471 * of the same object type, so it can be passed to the hash function. 00472 * However, I don't want to imply that this is the object being searched for. */ 00473 if (flags & OBJ_POINTER) 00474 cb_fn = match_by_addr; 00475 else 00476 #endif 00477 if (cb_fn == NULL) /* if NULL, match everything */ 00478 cb_fn = cb_true; 00479 /* 00480 * XXX this can be optimized. 00481 * If we have a hash function and lookup by pointer, 00482 * run the hash function. Otherwise, scan the whole container 00483 * (this only for the time being. We need to optimize this.) 00484 */ 00485 if ((flags & OBJ_POINTER)) /* we know hash can handle this case */ 00486 i = c->hash_fn(arg, flags & OBJ_POINTER) % c->n_buckets; 00487 else /* don't know, let's scan all buckets */ 00488 i = -1; /* XXX this must be fixed later. */ 00489 00490 /* determine the search boundaries: i..last-1 */ 00491 if (i < 0) { 00492 i = 0; 00493 last = c->n_buckets; 00494 } else { 00495 last = i + 1; 00496 } 00497 00498 ao2_lock(c); /* avoid modifications to the content */ 00499 00500 for (; i < last ; i++) { 00501 /* scan the list with prev-cur pointers */ 00502 struct bucket_list *cur; 00503 00504 AST_LIST_TRAVERSE_SAFE_BEGIN(&c->buckets[i], cur, entry) { 00505 int match = cb_fn(EXTERNAL_OBJ(cur->astobj), arg, flags) & (CMP_MATCH | CMP_STOP); 00506 00507 /* we found the object, performing operations according flags */ 00508 if (match == 0) { /* no match, no stop, continue */ 00509 continue; 00510 } else if (match == CMP_STOP) { /* no match but stop, we are done */ 00511 i = last; 00512 break; 00513 } 00514 /* we have a match (CMP_MATCH) here */ 00515 if (!(flags & OBJ_NODATA)) { /* if must return the object, record the value */ 00516 /* it is important to handle this case before the unlink */ 00517 ret = EXTERNAL_OBJ(cur->astobj); 00518 ao2_ref(ret, 1); 00519 } 00520 00521 if (flags & OBJ_UNLINK) { /* must unlink */ 00522 struct bucket_list *x = cur; 00523 00524 /* we are going to modify the container, so update version */ 00525 ast_atomic_fetchadd_int(&c->version, 1); 00526 AST_LIST_REMOVE_CURRENT(&c->buckets[i], entry); 00527 /* update number of elements and version */ 00528 ast_atomic_fetchadd_int(&c->elements, -1); 00529 ao2_ref(EXTERNAL_OBJ(x->astobj), -1); 00530 free(x); /* free the link record */ 00531 } 00532 00533 if ((match & CMP_STOP) || (flags & OBJ_MULTIPLE) == 0) { 00534 /* We found the only match we need */ 00535 i = last; /* force exit from outer loop */ 00536 break; 00537 } 00538 if (!(flags & OBJ_NODATA)) { 00539 #if 0 /* XXX to be completed */ 00540 /* 00541 * This is the multiple-return case. We need to link 00542 * the object in a list. The refcount is already increased. 00543 */ 00544 #endif 00545 } 00546 } 00547 AST_LIST_TRAVERSE_SAFE_END 00548 } 00549 ao2_unlock(c); 00550 return ret; 00551 }
struct ao2_container* ao2_container_alloc | ( | const unsigned int | n_buckets, | |
ao2_hash_fn | hash_fn, | |||
ao2_callback_fn | cmp_fn | |||
) |
Definition at line 337 of file astobj2.c.
References ao2_alloc(), ast_atomic_fetchadd_int(), ao2_container::cmp_fn, container_destruct(), ao2_container::hash_fn, hash_zero(), ao2_container::n_buckets, and ao2_container::version.
Referenced by init_queue(), load_module(), and xml_translate().
00339 { 00340 /* XXX maybe consistency check on arguments ? */ 00341 /* compute the container size */ 00342 size_t container_size = sizeof(struct ao2_container) + n_buckets * sizeof(struct bucket); 00343 00344 struct ao2_container *c = ao2_alloc(container_size, container_destruct); 00345 00346 if (!c) 00347 return NULL; 00348 00349 c->version = 1; /* 0 is a reserved value here */ 00350 c->n_buckets = n_buckets; 00351 c->hash_fn = hash_fn ? hash_fn : hash_zero; 00352 c->cmp_fn = cmp_fn; 00353 00354 #ifdef AO2_DEBUG 00355 ast_atomic_fetchadd_int(&ao2.total_containers, 1); 00356 #endif 00357 00358 return c; 00359 }
int ao2_container_count | ( | struct ao2_container * | c | ) |
return the number of elements in the container
Definition at line 364 of file astobj2.c.
References ao2_container::elements.
Referenced by __queues_show().
00365 { 00366 return c->elements; 00367 }
void* ao2_find | ( | struct ao2_container * | c, | |
void * | arg, | |||
enum search_flags | flags | |||
) |
the find function just invokes the default callback with some reasonable flags.
Definition at line 556 of file astobj2.c.
References ao2_callback(), and ao2_container::cmp_fn.
Referenced by __find_callno(), authenticate_request(), authenticate_verify(), build_peer(), build_user(), compare_weight(), find_peer(), find_user(), get_mohbyname(), iax2_destroy_helper(), interface_exists_global(), reload_queues(), remove_from_queue(), rt_handle_member_record(), and xml_translate().
00557 { 00558 return ao2_callback(c, flags, c->cmp_fn, arg); 00559 }
struct ao2_iterator ao2_iterator_init | ( | struct ao2_container * | c, | |
int | flags | |||
) |
initialize an iterator so we start from the first object
Definition at line 564 of file astobj2.c.
References ao2_iterator::flags.
Referenced by __iax2_show_peers(), __queues_show(), authenticate_reply(), check_access(), cli_files_show(), complete_iax2_show_peer(), complete_queue_remove_member(), dump_queue_members(), free_members(), get_member_status(), iax2_getpeername(), iax2_getpeertrunk(), iax2_show_users(), interface_exists(), is_our_turn(), manager_queues_status(), moh_classes_show(), poke_all_peers(), prune_peers(), prune_users(), queue_function_queuemembercount(), queue_function_queuememberlist(), reload_queues(), try_calling(), update_realtime_members(), and update_status().
00565 { 00566 struct ao2_iterator a = { 00567 .c = c, 00568 .flags = flags 00569 }; 00570 00571 return a; 00572 }
void* ao2_iterator_next | ( | struct ao2_iterator * | a | ) |
Definition at line 577 of file astobj2.c.
References ao2_lock(), AST_LIST_NEXT, AST_LIST_TRAVERSE, ao2_iterator::bucket, ao2_container::buckets, ao2_iterator::c, ao2_iterator::c_version, bucket_list::entry, F_AO2I_DONTLOCK, ao2_iterator::flags, INTERNAL_OBJ(), ao2_container::n_buckets, ao2_iterator::obj, ao2_container::version, ao2_iterator::version, and bucket_list::version.
Referenced by __iax2_show_peers(), __queues_show(), authenticate_reply(), check_access(), cli_files_show(), complete_iax2_show_peer(), complete_queue_remove_member(), dump_queue_members(), free_members(), get_member_status(), iax2_getpeername(), iax2_getpeertrunk(), iax2_show_users(), interface_exists(), is_our_turn(), manager_queues_status(), moh_classes_show(), poke_all_peers(), prune_peers(), prune_users(), queue_function_queuemembercount(), queue_function_queuememberlist(), reload_queues(), try_calling(), update_realtime_members(), and update_status().
00578 { 00579 int lim; 00580 struct bucket_list *p = NULL; 00581 void *ret = NULL; 00582 00583 if (INTERNAL_OBJ(a->c) == NULL) 00584 return NULL; 00585 00586 if (!(a->flags & F_AO2I_DONTLOCK)) 00587 ao2_lock(a->c); 00588 00589 /* optimization. If the container is unchanged and 00590 * we have a pointer, try follow it 00591 */ 00592 if (a->c->version == a->c_version && (p = a->obj) ) { 00593 if ( (p = AST_LIST_NEXT(p, entry)) ) 00594 goto found; 00595 /* nope, start from the next bucket */ 00596 a->bucket++; 00597 a->version = 0; 00598 a->obj = NULL; 00599 } 00600 00601 lim = a->c->n_buckets; 00602 00603 /* Browse the buckets array, moving to the next 00604 * buckets if we don't find the entry in the current one. 00605 * Stop when we find an element with version number greater 00606 * than the current one (we reset the version to 0 when we 00607 * switch buckets). 00608 */ 00609 for (; a->bucket < lim; a->bucket++, a->version = 0) { 00610 /* scan the current bucket */ 00611 AST_LIST_TRAVERSE(&a->c->buckets[a->bucket], p, entry) { 00612 if (p->version > a->version) 00613 goto found; 00614 } 00615 } 00616 00617 found: 00618 if (p) { 00619 a->version = p->version; 00620 a->obj = p; 00621 a->c_version = a->c->version; 00622 ret = EXTERNAL_OBJ(p->astobj); 00623 /* inc refcount of returned object */ 00624 ao2_ref(ret, 1); 00625 } 00626 00627 if (!(a->flags & F_AO2I_DONTLOCK)) 00628 ao2_unlock(a->c); 00629 00630 return ret; 00631 }
int ao2_lock | ( | void * | user_data | ) |
Definition at line 129 of file astobj2.c.
References ast_atomic_fetchadd_int(), ast_mutex_lock(), INTERNAL_OBJ(), __priv_data::lock, and astobj2::priv_data.
Referenced by __ao2_link(), ao2_callback(), ao2_iterator_next(), moh_release(), mohalloc(), and monmp3thread().
00133 { 00134 struct astobj2 *p = INTERNAL_OBJ(user_data); 00135 00136 if (p == NULL) 00137 return -1; 00138 00139 #ifdef AO2_DEBUG 00140 ast_atomic_fetchadd_int(&ao2.total_locked, 1); 00141 #endif 00142 00143 #ifndef DEBUG_THREADS 00144 return ast_mutex_lock(&p->priv_data.lock); 00145 #else 00146 return __ast_pthread_mutex_lock(file, line, func, var, &p->priv_data.lock); 00147 #endif 00148 }
int ao2_match_by_addr | ( | void * | user_data, | |
void * | arg, | |||
int | flags | |||
) |
another convenience function is a callback that matches on address
Definition at line 420 of file astobj2.c.
Referenced by ao2_unlink().
00421 { 00422 return (user_data == arg) ? (CMP_MATCH | CMP_STOP) : 0; 00423 }
int ao2_ref | ( | void * | user_data, | |
const int | delta | |||
) |
Definition at line 202 of file astobj2.c.
References ast_atomic_fetchadd_int(), ast_log(), ast_mutex_destroy(), __priv_data::data_size, __priv_data::destructor_fn, free, INTERNAL_OBJ(), __priv_data::lock, LOG_ERROR, astobj2::priv_data, and __priv_data::ref_counter.
Referenced by __ao2_link(), __find_callno(), __queues_show(), __unload_module(), add_to_queue(), announce_thread(), ao2_callback(), ast_closestream(), ast_filestream_frame_freed(), ast_readaudio_callback(), ast_readframe(), cd_cb(), compare_weight(), complete_queue_remove_member(), conf_free(), conf_run(), destroy_queue(), dump_queue_members(), free_members(), get_member_status(), hangupcalls(), iax2_destroy(), interface_exists(), interface_exists_global(), is_our_turn(), load_module(), manager_queues_status(), new_iax(), peer_ref(), peer_unref(), queue_function_queuemembercount(), queue_function_queuememberlist(), reload_queues(), remove_from_queue(), rt_handle_member_record(), set_member_paused(), try_calling(), update_realtime_members(), update_status(), user_ref(), user_unref(), and xml_translate().
00203 { 00204 int current_value; 00205 int ret; 00206 struct astobj2 *obj = INTERNAL_OBJ(user_data); 00207 00208 if (obj == NULL) 00209 return -1; 00210 00211 /* if delta is 0, just return the refcount */ 00212 if (delta == 0) 00213 return (obj->priv_data.ref_counter); 00214 00215 /* we modify with an atomic operation the reference counter */ 00216 ret = ast_atomic_fetchadd_int(&obj->priv_data.ref_counter, delta); 00217 current_value = ret + delta; 00218 00219 #ifdef AO2_DEBUG 00220 ast_atomic_fetchadd_int(&ao2.total_refs, delta); 00221 #endif 00222 00223 /* this case must never happen */ 00224 if (current_value < 0) 00225 ast_log(LOG_ERROR, "refcount %d on object %p\n", current_value, user_data); 00226 00227 if (current_value <= 0) { /* last reference, destroy the object */ 00228 if (obj->priv_data.destructor_fn != NULL) 00229 obj->priv_data.destructor_fn(user_data); 00230 00231 ast_mutex_destroy(&obj->priv_data.lock); 00232 #ifdef AO2_DEBUG 00233 ast_atomic_fetchadd_int(&ao2.total_mem, - obj->priv_data.data_size); 00234 ast_atomic_fetchadd_int(&ao2.total_objects, -1); 00235 #endif 00236 /* for safety, zero-out the astobj2 header and also the 00237 * first word of the user-data, which we make sure is always 00238 * allocated. */ 00239 bzero(obj, sizeof(struct astobj2 *) + sizeof(void *) ); 00240 free(obj); 00241 } 00242 00243 return ret; 00244 }
int ao2_trylock | ( | void * | user_data | ) |
Definition at line 151 of file astobj2.c.
References ast_atomic_fetchadd_int(), ast_mutex_trylock(), INTERNAL_OBJ(), __priv_data::lock, and astobj2::priv_data.
00155 { 00156 struct astobj2 *p = INTERNAL_OBJ(user_data); 00157 int res; 00158 00159 if (p == NULL) 00160 return -1; 00161 00162 #ifndef DEBUG_THREADS 00163 res = ast_mutex_trylock(&p->priv_data.lock); 00164 #else 00165 res = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock); 00166 #endif 00167 00168 #ifdef AO2_DEBUG 00169 if (!res) { 00170 ast_atomic_fetchadd_int(&ao2.total_locked, 1); 00171 } 00172 #endif 00173 00174 return res; 00175 }
void* ao2_unlink | ( | struct ao2_container * | c, | |
void * | user_data | |||
) |
Definition at line 429 of file astobj2.c.
References ao2_callback(), ao2_match_by_addr(), and INTERNAL_OBJ().
Referenced by build_user(), free_members(), iax2_prune_realtime(), prune_users(), reload_queues(), remove_by_peercallno(), remove_by_transfercallno(), remove_from_queue(), unlink_peer(), and update_realtime_members().
00430 { 00431 if (INTERNAL_OBJ(user_data) == NULL) /* safety check on the argument */ 00432 return NULL; 00433 00434 ao2_callback(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, ao2_match_by_addr, user_data); 00435 00436 return NULL; 00437 }
int ao2_unlock | ( | void * | user_data | ) |
Definition at line 178 of file astobj2.c.
References ast_atomic_fetchadd_int(), ast_mutex_unlock(), INTERNAL_OBJ(), __priv_data::lock, and astobj2::priv_data.
Referenced by __ao2_link(), ao2_callback(), moh_release(), mohalloc(), and monmp3thread().
00182 { 00183 struct astobj2 *p = INTERNAL_OBJ(user_data); 00184 00185 if (p == NULL) 00186 return -1; 00187 00188 #ifdef AO2_DEBUG 00189 ast_atomic_fetchadd_int(&ao2.total_locked, -1); 00190 #endif 00191 00192 #ifndef DEBUG_THREADS 00193 return ast_mutex_unlock(&p->priv_data.lock); 00194 #else 00195 return __ast_pthread_mutex_unlock(file, line, func, var, &p->priv_data.lock); 00196 #endif 00197 }
int astobj2_init | ( | void | ) |
Definition at line 764 of file astobj2.c.
References ARRAY_LEN, and ast_cli_register_multiple().
Referenced by main().
00765 { 00766 #ifdef AO2_DEBUG 00767 ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2)); 00768 #endif 00769 00770 return 0; 00771 }
static int cb_true | ( | void * | user_data, | |
void * | arg, | |||
int | flags | |||
) | [static] |
special callback that matches all
Definition at line 442 of file astobj2.c.
Referenced by ao2_callback().
static int cd_cb | ( | void * | obj, | |
void * | arg, | |||
int | flag | |||
) | [static] |
Definition at line 636 of file astobj2.c.
References ao2_ref().
Referenced by container_destruct().
00637 { 00638 ao2_ref(obj, -1); 00639 return 0; 00640 }
static void container_destruct | ( | void * | c | ) | [static] |
Definition at line 642 of file astobj2.c.
References ao2_callback(), ast_free, AST_LIST_REMOVE_HEAD, ao2_container::buckets, cd_cb(), bucket_list::entry, and ao2_container::n_buckets.
Referenced by ao2_container_alloc().
00643 { 00644 struct ao2_container *c = _c; 00645 int i; 00646 00647 ao2_callback(c, OBJ_UNLINK, cd_cb, NULL); 00648 00649 for (i = 0; i < c->n_buckets; i++) { 00650 struct bucket_list *cur; 00651 00652 while ((cur = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) { 00653 ast_free(cur); 00654 } 00655 } 00656 00657 #ifdef AO2_DEBUG 00658 ast_atomic_fetchadd_int(&ao2.total_containers, -1); 00659 #endif 00660 }
static int hash_zero | ( | const void * | user_obj, | |
const int | flags | |||
) | [static] |
always zero hash function
it is convenient to have a hash function that always returns 0. This is basically used when we want to have a container that is a simple linked list.
Definition at line 328 of file astobj2.c.
Referenced by ao2_container_alloc().
static struct astobj2* INTERNAL_OBJ | ( | void * | user_data | ) | [inline, static] |
convert from a pointer _p to a user-defined object
Definition at line 103 of file astobj2.c.
References AO2_MAGIC, ast_log(), and LOG_ERROR.
Referenced by __ao2_link(), ao2_callback(), ao2_iterator_next(), ao2_lock(), ao2_ref(), ao2_trylock(), ao2_unlink(), and ao2_unlock().
00104 { 00105 struct astobj2 *p; 00106 00107 if (!user_data) { 00108 ast_log(LOG_ERROR, "user_data is NULL\n"); 00109 return NULL; 00110 } 00111 00112 p = (struct astobj2 *) ((char *) user_data - sizeof(*p)); 00113 if (AO2_MAGIC != (p->priv_data.magic) ) { 00114 ast_log(LOG_ERROR, "bad magic number 0x%x for %p\n", p->priv_data.magic, p); 00115 p = NULL; 00116 } 00117 00118 return p; 00119 }