diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-08-22 20:44:23 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-08-22 20:44:23 +0000 |
commit | 72b013760eac527e5b46ed0e6ebb8246d8aa03c2 (patch) | |
tree | e9b4efbbf51e805a2079a93e75890a79e1d6e3a7 /include/asterisk/strings.h | |
parent | 3b2223fde919a450849b1578862f73832c8622ef (diff) |
Merged revisions 80362 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r80362 | russell | 2007-08-22 15:21:36 -0500 (Wed, 22 Aug 2007) | 34 lines
Merge changes from team/russell/iax_refcount.
This set of changes fixes problems with the handling of iax2_user and iax2_peer
objects. It was very possible for a thread to still hold a reference to one of
these objects while a reload operation tries to delete them. The fix here is to
ensure that all references to these objects are tracked so that they can't go away
while still in use.
To accomplish this, I used the astobj2 reference counted object model. This
code has been in one of Luigi Rizzo's branches for a long time and was primarily
developed by one of his students, Marta Carbone. I wanted to go ahead and bring
this in to 1.4 because there are other problems similar to the ones fixed by these
changes, so we might as well go ahead and use the new astobj if we're going to go
through all of the work necessary to fix the problems.
As a nice side benefit of these changes, peer and user handling got more efficient.
Using astobj2 lets us not hold the container lock for peers or users nearly as long
while iterating. Also, by changing a define at the top of chan_iax2.c, the objects
will be distributed in a hash table, drastically increasing lookup speed in these
containers, which will have a very big impact on systems that have a large number of
users or peers.
The use of the hash table will be made the default in trunk. It is not the default
in 1.4 because it changes the behavior slightly. Previously, since peers and users
were stored in memory in the same order they were specified in the configuration file,
you could influence peer and user matching order based on the order they are specified
in the configuration. The hash table does not guarantee any order in the container,
so this behavior will be going away. It just means that you have to be a little
more careful ensuring that peers and users are matched explicitly and not forcing
chan_iax2 to have to guess which user is the right one based on secret, host, and
access list settings, instead of simply using the username.
If you have any questions, feel free to ask on the asterisk-dev list.
........
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@80387 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r-- | include/asterisk/strings.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 76b58d715..d542ef8d8 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -23,6 +23,7 @@ #ifndef _ASTERISK_STRINGS_H #define _ASTERISK_STRINGS_H +#include <stdlib.h> #include <string.h> #include <stdarg.h> @@ -418,7 +419,6 @@ int ast_str_make_space(struct ast_str **buf, size_t new_len), (buf); \ }) - /*! * \brief Retrieve a thread locally stored dynamic string * @@ -662,4 +662,22 @@ int __attribute__ ((format (printf, 3, 4))) ast_str_append( } ) +/*! + * \brief Compute a hash value on a string + * + * This famous hash algorithm was written by Dan Bernstein and is + * commonly used. + * + * http://www.cse.yorku.ca/~oz/hash.html + */ +static force_inline int ast_str_hash(const char *str) +{ + int hash = 5381; + + while (*str) + hash = hash * 33 ^ *str++; + + return abs(hash); +} + #endif /* _ASTERISK_STRINGS_H */ |