Prevent endless loop on pool cleanup

When APR_POOL_DEBUG is set, we check up to three levels deep for a
kind of corruption of the cleanup lists where a node is duplicated
causing an endless loop and abort.

If we hit this class of corruption when not debugging, however, we'd
prefer to just ignore it in preference to looping infinitely or
aborting.

With this change, we check for immediate duplicates and simply stop
processing the cleanup list at that point potentially leaking
resources.

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Add locks on Windows to prevent race condition

We were seeing read lock failure on Windows.  Applying the patch
proposed below resolved the issue.

  http://mail-archives.apache.org/mod_mbox/apr-dev/200807.mbox/%3Cba9a54780807140154w7017d051h5f16e06ce1737060@mail.gmail.com%3E

References FreeSWITCH bug: FS-2110

Signed-off-by: Jeff Lenk <jeff@jefflenk.com>
Signed-off-by: Travis Cross <tc@traviscross.com>
vformatter should always treat ll format prefix as 64 bit

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Add apr_pool_mutex_set()

This commit allows adding a mutex to a pool to make low level
allocations thread-safe.

FreeSWITCH users running large production systems have been using this
technique for over five years without incident.

Since the fork, we've added in tree debugging code to check for
contentious use of a pool.  Here we're able to use those hooks to
reduce the size of the present commit.

TODO: Why not guard the destroy operation as well?

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Return the tag from apr_pool_tag()

This allows the function to be used as an accessor when passed a NULL
tag.  This is useful for e.g. debugging printf's.

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Add thread priority support for *nix and MS Windows

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Return success if socket is already closed

Prior to this commit, socket_cleanup would return an error if the
socket had already been closed.  With this commit we return success
instead.

This is useful, for example, if a socket is closed manually and we
then try to close it again as part of the cleanup of a pool.

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Add apr_queue_pop_timeout()

This function will pop or get an object from the queue, blocking if
the queue is already empty for up to N microseconds.

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>
Include apr_time.h in apr_queue.h

TODO: Explain why this is needed or a good idea.
Per Anthony: "sq queue"

Signed-off-by: Anthony Minessale <anthm@freeswitch.org>
Signed-off-by: Travis Cross <tc@traviscross.com>