[glib] g_atomic_int_get, g_atomic_pointer_get: accept const arguments



commit cf68300d27784ab5baaf6ef4761cead0ec404b1f
Author: Simon McVittie <simon mcvittie collabora co uk>
Date:   Sat Jan 26 17:37:33 2013 +0000

    g_atomic_int_get, g_atomic_pointer_get: accept const arguments
    
    Signed-off-by: Simon McVittie <simon mcvittie collabora co uk>
    Reviewed-by: Matthias Clasen <mclasen redhat com>
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=692583

 glib/gatomic.c      |   12 ++++++------
 glib/gatomic.h      |    4 ++--
 glib/tests/atomic.c |   11 +++++++++++
 3 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/glib/gatomic.c b/glib/gatomic.c
index 2df2bcc..2fc4f4a 100644
--- a/glib/gatomic.c
+++ b/glib/gatomic.c
@@ -111,7 +111,7 @@
  * Since: 2.4
  **/
 gint
-(g_atomic_int_get) (volatile gint *atomic)
+(g_atomic_int_get) (const volatile gint *atomic)
 {
   return g_atomic_int_get (atomic);
 }
@@ -316,9 +316,9 @@ guint
  * Since: 2.4
  **/
 gpointer
-(g_atomic_pointer_get) (volatile void *atomic)
+(g_atomic_pointer_get) (const volatile void *atomic)
 {
-  return g_atomic_pointer_get ((volatile gpointer *) atomic);
+  return g_atomic_pointer_get ((const volatile gpointer *) atomic);
 }
 
 /**
@@ -477,7 +477,7 @@ gsize
  * http://msdn.microsoft.com/en-us/library/ms684122(v=vs.85).aspx
  */
 gint
-(g_atomic_int_get) (volatile gint *atomic)
+(g_atomic_int_get) (const volatile gint *atomic)
 {
   MemoryBarrier ();
   return *atomic;
@@ -541,9 +541,9 @@ guint
 
 
 gpointer
-(g_atomic_pointer_get) (volatile void *atomic)
+(g_atomic_pointer_get) (const volatile void *atomic)
 {
-  volatile gpointer *ptr = atomic;
+  const volatile gpointer *ptr = atomic;
 
   MemoryBarrier ();
   return *ptr;
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 65b8f3a..e7fd1f2 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -31,7 +31,7 @@
 G_BEGIN_DECLS
 
 GLIB_AVAILABLE_IN_ALL
-gint                    g_atomic_int_get                      (volatile gint  *atomic);
+gint                    g_atomic_int_get                      (const volatile gint *atomic);
 GLIB_AVAILABLE_IN_ALL
 void                    g_atomic_int_set                      (volatile gint  *atomic,
                                                                gint            newval);
@@ -57,7 +57,7 @@ guint                   g_atomic_int_xor                      (volatile guint *a
                                                                guint           val);
 
 GLIB_AVAILABLE_IN_ALL
-gpointer                g_atomic_pointer_get                  (volatile void  *atomic);
+gpointer                g_atomic_pointer_get                  (const volatile void *atomic);
 GLIB_AVAILABLE_IN_ALL
 void                    g_atomic_pointer_set                  (volatile void  *atomic,
                                                                gpointer        newval);
diff --git a/glib/tests/atomic.c b/glib/tests/atomic.c
index 85483ed..1c252c6 100644
--- a/glib/tests/atomic.c
+++ b/glib/tests/atomic.c
@@ -14,6 +14,8 @@
 static void
 test_types (void)
 {
+  const gint *csp;
+  const gint * const *cspp;
   guint u, u2;
   gint s, s2;
   gpointer vp, vp2;
@@ -21,6 +23,9 @@ test_types (void)
   gsize gs, gs2;
   gboolean res;
 
+  csp = &s;
+  cspp = &csp;
+
   g_atomic_int_set (&u, 5);
   u2 = g_atomic_int_get (&u);
   g_assert_cmpint (u2, ==, 5);
@@ -100,6 +105,9 @@ test_types (void)
   g_assert (gs2 == 12);
   g_assert (gs == 8);
 
+  g_assert (g_atomic_int_get (csp) == s);
+  g_assert (g_atomic_pointer_get (cspp) == csp);
+
   /* repeat, without the macros */
 #undef g_atomic_int_set
 #undef g_atomic_int_get
@@ -200,6 +208,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   gs2 = g_atomic_pointer_xor (&gs, 4);
   g_assert (gs2 == 12);
   g_assert (gs == 8);
+
+  g_assert (g_atomic_int_get (csp) == s);
+  g_assert (g_atomic_pointer_get (cspp) == csp);
 }
 
 #define THREADS 10



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]