[asterisk-dev] proposed astobj2 changes

Luigi Rizzo rizzo at icir.org
Thu Sep 6 10:29:58 CDT 2007


Hi,
we are revising the behaviour of ao2_callback() in degenerate cases,
i.e. when you supply cb_fn == NULL and/or the pointer is not to an
ao2_object, and we think the current set of _search_flags is not enough.

First of all, we would like to have independent control on

- the use of the builtin hash function for the container. This is
  important not only for optimizing searches, but also in the case
  we want to apply a callback to all objects in a container and not
  just to one of the hash buckets;

- whether or not the argument to ao2_callback() points to an astobj2
  object or to a generic block of data. This information is completely
  opaque for the astobj2 generic code, and as such it should not
  have any side effects there. Instead, as it is now, OBJ_POINTER
  has the side effect of forcing the use of the hash function when
  walking through the container.

So we think it is necessary to add a new flag, OBJ_NOHASH, and use
OBJ_POINTER and OBJ_NOHASH as follows:

- OBJ_NOHASH means don't use internal hash function in ao2_callback(),
  but scan the entire container. (We picked a negated name because
  we believe most of the time you do want to use the hash function,
  so 0 is a handy default);

- OBJ_POINTER is just passed as a hint to the hash and callback functions
  to tell them how to interpret the argument. In the end the astobj2 code
  knows nothing about the internals of the object.

As the addition of OBJ_NOHASH might require a bit of change to the 
existing code, it might be the case to rename OBJ_POINTER to something
slightly different so that ao2 code not in trunk will not compile and
maintainers will be forced to revise that part. 

Of course we will fix the code in trunk and 1.4 when doing these changes.

As for the interpretation of cb_fn == NULL, the comment in the current 
code says that it "matches all objects" in the container, but this is
not completely true because if flags include OBJ_POINTER, then the
callback will only apply to one hash bucket, and not to the entire container.
So, a small modification will be necessary, namely force OBJ_NOHASH when
cb_fn == NULL

Hoping there are no objections, we will try to implement these changes
in the next day or two.

	cheers
	marta and luigi



More information about the asterisk-dev mailing list