Presentation is loading. Please wait.

Presentation is loading. Please wait.

Astobj2 Joshua Colp, Senior Software Developer 1 1.

Similar presentations


Presentation on theme: "Astobj2 Joshua Colp, Senior Software Developer 1 1."— Presentation transcript:

1 Astobj2 Joshua Colp, Senior Software Developer 1 1

2 The Past Previously no consistent full featured object API
Basic linked list container existed Inconsistent locking Fragile object destruction 2 2

3 The Present Reference counted objects
Containers (hash or linked list, optional) Iterators Callbacks Container cloning Recommended for new development when applicable Unit tested 3 3

4 Objects API calls: ao2_alloc, ao2_ref
Reference counted (integer stored in object) Destructor callback called when count of 0 is reached Optionally stored in containers Optional locking (mutex, read/write, none) 4 4

5 Global Objects API calls: ao2_global_obj_release, ao2_global_obj_replace_unref Global storage area for an object Object can be replaced at any time Storage area protected by lock Used by configuration framework 5 5

6 Containers API calls: ao2_container_alloc, ao2_link, ao2_unlink
Bucket size for object distribution User provided hashing callback User provided comparison callback Linked list used for collisions, thus bucket size of 1 is a linked list Is itself a reference counted ao2 object 6 6

7 Iterators API calls: ao2_iterator_init, ao2_iterator_next, ao2_iterator_destroy Container traversal Does not keep container locked Does not require separate function for logic Must remember to release reference to object Like iterating a linked list 7 7

8 Callbacks API call: ao2_callback
Keeps container locked for each execution Executes function on object(s), can perform matching or general logic Flags to control behavior (unlink if matched, allow multiple objects, key for specific object) Can return object matched 8 8

9 Finding Objects API call: ao2_find Uses callback internally
Can specify a key or pointer to object for comparison Returns object with reference count increased 9 9

10 Resource Acquisition Is Initialization
Macro: RAII_VAR Useful when increasing an object reference count Can decrease reference count automatically when variable goes out of scope Reduces chance of reference count leaks 10 10

11 Cloning API call: ao2_container_clone Uses callback internally
Creates new duplicate container Creates copies of node objects, can be expensive, objects not copied itself 11 11

12 Potential Problems Reference count leaks, object not getting destroyed
Circular references, multiple objects not getting destroyed Inefficient hashing algorithm, decreased performance 12 12

13 Learn More Include/asterisk/astobj2.h
ence+Count+Debugging Simple example is main/cel.c Used everywhere, though. 13 13


Download ppt "Astobj2 Joshua Colp, Senior Software Developer 1 1."

Similar presentations


Ads by Google