This commit is contained in:
Anthony Minessale 2011-03-22 12:17:00 -05:00
parent fd6089014e
commit 3b56c119a7
2 changed files with 112 additions and 1 deletions

View File

@ -24,6 +24,7 @@
* Contributor(s):
*
* Anthony Minessale II <anthm@freeswitch.org>
* Eliot Gable <egable@gmail.com>
*
* switch_apr.h -- APR includes header
*
@ -410,6 +411,65 @@ SWITCH_DECLARE(switch_status_t) switch_mutex_trylock(switch_mutex_t *lock);
/** @} */
/**
* @defgroup switch_atomic Multi-Threaded Adtomic Operations Routines
* @ingroup switch_apr
* @{
*/
/** Opaque type used for the atomic operations */
#ifdef apr_atomic_t
typedef apr_atomic_t switch_atomic_t;
#else
typedef uint32_t switch_atomic_t;
#endif
/**
* Some architectures require atomic operations internal structures to be
* initialized before use.
* @param pool The memory pool to use when initializing the structures.
*/
SWITCH_DECLARE(switch_status_t) switch_atomic_init(switch_memory_pool_t *pool);
/**
* Uses an atomic operation to read the uint32 value at the location specified
* by mem.
* @param mem The location of memory which stores the value to read.
*/
SWITCH_DECLARE(uint32_t) switch_atomic_read(volatile switch_atomic_t *mem);
/**
* Uses an atomic operation to set a uint32 value at a specified location of
* memory.
* @param mem The location of memory to set.
* @param val The uint32 value to set at the memory location.
*/
SWITCH_DECLARE(void) switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val);
/**
* Uses an atomic operation to add the uint32 value to the value at the
* specified location of memory.
* @param mem The location of the value to add to.
* @param val The uint32 value to add to the value at the memory location.
*/
SWITCH_DECLARE(void) switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val);
/**
* Uses an atomic operation to increment the value at the specified memroy
* location.
* @param mem The location of the value to increment.
*/
SWITCH_DECLARE(void) switch_atomic_inc(volatile switch_atomic_t *mem);
/**
* Uses an atomic operation to decrement the value at the specified memroy
* location.
* @param mem The location of the value to decrement.
*/
SWITCH_DECLARE(int) switch_atomic_dec(volatile switch_atomic_t *mem);
/** @} */
/**
* @defgroup switch_thread_rwlock Thread Read/Write lock Routines
* @ingroup switch_apr

View File

@ -24,7 +24,7 @@
* Contributor(s):
*
* Michael Jerris <mike@jerris.com>
*
* Eliot Gable <egable@gmail.com>
*
* switch_apr.c -- apr wrappers and extensions
*
@ -38,6 +38,7 @@
/* apr headers*/
#include <apr.h>
#include <apr_atomic.h>
#include <apr_pools.h>
#include <apr_hash.h>
#include <apr_network_io.h>
@ -1141,6 +1142,56 @@ SWITCH_DECLARE(switch_status_t) switch_thread_join(switch_status_t *retval, swit
}
SWITCH_DECLARE(switch_status_t) switch_atomic_init(switch_memory_pool_t *pool)
{
return apr_atomic_init((apr_pool_t *) pool);
}
SWITCH_DECLARE(uint32_t) switch_atomic_read(volatile switch_atomic_t *mem)
{
#ifdef apr_atomic_t
return apr_atomic_read((apr_atomic_t *)mem);
#else
return apr_atomic_read32((apr_uint32_t *)mem);
#endif
}
SWITCH_DECLARE(void) switch_atomic_set(volatile switch_atomic_t *mem, uint32_t val)
{
#ifdef apr_atomic_t
apr_atomic_set((apr_atomic_t *)mem, val);
#else
apr_atomic_set32((apr_uint32_t *)mem, val);
#endif
}
SWITCH_DECLARE(void) switch_atomic_add(volatile switch_atomic_t *mem, uint32_t val)
{
#ifdef apr_atomic_t
apr_atomic_add((apr_atomic_t *)mem, val);
#else
apr_atomic_add32((apr_uint32_t *)mem, val);
#endif
}
SWITCH_DECLARE(void) switch_atomic_inc(volatile switch_atomic_t *mem)
{
#ifdef apr_atomic_t
apr_atomic_inc((apr_atomic_t *)mem);
#else
apr_atomic_inc32((apr_uint32_t *)mem);
#endif
}
SWITCH_DECLARE(int) switch_atomic_dec(volatile switch_atomic_t *mem)
{
#ifdef apr_atomic_t
return apr_atomic_dec((apr_atomic_t *)mem);
#else
return apr_atomic_dec32((apr_uint32_t *)mem);
#endif
}
/* For Emacs:
* Local Variables: