[asterisk-dev] [Code Review] 4108: Weak Proxy Objects

Corey Farrell reviewboard at asterisk.org
Wed Mar 4 15:43:13 CST 2015


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/4108/
-----------------------------------------------------------

(Updated March 4, 2015, 4:43 p.m.)


Review request for Asterisk Developers, George Joseph and rmudgett.


Changes
-------

I never much liked the API naming I originally chose, but was initially focused on getting this thread safe.  I like Richard's idea that this is a weakproxy, so I've changed the code to use ao2_weakproxy as the namespace.  The only exception being ao2_get_weakproxy, as this is run against "normal" AO2 objects.  I've also made all ao2_weakproxy functions operate on weakproxy's only.  These functions now reject normal AO2 objects where weakproxy is expected.

This change also makes it possible to efficiently use weakproxy's in containers, as the weakproxy can contain it's own fields.  For weakproxy that may be put into containers, you would put the fields normally required for sort_fn, hash_fn and cmp_fn into the weakproxy.

One thing I don't like about the current API is the need to have 'struct ao2_weakproxy' as the first field of weakproxies.  I know this could be avoided by moving the field into 'struct astobj2', I'm just not sure extra storage for all AO2 objects is acceptable.  It could probably be done using another private structure (such as 'struct astobj2_lock'), but I'm not sure this is worth the added complexity to AO2.

I plan to add REF_DEBUG variants of some functions, I want to hold off on that until the API gets approval.


Summary (updated)
-----------------

Weak Proxy Objects


Repository: Asterisk


Description (updated)
-------

This implements "weak" references.  The weakproxy object is a real ao2 with normal reference counting of its own.  When a weakproxy is pointed to a normal object they hold references to each other.  The normal object is automatically freed when a single reference remains (the weakproxy).  The weakproxy also supports subscriptions that will notify callbacks when the normal object is about to be destroyed.


Diffs (updated)
-----

  /trunk/tests/test_astobj2_weaken.c PRE-CREATION 
  /trunk/main/astobj2.c 432445 
  /trunk/include/asterisk/astobj2.h 432445 

Diff: https://reviewboard.asterisk.org/r/4108/diff/


Testing (updated)
-------

Ran the included test with REF_DEBUG enabled under valgrind.  No reference leaks or improper memory access.  Though this does not test for races, I don't know of an automated way to do that.


Thanks,

Corey Farrell

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20150304/ee4f0b5a/attachment.html>


More information about the asterisk-dev mailing list