Thu Mar 25 12:09:45 2010

Asterisk developer's documentation


astobj2.c File Reference

#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_containerao2_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)
void ao2_iterator_destroy (struct ao2_iterator *i)
 Destroy a container iterator.
ao2_iterator ao2_iterator_init (struct ao2_container *c, int flags)
 Create an iterator for a container.
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 astobj2INTERNAL_OBJ (void *user_data)
 convert from a pointer _p to a user-defined object


Define Documentation

#define AO2_MAGIC   0xa570b123

Definition at line 49 of file astobj2.c.

Referenced by ao2_alloc(), and INTERNAL_OBJ().

#define EXTERNAL_OBJ ( _p   )     ((_p) == NULL ? NULL : (_p)->user_data)

convert from a pointer _p to an astobj2 object

Returns:
the pointer to the user-defined portion.

Definition at line 126 of file astobj2.c.

Referenced by ao2_alloc(), and ao2_callback().


Function Documentation

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 = abs(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 add_calltoken_ignore(), alloc_queue(), ao2_container_alloc(), build_callno_limits(), build_peer(), build_user(), conf_run(), create_callno_pools(), create_queue_member(), get_filestream(), moh_class_malloc(), new_iax(), peercnt_add(), 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_bt ( void   ) 

Definition at line 77 of file astobj2.c.

00077 {}

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.

Returns:
Is a pointer to an object or to a list of object if OBJ_MULTIPLE is specified.

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(), calltoken_required(), container_destruct(), delete_users(), load_module(), load_moh_classes(), reload_config(), set_config_destroy(), set_peercnt_limit(), and unload_module().

00455 {
00456    int i, start, 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       start = i = c->hash_fn(arg, flags & OBJ_POINTER) % c->n_buckets;
00487    else        /* don't know, let's scan all buckets */
00488       start = i = -1;      /* XXX this must be fixed later. */
00489 
00490    /* determine the search boundaries: i..last-1 */
00491    if (i < 0) {
00492       start = i = 0;
00493       last = c->n_buckets;
00494    } else if ((flags & OBJ_CONTINUE)) {
00495       last = c->n_buckets;
00496    } else {
00497       last = i + 1;
00498    }
00499 
00500    ao2_lock(c);   /* avoid modifications to the content */
00501 
00502    for (; i < last ; i++) {
00503       /* scan the list with prev-cur pointers */
00504       struct bucket_list *cur;
00505 
00506       AST_LIST_TRAVERSE_SAFE_BEGIN(&c->buckets[i], cur, entry) {
00507          int match = cb_fn(EXTERNAL_OBJ(cur->astobj), arg, flags) & (CMP_MATCH | CMP_STOP);
00508 
00509          /* we found the object, performing operations according flags */
00510          if (match == 0) { /* no match, no stop, continue */
00511             continue;
00512          } else if (match == CMP_STOP) {  /* no match but stop, we are done */
00513             i = last;
00514             break;
00515          }
00516          /* we have a match (CMP_MATCH) here */
00517          if (!(flags & OBJ_NODATA)) {  /* if must return the object, record the value */
00518             /* it is important to handle this case before the unlink */
00519             ret = EXTERNAL_OBJ(cur->astobj);
00520             ao2_ref(ret, 1);
00521          }
00522 
00523          if (flags & OBJ_UNLINK) {  /* must unlink */
00524             struct bucket_list *x = cur;
00525 
00526             /* we are going to modify the container, so update version */
00527             ast_atomic_fetchadd_int(&c->version, 1);
00528             AST_LIST_REMOVE_CURRENT(&c->buckets[i], entry);
00529             /* update number of elements and version */
00530             ast_atomic_fetchadd_int(&c->elements, -1);
00531             ao2_ref(EXTERNAL_OBJ(x->astobj), -1);
00532             free(x); /* free the link record */
00533          }
00534 
00535          if ((match & CMP_STOP) || (flags & OBJ_MULTIPLE) == 0) {
00536             /* We found the only match we need */
00537             i = last;   /* force exit from outer loop */
00538             break;
00539          }
00540          if (!(flags & OBJ_NODATA)) {
00541 #if 0 /* XXX to be completed */
00542             /*
00543              * This is the multiple-return case. We need to link
00544              * the object in a list. The refcount is already increased.
00545              */
00546 #endif
00547          }
00548       }
00549       AST_LIST_TRAVERSE_SAFE_END
00550 
00551       if (ret) {
00552          /* This assumes OBJ_MULTIPLE with !OBJ_NODATA is still not implemented */
00553          break;
00554       }
00555 
00556       if (i == c->n_buckets - 1 && (flags & OBJ_POINTER) && (flags & OBJ_CONTINUE)) {
00557          /* Move to the beginning to ensure we check every bucket */
00558          i = -1;
00559          last = start;
00560       }
00561    }
00562    ao2_unlock(c);
00563    return ret;
00564 }

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 create_callno_pools(), init_queue(), load_module(), load_objects(), 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(), and get_unused_callno().

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 569 of file astobj2.c.

References ao2_callback(), and ao2_container::cmp_fn.

Referenced by __find_callno(), add_calltoken_ignore(), authenticate_request(), authenticate_verify(), build_callno_limits(), build_peer(), build_user(), compare_weight(), find_peer(), find_user(), get_mohbyname(), get_unused_callno(), iax2_destroy_helper(), peercnt_add(), peercnt_modify(), peercnt_remove_by_addr(), reload_queues(), remove_from_queue(), rt_handle_member_record(), sched_delay_remove(), and xml_translate().

00570 {
00571    return ao2_callback(c, flags, c->cmp_fn, arg);
00572 }

void ao2_iterator_destroy ( struct ao2_iterator i  ) 

Destroy a container iterator.

destroy an iterator

Definition at line 592 of file astobj2.c.

References ao2_ref(), and ao2_iterator::c.

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_callnumber_usage(), iax2_show_users(), interface_exists(), interface_exists_global(), manager_queues_status(), moh_classes_show(), num_available_members(), poke_all_peers(), prune_peers(), prune_users(), queue_function_queuemembercount(), queue_function_queuememberlist(), reload_queues(), try_calling(), update_realtime_members(), and update_status().

00593 {
00594    ao2_ref(i->c, -1);
00595    i->c = NULL;
00596 }

struct ao2_iterator ao2_iterator_init ( struct ao2_container c,
int  flags 
)

Create an iterator for a container.

initialize an iterator so we start from the first object

Definition at line 577 of file astobj2.c.

References ao2_ref(), and 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_callnumber_usage(), iax2_show_users(), interface_exists(), interface_exists_global(), manager_queues_status(), moh_classes_show(), num_available_members(), poke_all_peers(), prune_peers(), prune_users(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_member_count(), reload_queues(), try_calling(), update_realtime_members(), and update_status().

00578 {
00579    struct ao2_iterator a = {
00580       .c = c,
00581       .flags = flags
00582    };
00583 
00584    ao2_ref(c, +1);
00585    
00586    return a;
00587 }

void* ao2_iterator_next ( struct ao2_iterator a  ) 

Definition at line 601 of file astobj2.c.

References AO2_ITERATOR_DONTLOCK, ao2_lock(), AST_LIST_NEXT, AST_LIST_TRAVERSE, ao2_iterator::bucket, ao2_container::buckets, ao2_iterator::c, ao2_iterator::c_version, bucket_list::entry, 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_callnumber_usage(), iax2_show_users(), interface_exists(), interface_exists_global(), manager_queues_status(), moh_classes_show(), num_available_members(), poke_all_peers(), prune_peers(), prune_users(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_member_count(), reload_queues(), try_calling(), update_realtime_members(), and update_status().

00602 {
00603    int lim;
00604    struct bucket_list *p = NULL;
00605    void *ret = NULL;
00606 
00607    if (INTERNAL_OBJ(a->c) == NULL)
00608       return NULL;
00609 
00610    if (!(a->flags & AO2_ITERATOR_DONTLOCK))
00611       ao2_lock(a->c);
00612 
00613    /* optimization. If the container is unchanged and
00614     * we have a pointer, try follow it
00615     */
00616    if (a->c->version == a->c_version && (p = a->obj) ) {
00617       if ( (p = AST_LIST_NEXT(p, entry)) )
00618          goto found;
00619       /* nope, start from the next bucket */
00620       a->bucket++;
00621       a->version = 0;
00622       a->obj = NULL;
00623    }
00624 
00625    lim = a->c->n_buckets;
00626 
00627    /* Browse the buckets array, moving to the next
00628     * buckets if we don't find the entry in the current one.
00629     * Stop when we find an element with version number greater
00630     * than the current one (we reset the version to 0 when we
00631     * switch buckets).
00632     */
00633    for (; a->bucket < lim; a->bucket++, a->version = 0) {
00634       /* scan the current bucket */
00635       AST_LIST_TRAVERSE(&a->c->buckets[a->bucket], p, entry) {
00636          if (p->version > a->version)
00637             goto found;
00638       }
00639    }
00640 
00641 found:
00642    if (p) {
00643       a->version = p->version;
00644       a->obj = p;
00645       a->c_version = a->c->version;
00646       ret = EXTERNAL_OBJ(p->astobj);
00647       /* inc refcount of returned object */
00648       ao2_ref(ret, 1);
00649    }
00650 
00651    if (!(a->flags & AO2_ITERATOR_DONTLOCK))
00652       ao2_unlock(a->c);
00653 
00654    return ret;
00655 }

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(), __queues_show(), add_calltoken_ignore(), add_to_queue(), ao2_callback(), ao2_iterator_next(), build_callno_limits(), compare_weight(), complete_queue_remove_member(), find_queue_by_name_rt(), get_member_status(), get_unused_callno(), interface_exists_global(), is_our_turn(), join_queue(), leave_queue(), manager_queues_status(), moh_release(), mohalloc(), monmp3thread(), peercnt_add(), peercnt_remove(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_function_queuewaitingcount(), queue_member_count(), recalc_holdtime(), record_abandoned(), reload_queue_members(), reload_queues(), remove_from_queue(), replace_callno(), ring_entry(), set_member_paused(), try_calling(), update_queue(), update_realtime_members(), and update_status().

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_calltoken_ignore(), add_to_queue(), announce_thread(), ao2_callback(), ao2_iterator_destroy(), ao2_iterator_init(), ast_closestream(), build_callno_limits(), calltoken_required(), cd_cb(), compare_weight(), complete_queue_remove_member(), conf_free(), conf_run(), create_callno_pools(), destroy_queue(), dump_queue_members(), free_members(), get_member_status(), hangupcalls(), iax2_destroy(), iax2_show_callnumber_usage(), insert_entry(), interface_exists(), interface_exists_global(), load_objects(), manager_queues_status(), new_iax(), num_available_members(), peer_ref(), peer_unref(), peercnt_add(), peercnt_modify(), peercnt_remove_by_addr(), peercnt_remove_cb(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_member_count(), reload_queues(), remove_from_queue(), remove_queue(), replace_callno(), rt_handle_member_record(), sched_delay_remove(), set_member_paused(), set_peercnt_limit(), 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(), peercnt_remove(), 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(), __queues_show(), add_calltoken_ignore(), add_to_queue(), ao2_callback(), build_callno_limits(), compare_weight(), complete_queue_remove_member(), find_queue_by_name_rt(), get_member_status(), get_unused_callno(), interface_exists_global(), is_our_turn(), join_queue(), leave_queue(), manager_queues_status(), moh_release(), mohalloc(), monmp3thread(), peercnt_add(), peercnt_remove(), queue_function_queuemembercount(), queue_function_queuememberlist(), queue_function_queuewaitingcount(), queue_member_count(), recalc_holdtime(), record_abandoned(), reload_queue_members(), reload_queues(), remove_from_queue(), replace_callno(), ring_entry(), set_member_paused(), try_calling(), update_queue(), update_realtime_members(), and update_status().

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 788 of file astobj2.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00789 {
00790 #ifdef AO2_DEBUG
00791    ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
00792 #endif
00793 
00794    return 0;
00795 }

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().

00443 {
00444    return CMP_MATCH;
00445 }

static int cd_cb ( void *  obj,
void *  arg,
int  flag 
) [static]

Definition at line 660 of file astobj2.c.

References ao2_ref().

Referenced by container_destruct().

00661 {
00662    ao2_ref(obj, -1);
00663    return 0;
00664 }

static void container_destruct ( void *  c  )  [static]

Definition at line 666 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().

00667 {
00668    struct ao2_container *c = _c;
00669    int i;
00670 
00671    ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
00672 
00673    for (i = 0; i < c->n_buckets; i++) {
00674       struct bucket_list *cur;
00675 
00676       while ((cur = AST_LIST_REMOVE_HEAD(&c->buckets[i], entry))) {
00677          ast_free(cur);
00678       }
00679    }
00680 
00681 #ifdef AO2_DEBUG
00682    ast_atomic_fetchadd_int(&ao2.total_containers, -1);
00683 #endif
00684 }

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.

Returns:
0

Definition at line 328 of file astobj2.c.

Referenced by ao2_container_alloc().

00329 {
00330    return 0;
00331 }

static struct astobj2* INTERNAL_OBJ ( void *  user_data  )  [inline, static]

convert from a pointer _p to a user-defined object

Returns:
the pointer to the astobj2 structure

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 }


Generated on Thu Mar 25 12:09:45 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7