]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3173
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Mar 2011 17:17:00 +0000 (12:17 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 22 Mar 2011 17:17:00 +0000 (12:17 -0500)
src/include/switch_apr.h
src/switch_apr.c

index a196af76f5d4b5db65ed1b99c7d04c90f0baa483..62559faf6361a0635fb1da92520bb67bba83d931 100644 (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
index 3798d6e2dc3acda3ca964b7d13eff94e3f7c9f86..3ca3c63f77c05993eea600a781d5111bd0fa0ba6 100644 (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: