Asterisk - The Open Source Telephony Project GIT-master-f36a736
astobj2.h
Go to the documentation of this file.
1/*
2 * astobj2 - replacement containers for asterisk data structures.
3 *
4 * Copyright (C) 2006 Marta Carbone, Luigi Rizzo - Univ. di Pisa, Italy
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17#ifndef _ASTERISK_ASTOBJ2_H
18#define _ASTERISK_ASTOBJ2_H
19
20#include "asterisk/compat.h"
21#include "asterisk/lock.h"
23#include "asterisk/inline_api.h"
24
25/*! \file
26 * \ref AstObj2
27 *
28 * \page AstObj2 Object Model implementing objects and containers.
29
30This module implements an abstraction for objects (with locks and
31reference counts), and containers for these user-defined objects,
32also supporting locking, reference counting and callbacks.
33
34The internal implementation of objects and containers is opaque to the user,
35so we can use different data structures as needs arise.
36
37\section AstObj2_UsageObjects USAGE - OBJECTS
38
39An ao2 object is a block of memory that the user code can access,
40and for which the system keeps track (with a bit of help from the
41programmer) of the number of references around. When an object has
42no more references (refcount == 0), it is destroyed, by first
43invoking whatever 'destructor' function the programmer specifies
44(it can be NULL if none is necessary), and then freeing the memory.
45This way objects can be shared without worrying who is in charge
46of freeing them.
47As an additional feature, ao2 objects are associated to individual
48locks.
49
50Creating an object requires the size of the object and
51a pointer to the destructor function:
52
53 struct foo *o;
54
55 o = ao2_alloc(sizeof(struct foo), my_destructor_fn);
56
57The value returned points to the user-visible portion of the objects
58(user-data), but is also used as an identifier for all object-related
59operations such as refcount and lock manipulations.
60
61On return from ao2_alloc():
62
63 - the object has a refcount = 1;
64 - the memory for the object is allocated dynamically and zeroed;
65 - we cannot realloc() the object itself;
66 - we cannot call free(o) to dispose of the object. Rather, we
67 tell the system that we do not need the reference anymore:
68
69 ao2_ref(o, -1)
70
71 causing the destructor to be called (and then memory freed) when
72 the refcount goes to 0.
73
74ao2_ref(o, +1) can be used to modify the refcount on the
75object in case we want to pass it around.
76
77ao2_lock(obj), ao2_unlock(obj), ao2_trylock(obj) can be used
78to manipulate the lock associated with the object.
79
80
81\section AstObj2_UsageContainers USAGE - CONTAINERS
82
83An ao2 container is an abstract data structure where we can store
84ao2 objects, search them (hopefully in an efficient way), and iterate
85or apply a callback function to them. A container is just an ao2 object
86itself.
87
88A container must first be allocated, specifying the initial
89parameters. At the moment, this is done as follows:
90
91 <b>Sample Usage:</b>
92 \code
93
94 struct ao2_container *c;
95
96 c = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_BUCKETS,
97 my_hash_fn, NULL, my_cmp_fn);
98 \endcode
99
100where
101
102- MAX_BUCKETS is the number of buckets in the hash table,
103- my_hash_fn() is the (user-supplied) function that returns a
104 hash key for the object (further reduced modulo MAX_BUCKETS
105 by the container's code);
106- my_cmp_fn() is the default comparison function used when doing
107 searches on the container,
108
109A container knows little or nothing about the objects it stores,
110other than the fact that they have been created by ao2_alloc().
111All knowledge of the (user-defined) internals of the objects
112is left to the (user-supplied) functions passed as arguments
113to ao2_container_alloc_hash().
114
115If we want to insert an object in a container, we should
116initialize its fields -- especially, those used by my_hash_fn() --
117to compute the bucket to use.
118Once done, we can link an object to a container with
119
120 ao2_link(c, o);
121
122The function returns NULL in case of errors (and the object
123is not inserted in the container). Other values mean success
124(we are not supposed to use the value as a pointer to anything).
125Linking an object to a container increases its refcount by 1
126automatically.
127
128\note While an object o is in a container, we expect that
129my_hash_fn(o) will always return the same value. The function
130does not lock the object to be computed, so modifications of
131those fields that affect the computation of the hash should
132be done by extracting the object from the container, and
133re-inserting it after the change (this is not terribly expensive).
134
135\note A container with a single buckets is effectively a linked
136list. However there is no ordering among elements.
137
138- \ref AstObj2_Containers
139- \ref astobj2.h All documentation for functions and data structures
140
141 */
142
143/*
144\note DEBUGGING REF COUNTS BIBLE:
145An interface to help debug refcounting is provided
146in this package. It is dependent on the refdebug being enabled in
147asterisk.conf.
148
149Each of the reference manipulations will generate one line of output in the refs
150log file. These lines look like this:
151...
1520x8756f00,+1,1234,chan_sip.c,22240,load_module,**constructor**,allocate users
1530x86e3408,+1,1234,chan_sip.c,22241,load_module,**constructor**,allocate peers
1540x86dd380,+1,1234,chan_sip.c,22242,load_module,**constructor**,allocate peers_by_ip
1550x822d020,+1,1234,chan_sip.c,22243,load_module,**constructor**,allocate dialogs
1560x8930fd8,+1,1234,chan_sip.c,20025,build_peer,**constructor**,allocate a peer struct
1570x8930fd8,+1,1234,chan_sip.c,21467,reload_config,1,link peer into peer table
1580x8930fd8,-1,1234,chan_sip.c,2370,unref_peer,2,unref_peer: from reload_config
1590x89318b0,1,5678,chan_sip.c,20025,build_peer,**constructor**,allocate a peer struct
1600x89318b0,+1,5678,chan_sip.c,21467,reload_config,1,link peer into peer table
1610x89318b0,-1,1234,chan_sip.c,2370,unref_peer,2,unref_peer: from reload_config
1620x8930218,+1,1234,chan_sip.c,20025,build_peer,**constructor**,allocate a peer struct
1630x8930218,+1,1234,chan_sip.c,21539,reload_config,1,link peer into peers table
1640x868c040,-1,1234,chan_sip.c,2424,dialog_unlink_all,2,unset the relatedpeer->call field in tandem with relatedpeer field itself
1650x868c040,-1,1234,chan_sip.c,2443,dialog_unlink_all,1,Let's unbump the count in the unlink so the poor pvt can disappear if it is time
1660x868c040,-1,1234,chan_sip.c,2443,dialog_unlink_all,**destructor**,Let's unbump the count in the unlink so the poor pvt can disappear if it is time
1670x8cc07e8,-1,1234,chan_sip.c,2370,unref_peer,3,unsetting a dialog relatedpeer field in sip_destroy
1680x8cc07e8,+1,1234,chan_sip.c,3876,find_peer,2,ao2_find in peers table
1690x8cc07e8,-1,1234,chan_sip.c,2370,unref_peer,3,unref_peer, from sip_devicestate, release ref from find_peer
170...
171
172This uses a comma delineated format. The columns in the format are as
173follows:
174- The first column is the object address.
175- The second column reflects how the operation affected the ref count
176 for that object. A change in the ref count is reflected either as
177 an increment (+) or decrement (-), as well as the amount it changed
178 by.
179- The third column is the ID of the thread that modified the reference
180 count.
181- The fourth column is the source file that the change in reference was
182 issued from.
183- The fifth column is the line number of the source file that the ref
184 change was issued from.
185- The sixth column is the name of the function that the ref change was
186 issued from.
187- The seventh column indicates either (a) construction of the object via
188 the special tag **constructor**; (b) destruction of the object via
189 the special tag **destructor**; (c) the previous reference count
190 prior to this reference change.
191- The eighth column is a special tag added by the developer to provide
192 context for the ref change. Note that any subsequent columns are
193 considered to be part of this tag.
194
195Sometimes you have some helper functions to do object create/ref/unref
196operations. Using these normally hides the place where these
197functions were called. To get the location where these functions
198were called to appear in refs log, you can do this sort of thing:
199
200#define my_t_alloc(data,tag) my_alloc_debug((data), tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
201#define my_alloc(data) my_t_alloc((data), NULL)
202
203static struct mydata *my_alloc_debug(void *data,
204 const char *tag, const char *file, int line, const char *func)
205{
206 struct mydata *p;
207
208 p = __ao2_alloc(sizeof(*p), NULL, AO2_ALLOC_OPT_LOCK_MUTEX, tag, file, line, func);
209 if (p) {
210 p->data = data;
211 }
212 return p;
213}
214
215To find out why objects are not destroyed (a common bug), you can
216enable refdebug in asterisk.conf. Run asterisk, exit with "core stop gracefully".
217This should result in every object being destroyed.
218
219Then, you can "sort -k 1 {AST_LOG_DIR}/refs > x1" to get a sorted list of
220all the objects, or you can use "contrib/script/refcounter.py" to scan
221the file for you and output any problems it finds.
222
223The above may seem astronomically more work than it is worth to debug
224reference counts, which may be true in "simple" situations, but for
225more complex situations, it is easily worth 100 times this effort to
226help find problems.
227
228To debug, pair all calls so that each call that increments the
229refcount is paired with a corresponding call that decrements the
230count for the same reason. Hopefully, you will be left with one
231or more unpaired calls. This is where you start your search!
232
233For instance, here is an example of this for a dialog object in
234chan_sip, that was not getting destroyed, after I moved the lines around
235to pair operations:
236
237 0x83787a0,+1,1234,chan_sip.c,5733,sip_alloc,**constructor**,(allocate a dialog(pvt) struct)
238 0x83787a0,-1,1234,chan_sip.c,19173,sip_poke_peer,4,(unref dialog at end of sip_poke_peer, obtained from sip_alloc, just before it goes out of scope)
239
240 0x83787a0,+1,1234,chan_sip.c,5854,sip_alloc,1,(link pvt into dialogs table)
241 0x83787a0,-1,1234,chan_sip.c,19150,sip_poke_peer,3,(About to change the callid -- remove the old name)
242 0x83787a0,+1,1234,chan_sip.c,19152,sip_poke_peer,2,(Linking in under new name)
243 0x83787a0,-1,1234,chan_sip.c,2399,dialog_unlink_all,5,(unlinking dialog via ao2_unlink)
244
245 0x83787a0,+1,1234,chan_sip.c,19130,sip_poke_peer,2,(copy sip alloc from p to peer->call)
246
247
248 0x83787a0,+1,1234,chan_sip.c,2996,__sip_reliable_xmit,3,(__sip_reliable_xmit: setting pkt->owner)
249 0x83787a0,-1,1234,chan_sip.c,2425,dialog_unlink_all,4,(remove all current packets in this dialog, and the pointer to the dialog too as part of __sip_destroy)
250
251 0x83787a0,+1,1234,chan_sip.c,22356,unload_module,4,(iterate thru dialogs)
252 0x83787a0,-1,1234,chan_sip.c,22359,unload_module,5,(toss dialog ptr from iterator_next)
253
254
255 0x83787a0,+1,1234,chan_sip.c,22373,unload_module,3,(iterate thru dialogs)
256 0x83787a0,-1,1234,chan_sip.c,22375,unload_module,2,(throw away iterator result)
257
258 0x83787a0,+1,1234,chan_sip.c,2397,dialog_unlink_all,4,(Let's bump the count in the unlink so it doesn't accidentally become dead before we are done)
259 0x83787a0,-1,1234,chan_sip.c,2436,dialog_unlink_all,3,(Let's unbump the count in the unlink so the poor pvt can disappear if it is time)
260
261As you can see, only one unbalanced operation is in the list, a ref count increment when
262the peer->call was set, but no corresponding decrement was made...
263
264Hopefully this helps you narrow your search and find those bugs.
265
266THE ART OF REFERENCE COUNTING
267(by Steve Murphy)
268SOME TIPS for complicated code, and ref counting:
269
2701. Theoretically, passing a refcounted object pointer into a function
271call is an act of copying the reference, and could be refcounted.
272But, upon examination, this sort of refcounting will explode the amount
273of code you have to enter, and for no tangible benefit, beyond
274creating more possible failure points/bugs. It will even
275complicate your code and make debugging harder, slow down your program
276doing useless increments and decrements of the ref counts.
277
2782. It is better to track places where a ref counted pointer
279is copied into a structure or stored. Make sure to decrement the refcount
280of any previous pointer that might have been there, if setting
281this field might erase a previous pointer. ao2_find and iterate_next
282internally increment the ref count when they return a pointer, so
283you need to decrement the count before the pointer goes out of scope.
284
2853. Any time you decrement a ref count, it may be possible that the
286object will be destroyed (freed) immediately by that call. If you
287are destroying a series of fields in a refcounted object, and
288any of the unref calls might possibly result in immediate destruction,
289you can first increment the count to prevent such behavior, then
290after the last test, decrement the pointer to allow the object
291to be destroyed, if the refcount would be zero.
292
293Example:
294
295 dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
296
297 ao2_t_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
298
299 *//* Unlink us from the owner (channel) if we have one *//*
300 if (dialog->owner) {
301 if (lockowner) {
302 ast_channel_lock(dialog->owner);
303 }
304 ast_debug(1, "Detaching from channel %s\n", dialog->owner->name);
305 dialog->owner->tech_pvt = dialog_unref(dialog->owner->tech_pvt, "resetting channel dialog ptr in unlink_all");
306 if (lockowner) {
307 ast_channel_unlock(dialog->owner);
308 }
309 }
310 if (dialog->registry) {
311 if (dialog->registry->call == dialog) {
312 dialog->registry->call = dialog_unref(dialog->registry->call, "nulling out the registry's call dialog field in unlink_all");
313 }
314 dialog->registry = registry_unref(dialog->registry, "delete dialog->registry");
315 }
316 ...
317 dialog_unref(dialog, "Let's unbump the count in the unlink so the poor pvt can disappear if it is time");
318
319In the above code, the ao2_t_unlink could end up destroying the dialog
320object; if this happens, then the subsequent usages of the dialog
321pointer could result in a core dump. So, we 'bump' the
322count upwards before beginning, and then decrementing the count when
323we are finished. This is analogous to 'locking' or 'protecting' operations
324for a short while.
325
3264. One of the most insidious problems I've run into when converting
327code to do ref counted automatic destruction, is in the destruction
328routines. Where a "destroy" routine had previously been called to
329get rid of an object in non-refcounted code, the new regime demands
330that you tear that "destroy" routine into two pieces, one that will
331tear down the links and 'unref' them, and the other to actually free
332and reset fields. A destroy routine that does any reference deletion
333for its own object, will never be called. Another insidious problem
334occurs in mutually referenced structures. As an example, a dialog contains
335a pointer to a peer, and a peer contains a pointer to a dialog. Watch
336out that the destruction of one doesn't depend on the destruction of the
337other, as in this case a dependency loop will result in neither being
338destroyed!
339
340Given the above, you should be ready to do a good job!
341
342murf
343
344*/
345
346
347
348/*!
349 * \brief Typedef for an object destructor.
350 *
351 * \param vdoomed Object to destroy.
352 *
353 * \details
354 * This is called just before freeing the memory for the object.
355 * It is passed a pointer to the user-defined data of the
356 * object.
357 */
358typedef void (*ao2_destructor_fn)(void *vdoomed);
359
360/*! \brief Options available when allocating an ao2 object. */
362 /*! The ao2 object has a recursive mutex lock associated with it. */
364 /*! The ao2 object has a non-recursive read/write lock associated with it. */
366 /*! The ao2 object has no lock associated with it. */
368 /*! The ao2 object locking option field mask. */
370 /*!
371 * \internal The ao2 object uses a separate object for locking.
372 *
373 * \note This option is used internally by ao2_alloc_with_lockobj and
374 * should never be passed directly to ao2_alloc.
375 */
377 /*! The ao2 object will not record any REF_DEBUG entries */
379};
380
381/*!
382 * \brief Allocate and initialize an object.
383 *
384 * \param data_size The sizeof() of the user-defined structure.
385 * \param destructor_fn The destructor function (can be NULL)
386 * \param options The ao2 object options (See enum ao2_alloc_opts)
387 * \param debug_msg An ao2 object debug tracing message.
388 * \return A pointer to user-data.
389 *
390 * \details
391 * Allocates a struct astobj2 with sufficient space for the
392 * user-defined structure.
393 * \note
394 * - storage is zeroed; XXX maybe we want a flag to enable/disable this.
395 * - the refcount of the object just created is 1
396 * - the returned pointer cannot be free()'d or realloc()'ed;
397 * rather, we just call ao2_ref(o, -1);
398 *
399 * @{
400 */
401
402#define ao2_t_alloc_options(data_size, destructor_fn, options, debug_msg) \
403 __ao2_alloc((data_size), (destructor_fn), (options), (debug_msg), __FILE__, __LINE__, __PRETTY_FUNCTION__)
404#define ao2_alloc_options(data_size, destructor_fn, options) \
405 __ao2_alloc((data_size), (destructor_fn), (options), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
406
407#define ao2_t_alloc(data_size, destructor_fn, debug_msg) \
408 __ao2_alloc((data_size), (destructor_fn), AO2_ALLOC_OPT_LOCK_MUTEX, (debug_msg), __FILE__, __LINE__, __PRETTY_FUNCTION__)
409#define ao2_alloc(data_size, destructor_fn) \
410 __ao2_alloc((data_size), (destructor_fn), AO2_ALLOC_OPT_LOCK_MUTEX, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
411
412void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options,
413 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
414
415/*! @} */
416
417/*!
418 * \since 14.1.0
419 * \brief Allocate and initialize an object with separate locking.
420 *
421 * \param data_size The sizeof() of the user-defined structure.
422 * \param destructor_fn The destructor function (can be NULL)
423 * \param lockobj A separate ao2 object that will provide locking.
424 * \param tag An ao2 object debug tracing message.
425 * \return A pointer to user-data.
426 *
427 * \see \ref ao2_alloc for additional details.
428 *
429 * \note lockobj must be a valid AO2 object.
430 */
431#define ao2_alloc_with_lockobj(data_size, destructor_fn, lockobj, tag) \
432 __ao2_alloc_with_lockobj((data_size), (destructor_fn), (lockobj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
433
434void *__ao2_alloc_with_lockobj(size_t data_size, ao2_destructor_fn destructor_fn, void *lockobj,
435 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
436
437/*! \brief
438 * Reference/unreference an object and return the old refcount.
439 *
440 * \param o A pointer to the object
441 * \param delta Value to add to the reference counter.
442 * \return The value of the reference counter before the operation.
443 *
444 * Increase/decrease the reference counter according
445 * the value of delta.
446 *
447 * If the refcount goes to zero, the object is destroyed.
448 *
449 * \note The object must not be locked by the caller of this function, as
450 * it is invalid to try to unlock it after releasing the reference.
451 *
452 * \note if we know the pointer to an object, it is because we
453 * have a reference count to it, so the only case when the object
454 * can go away is when we release our reference, and it is
455 * the last one in existence.
456 *
457 * @{
458 */
459#define ao2_ref(o,delta) __ao2_ref((o), (delta), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
460#define ao2_t_ref(o,delta,tag) __ao2_ref((o), (delta), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
461
462/*!
463 * \brief Retrieve the ao2 options used to create the object.
464 * \param obj pointer to the (user-defined part) of an object.
465 * \return options from enum ao2_alloc_opts.
466 */
467unsigned int ao2_options_get(void *obj);
468
469/*!
470 * \since 12
471 * \brief Bump refcount on an AO2 object by one, returning the object.
472 *
473 * This is useful for inlining a ref bump, and you don't care about the ref
474 * count. Also \c NULL safe, for even more convenience.
475 *
476 * \param obj AO2 object to bump the refcount on.
477 *
478 * \return The given \a obj pointer.
479 */
480#define ao2_bump(obj) \
481 ao2_t_bump((obj), NULL)
482
483#define ao2_t_bump(obj, tag) \
484 ({ \
485 typeof(obj) __obj_ ## __LINE__ = (obj); \
486 if (__obj_ ## __LINE__) { \
487 ao2_t_ref(__obj_ ## __LINE__, +1, (tag)); \
488 } \
489 __obj_ ## __LINE__; \
490 })
491
492int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func);
493
494/*!
495 * \since 12.4.0
496 * \brief Replace one object reference with another cleaning up the original.
497 *
498 * \param dst Pointer to the object that will be cleaned up.
499 * \param src Pointer to the object replacing it.
500 */
501#define ao2_replace(dst, src) \
502 ao2_t_replace((dst), (src), NULL)
503
504#define ao2_t_replace(dst, src, tag) \
505 {\
506 typeof(dst) *__dst_ ## __LINE__ = &dst; \
507 typeof(src) __src_ ## __LINE__ = src; \
508 if (__src_ ## __LINE__ != *__dst_ ## __LINE__) { \
509 if (__src_ ## __LINE__) {\
510 ao2_t_ref(__src_ ## __LINE__, +1, (tag)); \
511 } \
512 if (*__dst_ ## __LINE__) {\
513 ao2_t_ref(*__dst_ ## __LINE__, -1, (tag)); \
514 } \
515 *__dst_ ## __LINE__ = __src_ ## __LINE__; \
516 } \
517 }
518
519/*! @} */
520
521/*! \brief ao2_weakproxy
522 *
523 * @{
524 */
526typedef void (*ao2_weakproxy_notification_cb)(void *weakproxy, void *data);
527
528/*! \brief This struct should be opaque, but it's size is needed. */
531};
532
533/*! \brief Macro which must be used at the beginning of weakproxy capable objects.
534 *
535 * \note The primary purpose of user defined fields on weakproxy objects is to hold
536 * immutable container keys for the real object.
537 */
538#define AO2_WEAKPROXY() struct ao2_weakproxy __weakproxy##__LINE__
539
540/*!
541 * \since 14.0.0
542 * \brief Allocate an ao2_weakproxy object
543 *
544 * \param data_size The sizeof() of the user-defined structure.
545 * \param destructor_fn The destructor function (can be NULL)
546 *
547 * \note "struct ao2_weakproxy" must be the first field of any object.
548 * This can be done by using AO2_WEAKPROXY to declare your structure.
549 */
550#define ao2_weakproxy_alloc(data_size, destructor_fn) \
551 __ao2_weakproxy_alloc(data_size, destructor_fn, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
552
553#define ao2_t_weakproxy_alloc(data_size, destructor_fn, tag) \
554 __ao2_weakproxy_alloc(data_size, destructor_fn, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
555
556void *__ao2_weakproxy_alloc(size_t data_size, ao2_destructor_fn destructor_fn,
557 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
558
559/*!
560 * \since 14.0.0
561 * \brief Associate weakproxy with obj.
562 *
563 * \param weakproxy An object created by ao2_weakproxy_alloc.
564 * \param obj An ao2 object not created by ao2_weakproxy_alloc.
565 * \param flags OBJ_NOLOCK to avoid locking weakproxy.
566 *
567 * \retval 0 Success
568 * \retval -1 Failure
569 *
570 * \note obj must be newly created, this procedure is not thread safe
571 * if any other code can reach obj before this procedure ends.
572 *
573 * \note weakproxy may be previously existing, but must not currently
574 * have an object set.
575 *
576 * \note The only way to unset an object is for it to be destroyed.
577 * Any call to this function while an object is already set will fail.
578 */
579#define ao2_weakproxy_set_object(weakproxy, obj, flags) \
580 __ao2_weakproxy_set_object(weakproxy, obj, flags, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
581
582#define ao2_t_weakproxy_set_object(weakproxy, obj, flags, tag) \
583 __ao2_weakproxy_set_object(weakproxy, obj, flags, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
584
585int __ao2_weakproxy_set_object(void *weakproxy, void *obj, int flags,
586 const char *tag, const char *file, int line, const char *func);
587
588/*!
589 * \since 14.0.0
590 * \brief Run ao2_t_ref on the object associated with weakproxy.
591 *
592 * \param weakproxy The weakproxy to read from.
593 * \param delta Value to add to the reference counter.
594 * \param flags OBJ_NOLOCK to avoid locking weakproxy.
595 *
596 * \retval -2 weakproxy is not a valid ao2_weakproxy.
597 * \retval -1 weakproxy has no associated object.
598 *
599 * \return The value of the reference counter before the operation.
600 */
601#define ao2_weakproxy_ref_object(weakproxy, delta, flags) \
602 ao2_t_weakproxy_ref_object(weakproxy, delta, flags, NULL)
603
604#define ao2_t_weakproxy_ref_object(weakproxy, delta, flags, tag) \
605 __ao2_weakproxy_ref_object(weakproxy, delta, flags, \
606 tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
607
608int __ao2_weakproxy_ref_object(void *weakproxy, int delta, int flags,
609 const char *tag, const char *file, int line, const char *func);
610
611/*!
612 * \since 14.0.0
613 * \brief Get the object associated with weakproxy.
614 *
615 * \param weakproxy The weakproxy to read from.
616 * \param flags OBJ_NOLOCK to avoid locking weakproxy.
617 *
618 * \return A reference to the object previously set by ao2_weakproxy_set_object.
619 * \retval NULL Either no object was set or the previously set object has been freed.
620 */
621#define ao2_weakproxy_get_object(weakproxy, flags) \
622 __ao2_weakproxy_get_object(weakproxy, flags, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
623
624#define ao2_t_weakproxy_get_object(weakproxy, flags, tag) \
625 __ao2_weakproxy_get_object(weakproxy, flags, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
626
627void *__ao2_weakproxy_get_object(void *weakproxy, int flags,
628 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
629
630/*!
631 * \since 14.0.0
632 * \brief Request notification when weakproxy points to NULL.
633 *
634 * \param weakproxy The weak object
635 * \param cb Procedure to call when no real object is associated
636 * \param data Passed to cb
637 * \param flags OBJ_NOLOCK to avoid locking weakproxy.
638 *
639 * \retval 0 Success
640 * \retval -1 Failure
641 *
642 * \note Callbacks are run in the reverse order of subscriptions.
643 *
644 * \note This procedure will allow the same cb / data pair to be added to
645 * the same weakproxy multiple times.
646 *
647 * \note It is the caller's responsibility to ensure that *data is valid
648 * until after cb() is run or ao2_weakproxy_unsubscribe is called.
649 *
650 * \note If the weakproxy currently points to NULL the callback will be run immediately,
651 * without being added to the subscriber list.
652 */
653int ao2_weakproxy_subscribe(void *weakproxy, ao2_weakproxy_notification_cb cb, void *data, int flags);
654
655/*!
656 * \since 14.0.0
657 * \brief Remove notification of real object destruction.
658 *
659 * \param weakproxy The weak object
660 * \param cb Callback to remove from destroy notification list
661 * \param data Data pointer to match
662 * \param flags OBJ_NOLOCK to avoid locking weakproxy.
663 * OBJ_MULTIPLE to remove all copies of the same cb / data pair.
664 *
665 * \return The number of subscriptions removed.
666 * \retval 0 cb / data pair not found, nothing removed.
667 * \retval -1 Failure due to invalid parameters.
668 *
669 * \note Unless flags includes OBJ_MULTIPLE, this will only remove a single copy
670 * of the cb / data pair. If it was subscribed multiple times it must be
671 * unsubscribed as many times. The OBJ_MULTIPLE flag can be used to remove
672 * matching subscriptions.
673 *
674 * \note When it's time to run callbacks they are copied to a temporary list so the
675 * weakproxy can be unlocked before running. That means it's possible for
676 * this function to find nothing before the callback is run in another thread.
677 */
678int ao2_weakproxy_unsubscribe(void *weakproxy, ao2_weakproxy_notification_cb cb, void *data, int flags);
679
680/*!
681 * \since 14.0.0
682 * \brief Get the weakproxy attached to obj
683 *
684 * \param obj The object to retrieve a weakproxy from
685 *
686 * \return The weakproxy object
687 */
688#define ao2_get_weakproxy(obj) \
689 __ao2_get_weakproxy(obj, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
690
691#define ao2_t_get_weakproxy(obj, tag) \
692 __ao2_get_weakproxy(obj, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
693
694void *__ao2_get_weakproxy(void *obj,
695 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
696/*! @} */
697
698
699/*! \brief Which lock to request. */
701 /*! Request the mutex lock be acquired. */
703 /*! Request the read lock be acquired. */
705 /*! Request the write lock be acquired. */
707};
708
709/*! \brief
710 * Lock an object.
711 *
712 * \param a A pointer to the object we want to lock.
713 * \param lock_how, file, func, line, var
714 * \return 0 on success, other values on error.
715 */
716int __ao2_lock(void *a, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var);
717#define ao2_lock(a) __ao2_lock(a, AO2_LOCK_REQ_MUTEX, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
718#define ao2_rdlock(a) __ao2_lock(a, AO2_LOCK_REQ_RDLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
719#define ao2_wrlock(a) __ao2_lock(a, AO2_LOCK_REQ_WRLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
720
721/*! \brief
722 * Unlock an object.
723 *
724 * \param a A pointer to the object we want unlock.
725 * \param file, func, line, var
726 * \return 0 on success, other values on error.
727 */
728int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
729#define ao2_unlock(a) __ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
730
731/*! \brief
732 * Try locking-- (don't block if fail)
733 *
734 * \param a A pointer to the object we want to lock.
735 * \param lock_how, file, func, line, var
736 * \return 0 on success, other values on error.
737 */
738int __ao2_trylock(void *a, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var);
739#define ao2_trylock(a) __ao2_trylock(a, AO2_LOCK_REQ_MUTEX, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
740#define ao2_tryrdlock(a) __ao2_trylock(a, AO2_LOCK_REQ_RDLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
741#define ao2_trywrlock(a) __ao2_trylock(a, AO2_LOCK_REQ_WRLOCK, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
742
743/*!
744 * \brief Return the mutex lock address of an object
745 *
746 * \param[in] obj A pointer to the object we want.
747 * \return the address of the mutex lock, else NULL.
748 *
749 * This function comes in handy mainly for debugging locking
750 * situations, where the locking trace code reports the
751 * lock address, this allows you to correlate against
752 * object address, to match objects to reported locks.
753 *
754 * \warning AO2 lock objects do not include tracking fields when
755 * DEBUG_THREADS is not enabled.
756 *
757 * \since 1.6.1
758 */
759void *ao2_object_get_lockaddr(void *obj);
760
761
762/*!
763 * \brief Increment reference count on an object and lock it
764 * \since 13.9.0
765 *
766 * \param[in] obj A pointer to the ao2 object
767 * \retval 0 The object is not an ao2 object or wasn't locked successfully
768 * \retval 1 The object's reference count was incremented and was locked
769 */
771int ao2_ref_and_lock(void *obj),
772{
773 ao2_ref(obj, +1);
774 if (ao2_lock(obj)) {
775 ao2_ref(obj, -1);
776 return 0;
777 }
778 return 1;
779}
781
782/*!
783 * \brief Unlock an object and decrement its reference count
784 * \since 13.9.0
785 *
786 * \param[in] obj A pointer to the ao2 object
787 * \retval 0 The object is not an ao2 object or wasn't unlocked successfully
788 * \retval 1 The object was unlocked and it's reference count was decremented
789 */
791int ao2_unlock_and_unref(void *obj),
792{
793 if (ao2_unlock(obj)) {
794 return 0;
795 }
796 ao2_ref(obj, -1);
797
798 return 1;
799}
801
802/*! Global ao2 object holder structure. */
804 /*! Access lock to the held ao2 object. */
806 /*! Global ao2 object. */
807 void *obj;
808};
809
810/*!
811 * \brief Define a global object holder to be used to hold an ao2 object, statically initialized.
812 * \since 11.0
813 *
814 * \param name This will be the name of the object holder.
815 *
816 * \details
817 * This macro creates a global object holder that can be used to
818 * hold an ao2 object accessible using the API. The structure is
819 * allocated and initialized to be empty.
820 *
821 * Example usage:
822 * \code
823 * static AO2_GLOBAL_OBJ_STATIC(global_cfg);
824 * \endcode
825 *
826 * This defines global_cfg, intended to hold an ao2 object
827 * accessible using an API.
828 */
829#ifndef HAVE_PTHREAD_RWLOCK_INITIALIZER
830#define AO2_GLOBAL_OBJ_STATIC(name) \
831 struct ao2_global_obj name; \
832 static void __attribute__((constructor)) __init_##name(void) \
833 { \
834 ast_rwlock_init(&name.lock); \
835 name.obj = NULL; \
836 } \
837 static void __attribute__((destructor)) __fini_##name(void) \
838 { \
839 if (name.obj) { \
840 ao2_ref(name.obj, -1); \
841 name.obj = NULL; \
842 } \
843 ast_rwlock_destroy(&name.lock); \
844 } \
845 struct __dummy_##name
846#else
847#define AO2_GLOBAL_OBJ_STATIC(name) \
848 struct ao2_global_obj name = { \
849 .lock = AST_RWLOCK_INIT_VALUE, \
850 }
851#endif
852
853/*!
854 * \brief Release the ao2 object held in the global holder.
855 * \since 11.0
856 *
857 * \param holder Global ao2 object holder.
858 */
859#define ao2_global_obj_release(holder) \
860 __ao2_global_obj_replace_unref(&holder, NULL, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
861#define ao2_t_global_obj_release(holder, tag) \
862 __ao2_global_obj_replace_unref(&holder, NULL, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
863
864/*!
865 * \brief Replace an ao2 object in the global holder.
866 * \since 11.0
867 *
868 * \param holder Global ao2 object holder.
869 * \param obj Object to put into the holder. Can be NULL.
870 *
871 * \note This function automatically increases the reference
872 * count to account for the reference that the global holder now
873 * holds to the object.
874 *
875 * \return Reference to previous global ao2 object stored.
876 * \retval NULL if no object available.
877 */
878#define ao2_global_obj_replace(holder, obj) \
879 __ao2_global_obj_replace(&holder, (obj), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
880
881#define ao2_t_global_obj_replace(holder, obj, tag) \
882 __ao2_global_obj_replace(&holder, (obj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
883
884void *__ao2_global_obj_replace(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name) attribute_warn_unused_result;
885
886/*!
887 * \brief Replace an ao2 object in the global holder, throwing away any old object.
888 * \since 11.0
889 *
890 * \param holder Global ao2 object holder.
891 * \param obj Object to put into the holder. Can be NULL.
892 *
893 * \note This function automatically increases the reference
894 * count to account for the reference that the global holder now
895 * holds to the object. It also decreases the reference count
896 * of any object being replaced.
897 *
898 * \retval 0 The global object was previously empty
899 * \retval 1 The global object was not previously empty
900 */
901#define ao2_global_obj_replace_unref(holder, obj) \
902 __ao2_global_obj_replace_unref(&holder, (obj), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
903
904#define ao2_t_global_obj_replace_unref(holder, obj, tag) \
905 __ao2_global_obj_replace_unref(&holder, (obj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
906
907int __ao2_global_obj_replace_unref(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name);
908
909/*!
910 * \brief Get a reference to the object stored in the global holder.
911 * \since 11.0
912 *
913 * \param holder Global ao2 object holder.
914 *
915 * \return Reference to current ao2 object stored in the holder.
916 * \retval NULL if no object available.
917 */
918#define ao2_global_obj_ref(holder) \
919 __ao2_global_obj_ref(&holder, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
920
921#define ao2_t_global_obj_ref(holder, tag) \
922 __ao2_global_obj_ref(&holder, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__, #holder)
923
924void *__ao2_global_obj_ref(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name) attribute_warn_unused_result;
925
926
927/*!
928 \page AstObj2_Containers AstObj2 Containers
929
930Containers are data structures meant to store several objects,
931and perform various operations on them.
932Internally, objects are stored in lists, hash tables or other
933data structures depending on the needs.
934
935Operations on container include:
936
937 - \b ao2_find(c, arg, flags)
938 returns zero or more elements matching a given criteria
939 (specified as arg). 'c' is the container pointer. Flags
940 can be:
941 OBJ_UNLINK - to remove the object, once found, from the container.
942 OBJ_NODATA - don't return the object if found (no ref count change)
943 OBJ_MULTIPLE - don't stop at first match
944 OBJ_SEARCH_OBJECT - if set, 'arg' is an object pointer, and a hash table
945 search will be done. If not, a traversal is done.
946 OBJ_SEARCH_KEY - if set, 'arg', is a search key item that is not an object.
947 Similar to OBJ_SEARCH_OBJECT and mutually exclusive.
948 OBJ_SEARCH_PARTIAL_KEY - if set, 'arg', is a partial search key item that is not an object.
949 Similar to OBJ_SEARCH_KEY and mutually exclusive.
950
951 - \b ao2_callback(c, flags, fn, arg)
952 apply fn(obj, arg) to all objects in the container.
953 Similar to find. fn() can tell when to stop, and
954 do anything with the object including unlinking it.
955 - c is the container;
956 - flags can be
957 OBJ_UNLINK - to remove the object, once found, from the container.
958 OBJ_NODATA - don't return the object if found (no ref count change)
959 OBJ_MULTIPLE - don't stop at first match
960 OBJ_SEARCH_OBJECT - if set, 'arg' is an object pointer, and a hash table
961 search will be done. If not, a traversal is done through
962 all the hash table 'buckets'..
963 OBJ_SEARCH_KEY - if set, 'arg', is a search key item that is not an object.
964 Similar to OBJ_SEARCH_OBJECT and mutually exclusive.
965 OBJ_SEARCH_PARTIAL_KEY - if set, 'arg', is a partial search key item that is not an object.
966 Similar to OBJ_SEARCH_KEY and mutually exclusive.
967 - fn is a func that returns int, and takes 3 args:
968 (void *obj, void *arg, int flags);
969 obj is an object
970 arg is the same as arg passed into ao2_callback
971 flags is the same as flags passed into ao2_callback
972 fn returns:
973 0: no match, keep going
974 CMP_STOP: stop search, no match
975 CMP_MATCH: This object is matched.
976
977 Note that the entire operation is run with the container
978 locked, so nobody else can change its content while we work on it.
979 However, we pay this with the fact that doing
980 anything blocking in the callback keeps the container
981 blocked.
982 The mechanism is very flexible because the callback function fn()
983 can do basically anything e.g. counting, deleting records, etc.
984 possibly using arg to store the results.
985
986 - \b iterate on a container
987 this is done with the following sequence
988
989\code
990
991 struct ao2_container *c = ... // our container
992 struct ao2_iterator i;
993 void *o;
994
995 i = ao2_iterator_init(c, flags);
996
997 while ((o = ao2_iterator_next(&i))) {
998 ... do something on o ...
999 ao2_ref(o, -1);
1000 }
1001
1002 ao2_iterator_destroy(&i);
1003\endcode
1004
1005 The difference with the callback is that the control
1006 on how to iterate is left to us.
1007
1008 - \b ao2_ref(c, -1)
1009 dropping a reference to a container destroys it, very simple!
1010
1011Containers are ao2 objects themselves, and this is why their
1012implementation is simple too.
1013
1014Before declaring containers, we need to declare the types of the
1015arguments passed to the constructor - in turn, this requires
1016to define callback and hash functions and their arguments.
1017
1018- \ref AstObj2
1019- \ref astobj2.h
1020 */
1021
1022/*! \brief
1023 * A callback function will return a combination of CMP_MATCH and CMP_STOP.
1024 * The latter will terminate the search in a container.
1025 */
1027 CMP_MATCH = 0x1, /*!< the object matches the request */
1028 CMP_STOP = 0x2, /*!< stop the search now */
1029};
1030
1031/*!
1032 * \brief Flags passed to ao2_callback_fn(), ao2_hash_fn(), and ao2_sort_fn() to modify behaviour.
1033 */
1035 /*!
1036 * Unlink the object for which the callback function returned
1037 * CMP_MATCH.
1038 */
1039 OBJ_UNLINK = (1 << 0),
1040 /*!
1041 * On match, don't return the object hence do not increase its
1042 * refcount.
1043 */
1044 OBJ_NODATA = (1 << 1),
1045 /*!
1046 * Don't stop at the first match in ao2_callback() unless the
1047 * result of the callback function has the CMP_STOP bit set.
1048 */
1049 OBJ_MULTIPLE = (1 << 2),
1050 /*!
1051 * \brief Assume that the ao2_container is already locked.
1052 *
1053 * \note For ao2_containers that have mutexes, no locking will
1054 * be done.
1055 *
1056 * \note For ao2_containers that have RWLOCKs, the lock will be
1057 * promoted to write mode as needed. The lock will be returned
1058 * to the original locked state.
1059 *
1060 * \note Only use this flag if the ao2_container is manually
1061 * locked already.
1062 */
1063 OBJ_NOLOCK = (1 << 4),
1064
1065 /*!
1066 * \brief Search option field mask.
1067 *
1068 * \todo Eventually OBJ_SEARCH_MASK will shrink to a two bit
1069 * field when the codebase is made to use the search field
1070 * values as a field instead of independent bits.
1071 */
1072 OBJ_SEARCH_MASK = (0x07 << 5),
1073 /*! \brief The arg parameter has no meaning to the astobj2 code. */
1075 /*!
1076 * \brief The arg parameter is an object of the same type.
1077 *
1078 * \details
1079 * The arg parameter is an object of the same type as the one
1080 * being searched for, so use the object's ao2_hash_fn and/or
1081 * ao2_sort_fn functions for optimized searching.
1082 *
1083 * \note The supplied ao2_callback_fn is called after the
1084 * container nodes have been filtered by the ao2_hash_fn and/or
1085 * ao2_sort_fn functions.
1086 */
1088 /*!
1089 * \brief The arg parameter is a search key, but is not an object.
1090 *
1091 * \details
1092 * This can be used when you want to be able to pass custom data
1093 * to the container's stored ao2_hash_fn, ao2_sort_fn, and
1094 * ao2_find ao2_callback_fn functions that is not a full object,
1095 * but perhaps just a string.
1096 *
1097 * \note The supplied ao2_callback_fn is called after the
1098 * container nodes have been filtered by the ao2_hash_fn and/or
1099 * ao2_sort_fn functions.
1100 */
1101 OBJ_SEARCH_KEY = (2 << 5),
1102 /*!
1103 * \brief The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
1104 *
1105 * \details
1106 * The partial key can be used by the ao2_sort_fn to guide the
1107 * search to find a contiguous subset of a sorted container.
1108 * For example, a sorted container holds: "A", "B", "Bert",
1109 * "Beth", "Earnie". Doing a partial key search with "B" will
1110 * find the sorted subset of all held objects starting with "B".
1111 *
1112 * \note The supplied ao2_callback_fn is called after the
1113 * container nodes have been filtered by the ao2_sort_fn
1114 * function.
1115 */
1117
1118 /*! \brief Traverse order option field mask. */
1119 OBJ_ORDER_MASK = (0x03 << 8),
1120 /*! \brief Traverse in ascending order (First to last container object) */
1122 /*! \brief Traverse in descending order (Last to first container object) */
1124 /*!
1125 * \brief Traverse in pre-order (Node then children, for tree container)
1126 *
1127 * \note For non-tree containers, it is up to the container type
1128 * to make the best interpretation of the order. For list and
1129 * hash containers, this also means ascending order because a
1130 * binary tree can degenerate into a list.
1131 */
1132 OBJ_ORDER_PRE = (2 << 8),
1133 /*!
1134 * \brief Traverse in post-order (Children then node, for tree container)
1135 *
1136 * \note For non-tree containers, it is up to the container type
1137 * to make the best interpretation of the order. For list and
1138 * hash containers, this also means descending order because a
1139 * binary tree can degenerate into a list.
1140 */
1141 OBJ_ORDER_POST = (3 << 8),
1142};
1143
1144/*
1145 * Deprecated backward compatible flag names.
1146 *
1147 * Note: OBJ_POINTER, OBJ_KEY, and OBJ_PARTIAL_KEY are mutually
1148 * exclusive.
1149 */
1150#define OBJ_POINTER OBJ_SEARCH_OBJECT /*!< Deprecated name */
1151#define OBJ_KEY OBJ_SEARCH_KEY /*!< Deprecated name */
1152#define OBJ_PARTIAL_KEY OBJ_SEARCH_PARTIAL_KEY /*!< Deprecated name */
1153
1154/*!
1155 * \brief Options available when allocating an ao2 container object.
1156 *
1157 * \note Each option is open to some interpretation by the
1158 * container type as long as it makes sense with the option
1159 * name.
1160 */
1162 /*!
1163 * \brief Insert objects at the beginning of the container.
1164 * (Otherwise it is the opposite; insert at the end.)
1165 *
1166 * \note If an ao2_sort_fn is provided, the object is inserted
1167 * before any objects with duplicate keys.
1168 *
1169 * \note Hash containers insert the object in the computed hash
1170 * bucket in the indicated manner.
1171 */
1173
1174 /*!
1175 * \brief The ao2 container objects with duplicate keys option field mask.
1176 */
1178 /*!
1179 * \brief Allow objects with duplicate keys in container.
1180 */
1182 /*!
1183 * \brief Reject objects with duplicate keys in container.
1184 *
1185 * \note The container must be sorted. i.e. have an
1186 * ao2_sort_fn.
1187 */
1189 /*!
1190 * \brief Reject duplicate objects in container.
1191 *
1192 * \details Don't link the same object into the container twice.
1193 * However, you can link a different object with the same key.
1194 *
1195 * \note The container must be sorted. i.e. have an
1196 * ao2_sort_fn.
1197 *
1198 * \note It is assumed that the objects are located where the
1199 * search key says they should be located.
1200 */
1202 /*!
1203 * \brief Replace objects with duplicate keys in container.
1204 *
1205 * \details The existing duplicate object is removed and the new
1206 * object takes the old object's place.
1207 *
1208 * \note The container must be sorted. i.e. have an
1209 * ao2_sort_fn.
1210 */
1212};
1213
1214/*!
1215 * \brief Type of a generic callback function
1216 * \param obj pointer to the (user-defined part) of an object.
1217 * \param arg callback argument from ao2_callback()
1218 * \param flags flags from ao2_callback()
1219 * OBJ_SEARCH_OBJECT - if set, 'arg', is an object.
1220 * OBJ_SEARCH_KEY - if set, 'arg', is a search key item that is not an object.
1221 * OBJ_SEARCH_PARTIAL_KEY - if set, 'arg', is a partial search key item that is not an object.
1222 *
1223 * The return values are a combination of enum _cb_results.
1224 * Callback functions are used to search or manipulate objects in a container.
1225 */
1226typedef int (ao2_callback_fn)(void *obj, void *arg, int flags);
1227
1228/*! \brief A common ao2_callback is one that matches by address. */
1229int ao2_match_by_addr(void *obj, void *arg, int flags);
1230
1231/*!
1232 * \brief Type of a generic callback function
1233 * \param obj pointer to the (user-defined part) of an object.
1234 * \param arg callback argument from ao2_callback()
1235 * \param data arbitrary data from ao2_callback()
1236 * \param flags flags from ao2_callback()
1237 * OBJ_SEARCH_OBJECT - if set, 'arg', is an object.
1238 * OBJ_SEARCH_KEY - if set, 'arg', is a search key item that is not an object.
1239 * OBJ_SEARCH_PARTIAL_KEY - if set, 'arg', is a partial search key item that is not an object.
1240 *
1241 * The return values are a combination of enum _cb_results.
1242 * Callback functions are used to search or manipulate objects in a container.
1243 */
1244typedef int (ao2_callback_data_fn)(void *obj, void *arg, void *data, int flags);
1245
1246/*!
1247 * Type of a generic function to generate a hash value from an object.
1248 *
1249 * \param obj pointer to the (user-defined part) of an object.
1250 * \param flags flags from ao2_callback()
1251 * OBJ_SEARCH_OBJECT - if set, 'obj', is an object.
1252 * OBJ_SEARCH_KEY - if set, 'obj', is a search key item that is not an object.
1253 *
1254 * \note This function must be idempotent.
1255 *
1256 * \return Computed hash value.
1257 */
1258typedef int (ao2_hash_fn)(const void *obj, int flags);
1259
1260/*!
1261 * \brief Type of generic container sort function.
1262 *
1263 * \param obj_left pointer to the (user-defined part) of an object.
1264 * \param obj_right pointer to the (user-defined part) of an object.
1265 * \param flags flags from ao2_callback()
1266 * OBJ_SEARCH_OBJECT - if set, 'obj_right', is an object.
1267 * OBJ_SEARCH_KEY - if set, 'obj_right', is a search key item that is not an object.
1268 * OBJ_SEARCH_PARTIAL_KEY - if set, 'obj_right', is a partial search key item that is not an object.
1269 *
1270 * \note This function must be idempotent.
1271 *
1272 * \retval negtaive if obj_left < obj_right
1273 * \retval 0 if obj_left == obj_right
1274 * \retval positive if obj_left > obj_right
1275 */
1276typedef int (ao2_sort_fn)(const void *obj_left, const void *obj_right, int flags);
1277
1278/*! \name Object Containers
1279 * Here start declarations of containers.
1280 *
1281 * @{
1282 */
1283struct ao2_container;
1284
1285/*!
1286 * \brief Allocate and initialize a hash container with the desired number of buckets.
1287 *
1288 * \details
1289 * We allocate space for a struct astobj_container, struct container
1290 * and the buckets[] array.
1291 *
1292 * \param ao2_options Container ao2 object options (See enum ao2_alloc_opts)
1293 * \param container_options Container behaviour options (See enum ao2_container_opts)
1294 * \param n_buckets Number of buckets for hash
1295 * \param hash_fn Pointer to a function computing a hash value. (NULL if everyting goes in first bucket.)
1296 * \param sort_fn Pointer to a sort function. (NULL to not sort the buckets.)
1297 * \param cmp_fn Pointer to a compare function used by ao2_find. (NULL to match everything)
1298 *
1299 * \return A pointer to a struct container.
1300 *
1301 * \note Destructor is set implicitly.
1302 */
1303#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn) \
1304 __ao2_container_alloc_hash((ao2_options), (container_options), (n_buckets), (hash_fn), (sort_fn), (cmp_fn), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1305
1306#define ao2_t_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn, tag) \
1307 __ao2_container_alloc_hash((ao2_options), (container_options), (n_buckets), (hash_fn), (sort_fn), (cmp_fn), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1308
1309struct ao2_container *__ao2_container_alloc_hash(unsigned int ao2_options,
1310 unsigned int container_options, unsigned int n_buckets, ao2_hash_fn *hash_fn,
1312 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
1313
1314/*!
1315 * \brief Allocate and initialize a list container.
1316 *
1317 * \param ao2_options Container ao2 object options (See enum ao2_alloc_opts)
1318 * \param container_options Container behaviour options (See enum ao2_container_opts)
1319 * \param sort_fn Pointer to a sort function. (NULL if list not sorted.)
1320 * \param cmp_fn Pointer to a compare function used by ao2_find. (NULL to match everything)
1321 *
1322 * \return A pointer to a struct container.
1323 *
1324 * \note Destructor is set implicitly.
1325 * \note Implemented as a degenerate hash table.
1326 */
1327#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn) \
1328 __ao2_container_alloc_list((ao2_options), (container_options), (sort_fn), (cmp_fn), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1329
1330#define ao2_t_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn, tag) \
1331 __ao2_container_alloc_list((ao2_options), (container_options), (sort_fn), (cmp_fn), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1332
1333struct ao2_container *__ao2_container_alloc_list(unsigned int ao2_options,
1334 unsigned int container_options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn,
1335 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
1336
1337/*!
1338 * \brief Allocate and initialize a red-black tree container.
1339 *
1340 * \param ao2_options Container ao2 object options (See enum ao2_alloc_opts)
1341 * \param container_options Container behaviour options (See enum ao2_container_opts)
1342 * \param sort_fn Pointer to a sort function.
1343 * \param cmp_fn Pointer to a compare function used by ao2_find. (NULL to match everything)
1344 *
1345 * \return A pointer to a struct container.
1346 *
1347 * \note Destructor is set implicitly.
1348 */
1349#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn) \
1350 __ao2_container_alloc_rbtree((ao2_options), (container_options), (sort_fn), (cmp_fn), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1351
1352#define ao2_t_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn, tag) \
1353 __ao2_container_alloc_rbtree((ao2_options), (container_options), (sort_fn), (cmp_fn), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1354
1355struct ao2_container *__ao2_container_alloc_rbtree(unsigned int ao2_options, unsigned int container_options,
1357 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
1358
1359/*! \brief
1360 * Returns the number of elements in a container.
1361 */
1363
1364/*!
1365 * \brief Copy all object references in the src container into the dest container.
1366 * \since 11.0
1367 *
1368 * \param dest Container to copy src object references into.
1369 * \param src Container to copy all object references from.
1370 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
1371 * Otherwise, the src container is locked first.
1372 *
1373 * \pre The dest container must be empty. If the duplication fails, the
1374 * dest container will be returned empty.
1375 *
1376 * \note This can potentially be expensive because a malloc is
1377 * needed for every object in the src container.
1378 *
1379 * \retval 0 on success.
1380 * \retval -1 on error.
1381 */
1382int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
1383
1384/*!
1385 * \brief Copy object references associated with src container weakproxies into the dest container.
1386 *
1387 * \param dest Container to copy src strong object references into.
1388 * \param src Container to copy all weak object references from.
1389 * \param flags OBJ_NOLOCK if a lock is already held on both containers.
1390 * Otherwise, the src container is locked first.
1391 *
1392 * \pre The dest container must be empty. If the duplication fails, the
1393 * dest container will be returned empty.
1394 *
1395 * \note This can potentially be expensive because a malloc is
1396 * needed for every object in the src container.
1397 *
1398 * \note Every object inside the container is locked by \ref ao2_weakproxy_get_object.
1399 * Any weakproxy in \p src with no associated object is ignored.
1400 *
1401 * \retval 0 on success.
1402 * \retval -1 on error.
1403 */
1404int ao2_container_dup_weakproxy_objs(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags);
1405
1406/*!
1407 * \brief Create a clone/copy of the given container.
1408 * \since 11.0
1409 *
1410 * \param orig Container to copy all object references from.
1411 * \param flags OBJ_NOLOCK if a lock is already held on the container.
1412 *
1413 * \note This can potentially be expensive because a malloc is
1414 * needed for every object in the orig container.
1415 *
1416 * \return Clone container on success.
1417 * \retval NULL on error.
1418 */
1419#define ao2_container_clone(orig, flags) \
1420 __ao2_container_clone(orig, flags, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1421
1422#define ao2_t_container_clone(orig, flags, tag) \
1423 __ao2_container_clone(orig, flags, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1424
1425struct ao2_container *__ao2_container_clone(struct ao2_container *orig, enum search_flags flags,
1426 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
1427
1428/*!
1429 * \brief Print output.
1430 * \since 12.0.0
1431 *
1432 * \param where User data pointer needed to determine where to put output.
1433 * \param fmt printf type format string.
1434 */
1435typedef void (ao2_prnt_fn)(void *where, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
1436
1437/*!
1438 * \brief Print object key.
1439 * \since 12.0.0
1440 *
1441 * \param v_obj A pointer to the object we want the key printed.
1442 * \param where User data needed by prnt to determine where to put output.
1443 * \param prnt Print output callback function to use.
1444 */
1445typedef void (ao2_prnt_obj_fn)(void *v_obj, void *where, ao2_prnt_fn *prnt);
1446
1447/*!
1448 * \brief Display contents of the specified container.
1449 * \since 12.0.0
1450 *
1451 * \param self Container to dump.
1452 * \param flags OBJ_NOLOCK if a lock is already held on the container.
1453 * \param name Container name. (NULL if anonymous)
1454 * \param where User data needed by prnt to determine where to put output.
1455 * \param prnt Print output callback function to use.
1456 * \param prnt_obj Callback function to print the given object's key. (NULL if not available)
1457 */
1458void ao2_container_dump(struct ao2_container *self, enum search_flags flags, const char *name, void *where, ao2_prnt_fn *prnt, ao2_prnt_obj_fn *prnt_obj);
1459
1460/*!
1461 * \brief Display statistics of the specified container.
1462 * \since 12.0.0
1463 *
1464 * \param self Container to display statistics.
1465 * \param flags OBJ_NOLOCK if a lock is already held on the container.
1466 * \param name Container name. (NULL if anonymous)
1467 * \param where User data needed by prnt to determine where to put output.
1468 * \param prnt Print output callback function to use.
1469 */
1470void ao2_container_stats(struct ao2_container *self, enum search_flags flags, const char *name, void *where, ao2_prnt_fn *prnt);
1471
1472/*!
1473 * \brief Perform an integrity check on the specified container.
1474 * \since 12.0.0
1475 *
1476 * \param self Container to check integrity.
1477 * \param flags OBJ_NOLOCK if a lock is already held on the container.
1478 *
1479 * \retval 0 on success.
1480 * \retval -1 on error.
1481 */
1482int ao2_container_check(struct ao2_container *self, enum search_flags flags);
1483
1484/*!
1485 * \brief Register a container for CLI stats and integrity check.
1486 * \since 12.0.0
1487 *
1488 * \param name Name to register the container under.
1489 * \param self Container to register.
1490 * \param prnt_obj Callback function to print the given object's key. (NULL if not available)
1491 *
1492 * \retval 0 on success.
1493 * \retval -1 on error.
1494 */
1495int ao2_container_register(const char *name, struct ao2_container *self, ao2_prnt_obj_fn *prnt_obj);
1496
1497/*!
1498 * \brief Unregister a container for CLI stats and integrity check.
1499 * \since 12.0.0
1500 *
1501 * \param name Name the container is registered under.
1502 */
1503void ao2_container_unregister(const char *name);
1504
1505/*! @} */
1506
1507/*! \name Object Management
1508 * Here we have functions to manage objects.
1509 *
1510 * We can use the functions below on any kind of
1511 * object defined by the user.
1512 *
1513 * @{
1514 */
1515
1516/*!
1517 * \brief Add an object to a container.
1518 *
1519 * \param container The container to operate on.
1520 * \param obj The object to be added.
1521 *
1522 * \retval 0 on errors.
1523 * \retval 1 on success.
1524 *
1525 * This function inserts an object in a container according its key.
1526 *
1527 * \note Remember to set the key before calling this function.
1528 *
1529 * \note This function automatically increases the reference count to account
1530 * for the reference that the container now holds to the object.
1531 */
1532#define ao2_link(container, obj) \
1533 __ao2_link((container), (obj), 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1534#define ao2_t_link(container, obj, tag) \
1535 __ao2_link((container), (obj), 0, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1536
1537/*!
1538 * \brief Add an object to a container.
1539 *
1540 * \param container The container to operate on.
1541 * \param obj The object to be added.
1542 * \param flags search_flags to control linking the object. (OBJ_NOLOCK)
1543 *
1544 * \retval 0 on errors.
1545 * \retval 1 on success.
1546 *
1547 * This function inserts an object in a container according its key.
1548 *
1549 * \note Remember to set the key before calling this function.
1550 *
1551 * \note This function automatically increases the reference count to account
1552 * for the reference that the container now holds to the object.
1553 */
1554#define ao2_link_flags(container, obj, flags) \
1555 __ao2_link((container), (obj), (flags), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1556#define ao2_t_link_flags(container, obj, flags, tag) \
1557 __ao2_link((container), (obj), (flags), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1558
1559int __ao2_link(struct ao2_container *c, void *obj_new, int flags,
1560 const char *tag, const char *file, int line, const char *func);
1561
1562/*!
1563 * \brief Remove an object from a container
1564 *
1565 * \param container The container to operate on.
1566 * \param obj The object to unlink.
1567 *
1568 * \retval NULL always
1569 *
1570 * \note The object requested to be unlinked must be valid. However, if it turns
1571 * out that it is not in the container, this function is still safe to
1572 * be called.
1573 *
1574 * \note If the object gets unlinked from the container, the container's
1575 * reference to the object will be automatically released. (The
1576 * refcount will be decremented).
1577 */
1578#define ao2_unlink(container, obj) \
1579 __ao2_unlink((container), (obj), 0, NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1580#define ao2_t_unlink(container, obj, tag) \
1581 __ao2_unlink((container), (obj), 0, (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1582
1583/*!
1584 * \brief Remove an object from a container
1585 *
1586 * \param container The container to operate on.
1587 * \param obj The object to unlink.
1588 * \param flags search_flags to control unlinking the object. (OBJ_NOLOCK)
1589 *
1590 * \retval NULL always
1591 *
1592 * \note The object requested to be unlinked must be valid. However, if it turns
1593 * out that it is not in the container, this function is still safe to
1594 * be called.
1595 *
1596 * \note If the object gets unlinked from the container, the container's
1597 * reference to the object will be automatically released. (The
1598 * refcount will be decremented).
1599 */
1600#define ao2_unlink_flags(container, obj, flags) \
1601 __ao2_unlink((container), (obj), (flags), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1602
1603#define ao2_t_unlink_flags(container, obj, flags, tag) \
1604 __ao2_unlink((container), (obj), (flags), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1605
1606void *__ao2_unlink(struct ao2_container *c, void *obj, int flags,
1607 const char *tag, const char *file, int line, const char *func);
1608
1609/*! @} */
1610
1611
1612/*! \brief
1613 * ao2_callback() is a generic function that applies cb_fn() to all objects
1614 * in a container, as described below.
1615 *
1616 * \param c A pointer to the container to operate on.
1617 * \param flags A set of flags specifying the operation to perform,
1618 * partially used by the container code, but also passed to
1619 * the callback.
1620 * - If OBJ_NODATA is set, ao2_callback will return NULL. No refcounts
1621 * of any of the traversed objects will be incremented.
1622 * On the converse, if it is NOT set (the default), the ref count
1623 * of the first matching object will be incremented and returned.
1624 * - If OBJ_MULTIPLE is set, the ref count of all matching objects will
1625 * be incremented in an iterator for a temporary container and returned.
1626 * - If OBJ_SEARCH_OBJECT is set, the traversed items will be restricted
1627 * to the objects in the bucket that the object key hashes to.
1628 * - If OBJ_SEARCH_KEY is set, the traversed items will be restricted
1629 * to the objects in the bucket that the object key hashes to.
1630 * \param cb_fn A function pointer, that will be called on all
1631 * objects, to see if they match. This function returns CMP_MATCH
1632 * if the object is matches the criteria; CMP_STOP if the traversal
1633 * should immediately stop, or both (via bitwise ORing), if you find a
1634 * match and want to end the traversal, and 0 if the object is not a match,
1635 * but the traversal should continue. This is the function that is applied
1636 * to each object traversed. Its arguments are:
1637 * (void *obj, void *arg, int flags), where:
1638 * obj is an object
1639 * arg is the same as arg passed into ao2_callback
1640 * flags is the same as flags passed into ao2_callback (flags are
1641 * also used by ao2_callback).
1642 * \param arg passed to the callback.
1643 *
1644 * \retval NULL on failure or no matching object found.
1645 *
1646 * \return object found if OBJ_MULTIPLE is not set in the flags
1647 * parameter.
1648 *
1649 * \return ao2_iterator pointer if OBJ_MULTIPLE is set in the
1650 * flags parameter. The iterator must be destroyed with
1651 * ao2_iterator_destroy() when the caller no longer needs it.
1652 *
1653 * If the function returns any objects, their refcount is incremented,
1654 * and the caller is in charge of decrementing them once done.
1655 *
1656 * Typically, ao2_callback() is used for two purposes:
1657 * - to perform some action (including removal from the container) on one
1658 * or more objects; in this case, cb_fn() can modify the object itself,
1659 * and to perform deletion should set CMP_MATCH on the matching objects,
1660 * and have OBJ_UNLINK set in flags.
1661 * - to look for a specific object in a container; in this case, cb_fn()
1662 * should not modify the object, but just return a combination of
1663 * CMP_MATCH and CMP_STOP on the desired object.
1664 * Other usages are also possible, of course.
1665 *
1666 * This function searches through a container and performs operations
1667 * on objects according on flags passed.
1668 * XXX describe better
1669 * The comparison is done calling the compare function set implicitly.
1670 * The arg pointer can be a pointer to an object or to a key,
1671 * we can say this looking at flags value.
1672 * If arg points to an object we will search for the object pointed
1673 * by this value, otherwise we search for a key value.
1674 * If the key is not unique we only find the first matching value.
1675 *
1676 * The use of flags argument is the follow:
1677 *
1678 * OBJ_UNLINK unlinks the object found
1679 * OBJ_NODATA on match, do not return an object
1680 * Callbacks use OBJ_NODATA as a default
1681 * functions such as find() do
1682 * OBJ_MULTIPLE return multiple matches
1683 * Default is no.
1684 * OBJ_SEARCH_OBJECT the pointer is to an object
1685 * OBJ_SEARCH_KEY the pointer is to a search key
1686 * OBJ_SEARCH_PARTIAL_KEY the pointer is to a partial search key
1687 *
1688 * \note When the returned object is no longer in use, ao2_ref() should
1689 * be used to free the additional reference possibly created by this function.
1690 *
1691 * @{
1692 */
1693#define ao2_callback(c, flags, cb_fn, arg) \
1694 __ao2_callback((c), (flags), (cb_fn), (arg), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1695
1696#define ao2_t_callback(c, flags, cb_fn, arg, tag) \
1697 __ao2_callback((c), (flags), (cb_fn), (arg), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1698
1699void *__ao2_callback(struct ao2_container *c, enum search_flags flags,
1700 ao2_callback_fn *cb_fn, void *arg, const char *tag, const char *file, int line,
1701 const char *func);
1702
1703/*! @} */
1704
1705/*! \brief
1706 * ao2_callback_data() is a generic function that applies cb_fn() to all objects
1707 * in a container. It is functionally identical to ao2_callback() except that
1708 * instead of taking an ao2_callback_fn *, it takes an ao2_callback_data_fn *, and
1709 * allows the caller to pass in arbitrary data.
1710 *
1711 * This call would be used instead of ao2_callback() when the caller needs to pass
1712 * OBJ_SEARCH_OBJECT, OBJ_SEARCH_KEY, or OBJ_SEARCH_PARTIAL_KEY as part of the flags
1713 * argument (which in turn requires passing in a known pointer type for 'arg') and
1714 * also needs access to other non-global data to complete it's comparison or task.
1715 *
1716 * See the documentation for ao2_callback() for argument descriptions.
1717 *
1718 * \see ao2_callback()
1719 */
1720
1721#define ao2_t_callback_data(container, flags, cb_fn, arg, data, tag) \
1722 __ao2_callback_data((container), (flags), (cb_fn), (arg), (data), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1723#define ao2_callback_data(container, flags, cb_fn, arg, data) \
1724 __ao2_callback_data((container), (flags), (cb_fn), (arg), (data), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1725
1726void *__ao2_callback_data(struct ao2_container *c, enum search_flags flags,
1727 ao2_callback_data_fn *cb_fn, void *arg, void *data, const char *tag, const char *file,
1728 int line, const char *func);
1729
1730/*! ao2_find() is a short hand for ao2_callback(c, flags, c->cmp_fn, arg)
1731 * XXX possibly change order of arguments ?
1732 */
1733
1734#define ao2_t_find(container, arg, flags, tag) \
1735 __ao2_find((container), (arg), (flags), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1736#define ao2_find(container, arg, flags) \
1737 __ao2_find((container), (arg), (flags), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1738
1739void *__ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags,
1740 const char *tag, const char *file, int line, const char *func);
1741
1742/*!
1743 * \brief Perform an ao2_find on a container with ao2_weakproxy objects, returning the real object.
1744 *
1745 * \note Only OBJ_SEARCH_* and OBJ_NOLOCK flags are supported by this function.
1746 * \see ao2_callback for description of arguments.
1747 */
1748#define ao2_weakproxy_find(c, arg, flags, tag) \
1749 __ao2_weakproxy_find(c, arg, flags, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1750void *__ao2_weakproxy_find(struct ao2_container *c, const void *arg, enum search_flags flags,
1751 const char *tag, const char *file, int line, const char *func);
1752
1753/*! \brief
1754 *
1755 *
1756 * When we need to walk through a container, we use an
1757 * ao2_iterator to keep track of the current position.
1758 *
1759 * Because the navigation is typically done without holding the
1760 * lock on the container across the loop, objects can be
1761 * inserted or deleted or moved while we work. As a
1762 * consequence, there is no guarantee that we manage to touch
1763 * all the elements in the container, and it is possible that we
1764 * touch the same object multiple times.
1765 *
1766 * An iterator must be first initialized with
1767 * ao2_iterator_init(), then we can use o = ao2_iterator_next()
1768 * to move from one element to the next. Remember that the
1769 * object returned by ao2_iterator_next() has its refcount
1770 * incremented, and the reference must be explicitly released
1771 * when done with it.
1772 *
1773 * In addition, ao2_iterator_init() will hold a reference to the
1774 * container being iterated and the last container node found.
1775 * These objects will be unreffed when ao2_iterator_destroy() is
1776 * called to free up the resources used by the iterator (if
1777 * any).
1778 *
1779 * Example:
1780 *
1781 * \code
1782 *
1783 * struct ao2_container *c = ... // the container we want to iterate on
1784 * struct ao2_iterator i;
1785 * struct my_obj *o;
1786 *
1787 * i = ao2_iterator_init(c, flags);
1788 *
1789 * while ((o = ao2_iterator_next(&i))) {
1790 * ... do something on o ...
1791 * ao2_ref(o, -1);
1792 * }
1793 *
1794 * ao2_iterator_restart(&i);
1795 * while ((o = ao2_iterator_next(&i))) {
1796 * ... do something on o ...
1797 * ao2_ref(o, -1);
1798 * }
1799 *
1800 * ao2_iterator_destroy(&i);
1801 *
1802 * \endcode
1803 *
1804 */
1805
1806/*!
1807 * \brief The astobj2 iterator
1808 *
1809 * \note You are not supposed to know the internals of an iterator!
1810 * We would like the iterator to be opaque, unfortunately
1811 * its size needs to be known if we want to store it around
1812 * without too much trouble.
1813 * Anyways...
1814 * The iterator has a pointer to the container, and a flags
1815 * field specifying various things e.g. whether the container
1816 * should be locked or not while navigating on it.
1817 * The iterator "points" to the current container node.
1818 *
1819 * Details are in the implementation of ao2_iterator_next()
1820 */
1822 /*! The container (Has a reference) */
1824 /*! Last container node (Has a reference) */
1826 /*! Nonzero if the iteration has completed. */
1828 /*! operation flags (enum ao2_iterator_flags) */
1830};
1831
1832/*! Flags that can be passed to ao2_iterator_init() to modify the behavior
1833 * of the iterator.
1834 */
1836 /*!
1837 * \brief Assume that the ao2_container is already locked.
1838 *
1839 * \note For ao2_containers that have mutexes, no locking will
1840 * be done.
1841 *
1842 * \note For ao2_containers that have RWLOCKs, the lock will be
1843 * promoted to write mode as needed. The lock will be returned
1844 * to the original locked state.
1845 *
1846 * \note Only use this flag if the ao2_container is manually
1847 * locked already. You should hold the lock until after
1848 * ao2_iterator_destroy(). If you must release the lock then
1849 * you must at least hold the lock whenever you call an
1850 * ao2_iterator_xxx function with this iterator.
1851 */
1853 /*!
1854 * Indicates that the iterator was dynamically allocated by
1855 * astobj2 API and should be freed by ao2_iterator_destroy().
1856 */
1858 /*!
1859 * Indicates that before the iterator returns an object from
1860 * the container being iterated, the object should be unlinked
1861 * from the container.
1862 */
1864 /*!
1865 * Iterate in descending order (Last to first container object)
1866 * (Otherwise ascending order)
1867 *
1868 * \note Other traversal orders such as pre-order and post-order
1869 * do not make sense because they require the container
1870 * structure to be static during the traversal. Iterators just
1871 * about guarantee that is not going to happen because the
1872 * container is allowed to change by other threads during the
1873 * iteration.
1874 */
1876};
1877
1878/*!
1879 * \brief Create an iterator for a container
1880 *
1881 * \param c the container
1882 * \param flags one or more flags from ao2_iterator_flags.
1883 *
1884 * \return the constructed iterator
1885 *
1886 * \note This function does \b not take a pointer to an iterator;
1887 * rather, it returns an iterator structure that should be
1888 * assigned to (overwriting) an existing iterator structure
1889 * allocated on the stack or on the heap.
1890 *
1891 * This function will take a reference on the container being iterated.
1892 */
1894
1895/*!
1896 * \brief Destroy a container iterator
1897 *
1898 * \param iter the iterator to destroy
1899 *
1900 * This function will release the container reference held by the iterator
1901 * and any other resources it may be holding.
1902 */
1903#if defined(TEST_FRAMEWORK)
1904void ao2_iterator_destroy(struct ao2_iterator *iter) __attribute__((noinline));
1905#else
1906void ao2_iterator_destroy(struct ao2_iterator *iter);
1907#endif /* defined(TEST_FRAMEWORK) */
1908
1909#define ao2_t_iterator_next(iter, tag) \
1910 __ao2_iterator_next((iter), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1911#define ao2_iterator_next(iter) \
1912 __ao2_iterator_next((iter), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1913
1914void *__ao2_iterator_next(struct ao2_iterator *iter,
1915 const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result;
1916
1917/*!
1918 * \brief Restart an iteration.
1919 *
1920 * \param iter the iterator to restart
1921 *
1922 * \note A restart is not going to have any effect if the
1923 * iterator was created with the AO2_ITERATOR_UNLINK flag. Any
1924 * previous objects returned were removed from the container.
1925 */
1926void ao2_iterator_restart(struct ao2_iterator *iter);
1927
1928/*! gcc __attribute__(cleanup()) functions
1929 * \note they must be able to handle NULL parameters because most of the
1930 * allocation/find functions can fail and we don't want to try to tear
1931 * down a NULL */
1932void __ao2_cleanup(void *obj);
1933void __ao2_cleanup_debug(void *obj, const char *tag, const char *file, int line, const char *function);
1934#define ao2_cleanup(obj) __ao2_cleanup_debug((obj), NULL, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1935#define ao2_t_cleanup(obj, tag) __ao2_cleanup_debug((obj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
1936void ao2_iterator_cleanup(struct ao2_iterator *iter);
1937
1938/*!
1939 * \brief Get a count of the iterated container objects.
1940 *
1941 * \param iter the iterator to query
1942 *
1943 * \return The number of objects in the iterated container
1944 */
1945int ao2_iterator_count(struct ao2_iterator *iter);
1946
1947/*!
1948 * \brief Creates a hash function for a structure field.
1949 * \param stype The structure type
1950 * \param field The string field in the structure to hash
1951 * \param hash_fn Function which hashes the field
1952 *
1953 * AO2_FIELD_HASH_FN(mystruct, myfield, ast_str_hash) will
1954 * produce a function named mystruct_hash_fn which hashes
1955 * mystruct->myfield with ast_str_hash.
1956 */
1957#define AO2_FIELD_HASH_FN(stype, field, hash_fn) \
1958static int stype ## _hash_fn(const void *obj, const int flags) \
1959{ \
1960 const struct stype *object = obj; \
1961 const char *key; \
1962 switch (flags & OBJ_SEARCH_MASK) { \
1963 case OBJ_SEARCH_KEY: \
1964 key = obj; \
1965 break; \
1966 case OBJ_SEARCH_OBJECT: \
1967 key = object->field; \
1968 break; \
1969 default: \
1970 ast_assert(0); \
1971 return 0; \
1972 } \
1973 return hash_fn(key); \
1974}
1975
1976
1977#define AO2_FIELD_TRANSFORM_CMP_FN(cmp) ((cmp) ? 0 : CMP_MATCH)
1978#define AO2_FIELD_TRANSFORM_SORT_FN(cmp) (cmp)
1979
1980/*!
1981 * \internal
1982 *
1983 * \brief Creates a compare function for a structure string field.
1984 * \param stype The structure type
1985 * \param fn_suffix Function name suffix
1986 * \param field The string field in the structure to compare
1987 * \param key_cmp Key comparison function like strcmp
1988 * \param partial_key_cmp Partial key comparison function like strncmp
1989 * \param transform A macro that takes the cmp result as an argument
1990 * and transforms it to a return value.
1991 * \param argconst
1992 *
1993 * Do not use this macro directly, instead use macro's starting with
1994 * AST_STRING_FIELD.
1995 *
1996 * \warning The macro is an internal implementation detail, the API
1997 * may change at any time.
1998 */
1999#define AO2_FIELD_CMP_FN(stype, fn_suffix, field, key_cmp, partial_key_cmp, transform, argconst) \
2000static int stype ## fn_suffix(argconst void *obj, argconst void *arg, int flags) \
2001{ \
2002 const struct stype *object_left = obj, *object_right = arg; \
2003 const char *right_key = arg; \
2004 int cmp; \
2005 switch (flags & OBJ_SEARCH_MASK) { \
2006 case OBJ_SEARCH_OBJECT: \
2007 right_key = object_right->field; \
2008 case OBJ_SEARCH_KEY: \
2009 cmp = key_cmp(object_left->field, right_key); \
2010 break; \
2011 case OBJ_SEARCH_PARTIAL_KEY: \
2012 cmp = partial_key_cmp(object_left->field, right_key, strlen(right_key)); \
2013 break; \
2014 default: \
2015 cmp = 0; \
2016 break; \
2017 } \
2018 return transform(cmp); \
2019}
2020
2021/*!
2022 * \brief Creates a hash function for a structure string field.
2023 * \param stype The structure type
2024 * \param field The string field in the structure to hash
2025 *
2026 * AO2_STRING_FIELD_HASH_FN(mystruct, myfield) will produce a function
2027 * named mystruct_hash_fn which hashes mystruct->myfield.
2028 *
2029 * AO2_STRING_FIELD_HASH_FN(mystruct, myfield) would do the same except
2030 * it uses the hash function which ignores case.
2031 */
2032#define AO2_STRING_FIELD_HASH_FN(stype, field) \
2033 AO2_FIELD_HASH_FN(stype, field, ast_str_hash)
2034#define AO2_STRING_FIELD_CASE_HASH_FN(stype, field) \
2035 AO2_FIELD_HASH_FN(stype, field, ast_str_case_hash)
2036
2037/*!
2038 * \brief Creates a compare function for a structure string field.
2039 * \param stype The structure type
2040 * \param field The string field in the structure to compare
2041 *
2042 * AO2_STRING_FIELD_CMP_FN(mystruct, myfield) will produce a function
2043 * named mystruct_cmp_fn which compares mystruct->myfield.
2044 *
2045 * AO2_STRING_FIELD_CASE_CMP_FN(mystruct, myfield) would do the same
2046 * except it performs case insensitive comparisons.
2047 */
2048#define AO2_STRING_FIELD_CMP_FN(stype, field) \
2049 AO2_FIELD_CMP_FN(stype, _cmp_fn, field, strcmp, strncmp, AO2_FIELD_TRANSFORM_CMP_FN,)
2050#define AO2_STRING_FIELD_CASE_CMP_FN(stype, field) \
2051 AO2_FIELD_CMP_FN(stype, _cmp_fn, field, strcasecmp, strncasecmp, AO2_FIELD_TRANSFORM_CMP_FN,)
2052
2053/*!
2054 * \brief Creates a sort function for a structure string field.
2055 * \param stype The structure type
2056 * \param field The string field in the structure to compare
2057 *
2058 * AO2_STRING_FIELD_SORT_FN(mystruct, myfield) will produce a function
2059 * named mystruct_sort_fn which compares mystruct->myfield.
2060 *
2061 * AO2_STRING_FIELD_CASE_SORT_FN(mystruct, myfield) would do the same
2062 * except it performs case insensitive comparisons.
2063 */
2064#define AO2_STRING_FIELD_SORT_FN(stype, field) \
2065 AO2_FIELD_CMP_FN(stype, _sort_fn, field, strcmp, strncmp, AO2_FIELD_TRANSFORM_SORT_FN, const)
2066#define AO2_STRING_FIELD_CASE_SORT_FN(stype, field) \
2067 AO2_FIELD_CMP_FN(stype, _sort_fn, field, strcasecmp, strncasecmp, AO2_FIELD_TRANSFORM_SORT_FN, const)
2068
2069#endif /* _ASTERISK_ASTOBJ2_H */
#define var
Definition: ast_expr2f.c:605
void * __ao2_global_obj_replace(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name) attribute_warn_unused_result
void * __ao2_iterator_next(struct ao2_iterator *iter, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
void() ao2_prnt_obj_fn(void *v_obj, void *where, ao2_prnt_fn *prnt)
Print object key.
Definition: astobj2.h:1445
int ao2_weakproxy_unsubscribe(void *weakproxy, ao2_weakproxy_notification_cb cb, void *data, int flags)
Remove notification of real object destruction.
Definition: astobj2.c:973
int ao2_weakproxy_subscribe(void *weakproxy, ao2_weakproxy_notification_cb cb, void *data, int flags)
Request notification when weakproxy points to NULL.
Definition: astobj2.c:934
unsigned int ao2_options_get(void *obj)
Retrieve the ao2 options used to create the object.
Definition: astobj2.c:781
_cb_results
A callback function will return a combination of CMP_MATCH and CMP_STOP. The latter will terminate th...
Definition: astobj2.h:1026
@ CMP_MATCH
Definition: astobj2.h:1027
@ CMP_STOP
Definition: astobj2.h:1028
void * __ao2_global_obj_ref(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name) attribute_warn_unused_result
ao2_alloc_opts
Options available when allocating an ao2 object.
Definition: astobj2.h:361
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_OBJ
Definition: astobj2.h:376
@ AO2_ALLOC_OPT_LOCK_RWLOCK
Definition: astobj2.h:365
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
@ AO2_ALLOC_OPT_LOCK_MASK
Definition: astobj2.h:369
@ AO2_ALLOC_OPT_NO_REF_DEBUG
Definition: astobj2.h:378
void ao2_iterator_cleanup(struct ao2_iterator *iter)
int __ao2_trylock(void *a, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var)
Try locking– (don't block if fail)
Definition: astobj2.c:342
int ao2_container_dup_weakproxy_objs(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy object references associated with src container weakproxies into the dest container.
int ao2_match_by_addr(void *obj, void *arg, int flags)
A common ao2_callback is one that matches by address.
int ao2_container_check(struct ao2_container *self, enum search_flags flags)
Perform an integrity check on the specified container.
void * __ao2_callback_data(struct ao2_container *c, enum search_flags flags, ao2_callback_data_fn *cb_fn, void *arg, void *data, const char *tag, const char *file, int line, const char *func)
void ao2_container_unregister(const char *name)
Unregister a container for CLI stats and integrity check.
ao2_lock_req
Which lock to request.
Definition: astobj2.h:700
@ AO2_LOCK_REQ_MUTEX
Definition: astobj2.h:702
@ AO2_LOCK_REQ_WRLOCK
Definition: astobj2.h:706
@ AO2_LOCK_REQ_RDLOCK
Definition: astobj2.h:704
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
void * __ao2_callback(struct ao2_container *c, enum search_flags flags, ao2_callback_fn *cb_fn, void *arg, const char *tag, const char *file, int line, const char *func)
void * __ao2_weakproxy_get_object(void *weakproxy, int flags, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:889
void(* ao2_weakproxy_notification_cb)(void *weakproxy, void *data)
Definition: astobj2.h:526
void ao2_container_stats(struct ao2_container *self, enum search_flags flags, const char *name, void *where, ao2_prnt_fn *prnt)
Display statistics of the specified container.
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
Definition: astobj2.h:1226
ao2_iterator_flags
Definition: astobj2.h:1835
@ AO2_ITERATOR_UNLINK
Definition: astobj2.h:1863
@ AO2_ITERATOR_DONTLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1852
@ AO2_ITERATOR_MALLOCD
Definition: astobj2.h:1857
@ AO2_ITERATOR_DESCENDING
Definition: astobj2.h:1875
int __ao2_weakproxy_ref_object(void *weakproxy, int delta, int flags, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:862
void(* ao2_destructor_fn)(void *vdoomed)
Typedef for an object destructor.
Definition: astobj2.h:358
int __ao2_link(struct ao2_container *c, void *obj_new, int flags, const char *tag, const char *file, int line, const char *func)
int ao2_ref_and_lock(void *obj)
Increment reference count on an object and lock it.
Definition: astobj2.h:780
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
int ao2_iterator_count(struct ao2_iterator *iter)
Get a count of the iterated container objects.
int() ao2_sort_fn(const void *obj_left, const void *obj_right, int flags)
Type of generic container sort function.
Definition: astobj2.h:1276
void ao2_iterator_restart(struct ao2_iterator *iter)
Restart an iteration.
#define ao2_unlock(a)
Definition: astobj2.h:729
struct ao2_container * __ao2_container_alloc_list(unsigned int ao2_options, unsigned int container_options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
struct ao2_container * __ao2_container_alloc_rbtree(unsigned int ao2_options, unsigned int container_options, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
void * __ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
int() ao2_hash_fn(const void *obj, int flags)
Definition: astobj2.h:1258
int __ao2_weakproxy_set_object(void *weakproxy, void *obj, int flags, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:818
struct ao2_container * __ao2_container_alloc_hash(unsigned int ao2_options, unsigned int container_options, unsigned int n_buckets, ao2_hash_fn *hash_fn, ao2_sort_fn *sort_fn, ao2_callback_fn *cmp_fn, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
#define ao2_lock(a)
Definition: astobj2.h:717
void * __ao2_weakproxy_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ao2_container * __ao2_container_clone(struct ao2_container *orig, enum search_flags flags, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
int __ao2_global_obj_replace_unref(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
void __ao2_cleanup(void *obj)
Definition: astobj2.c:677
int ao2_container_register(const char *name, struct ao2_container *self, ao2_prnt_obj_fn *prnt_obj)
Register a container for CLI stats and integrity check.
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
Definition: astobj2.c:476
void ao2_container_dump(struct ao2_container *self, enum search_flags flags, const char *name, void *where, ao2_prnt_fn *prnt, ao2_prnt_obj_fn *prnt_obj)
Display contents of the specified container.
void * __ao2_weakproxy_alloc(size_t data_size, ao2_destructor_fn destructor_fn, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:793
void __ao2_cleanup_debug(void *obj, const char *tag, const char *file, int line, const char *function)
Definition: astobj2.c:670
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int() ao2_callback_data_fn(void *obj, void *arg, void *data, int flags)
Type of a generic callback function.
Definition: astobj2.h:1244
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
search_flags
Flags passed to ao2_callback_fn(), ao2_hash_fn(), and ao2_sort_fn() to modify behaviour.
Definition: astobj2.h:1034
@ OBJ_ORDER_MASK
Traverse order option field mask.
Definition: astobj2.h:1119
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
@ OBJ_ORDER_DESCENDING
Traverse in descending order (Last to first container object)
Definition: astobj2.h:1123
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_ORDER_PRE
Traverse in pre-order (Node then children, for tree container)
Definition: astobj2.h:1132
@ OBJ_ORDER_ASCENDING
Traverse in ascending order (First to last container object)
Definition: astobj2.h:1121
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
@ OBJ_ORDER_POST
Traverse in post-order (Children then node, for tree container)
Definition: astobj2.h:1141
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
@ OBJ_SEARCH_NONE
The arg parameter has no meaning to the astobj2 code.
Definition: astobj2.h:1074
void * __ao2_unlink(struct ao2_container *c, void *obj, int flags, const char *tag, const char *file, int line, const char *func)
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:768
int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var)
Unlock an object.
Definition: astobj2.c:288
int __ao2_lock(void *a, enum ao2_lock_req lock_how, const char *file, const char *func, int line, const char *var)
Lock an object.
Definition: astobj2.c:222
void * __ao2_alloc_with_lockobj(size_t data_size, ao2_destructor_fn destructor_fn, void *lockobj, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:774
void() ao2_prnt_fn(void *where, const char *fmt,...)
Print output.
Definition: astobj2.h:1435
int ao2_unlock_and_unref(void *obj)
Unlock an object and decrement its reference count.
Definition: astobj2.h:800
void * __ao2_get_weakproxy(void *obj, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:917
ao2_container_opts
Options available when allocating an ao2 container object.
Definition: astobj2.h:1161
@ AO2_CONTAINER_ALLOC_OPT_DUPS_OBJ_REJECT
Reject duplicate objects in container.
Definition: astobj2.h:1201
@ AO2_CONTAINER_ALLOC_OPT_INSERT_BEGIN
Insert objects at the beginning of the container. (Otherwise it is the opposite; insert at the end....
Definition: astobj2.h:1172
@ AO2_CONTAINER_ALLOC_OPT_DUPS_ALLOW
Allow objects with duplicate keys in container.
Definition: astobj2.h:1181
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT
Reject objects with duplicate keys in container.
Definition: astobj2.h:1188
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE
Replace objects with duplicate keys in container.
Definition: astobj2.h:1211
@ AO2_CONTAINER_ALLOC_OPT_DUPS_MASK
The ao2 container objects with duplicate keys option field mask.
Definition: astobj2.h:1177
#define attribute_warn_unused_result
Definition: compiler.h:71
static const char name[]
Definition: format_mp3.c:68
General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific...
Inlinable API function macro.
#define AST_INLINE_API(hdr, body)
Definition: inline_api.h:54
A set of macros to manage forward-linked lists.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
Definition: linkedlists.h:225
Asterisk locking-related definitions:
Generic container type.
ao2_callback_fn * cmp_fn
void * obj
Definition: astobj2.h:807
ast_rwlock_t lock
Definition: astobj2.h:805
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
int complete
Definition: astobj2.h:1827
struct ao2_container * c
Definition: astobj2.h:1823
void * last_node
Definition: astobj2.h:1825
This struct should be opaque, but it's size is needed.
Definition: astobj2.h:529
struct ao2_weakproxy::@186 destroyed_cb
Structure for rwlock and tracking information.
Definition: lock.h:157
static struct test_options options
static struct test_val a
static struct test_val c