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
This commit is contained in:
Simon McVittie 2013-01-26 17:37:33 +00:00
parent f7b31301d5
commit cf68300d27
3 changed files with 19 additions and 8 deletions

View File

@ -111,7 +111,7 @@
* Since: 2.4 * Since: 2.4
**/ **/
gint gint
(g_atomic_int_get) (volatile gint *atomic) (g_atomic_int_get) (const volatile gint *atomic)
{ {
return g_atomic_int_get (atomic); return g_atomic_int_get (atomic);
} }
@ -316,9 +316,9 @@ guint
* Since: 2.4 * Since: 2.4
**/ **/
gpointer 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 * http://msdn.microsoft.com/en-us/library/ms684122(v=vs.85).aspx
*/ */
gint gint
(g_atomic_int_get) (volatile gint *atomic) (g_atomic_int_get) (const volatile gint *atomic)
{ {
MemoryBarrier (); MemoryBarrier ();
return *atomic; return *atomic;
@ -541,9 +541,9 @@ guint
gpointer 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 (); MemoryBarrier ();
return *ptr; return *ptr;

View File

@ -31,7 +31,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
GLIB_AVAILABLE_IN_ALL 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 GLIB_AVAILABLE_IN_ALL
void g_atomic_int_set (volatile gint *atomic, void g_atomic_int_set (volatile gint *atomic,
gint newval); gint newval);
@ -57,7 +57,7 @@ guint g_atomic_int_xor (volatile guint *a
guint val); guint val);
GLIB_AVAILABLE_IN_ALL 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 GLIB_AVAILABLE_IN_ALL
void g_atomic_pointer_set (volatile void *atomic, void g_atomic_pointer_set (volatile void *atomic,
gpointer newval); gpointer newval);

View File

@ -14,6 +14,8 @@
static void static void
test_types (void) test_types (void)
{ {
const gint *csp;
const gint * const *cspp;
guint u, u2; guint u, u2;
gint s, s2; gint s, s2;
gpointer vp, vp2; gpointer vp, vp2;
@ -21,6 +23,9 @@ test_types (void)
gsize gs, gs2; gsize gs, gs2;
gboolean res; gboolean res;
csp = &s;
cspp = &csp;
g_atomic_int_set (&u, 5); g_atomic_int_set (&u, 5);
u2 = g_atomic_int_get (&u); u2 = g_atomic_int_get (&u);
g_assert_cmpint (u2, ==, 5); g_assert_cmpint (u2, ==, 5);
@ -100,6 +105,9 @@ test_types (void)
g_assert (gs2 == 12); g_assert (gs2 == 12);
g_assert (gs == 8); g_assert (gs == 8);
g_assert (g_atomic_int_get (csp) == s);
g_assert (g_atomic_pointer_get (cspp) == csp);
/* repeat, without the macros */ /* repeat, without the macros */
#undef g_atomic_int_set #undef g_atomic_int_set
#undef g_atomic_int_get #undef g_atomic_int_get
@ -200,6 +208,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gs2 = g_atomic_pointer_xor (&gs, 4); gs2 = g_atomic_pointer_xor (&gs, 4);
g_assert (gs2 == 12); g_assert (gs2 == 12);
g_assert (gs == 8); g_assert (gs == 8);
g_assert (g_atomic_int_get (csp) == s);
g_assert (g_atomic_pointer_get (cspp) == csp);
} }
#define THREADS 10 #define THREADS 10