blob: 7350803c6fad55f04770273d1b91d05fe3a763a3 [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001From 2d03f99ae4de394cac0690717d96c2d884ccdae2 Mon Sep 17 00:00:00 2001
2From: Philip Withnall <pwithnall@endlessos.org>
3Date: Mon, 16 Nov 2020 14:47:47 +0000
4Subject: [PATCH 24/29] tests: Add comment to volatile atomic tests
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9`volatile` should not be used to indicate atomic variables, and we
10shouldnt encourage its use. Keep the tests, since they check that we
11dont emit warnings when built against incorrect old code which uses
12`volatile`. But add a comment to stop copy/paste use of `volatile`
13in the future.
14
15Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
16
17Helps: #600
18Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719]
19---
20 glib/tests/atomic.c | 6 ++++++
21 1 file changed, 6 insertions(+)
22
23diff --git a/glib/tests/atomic.c b/glib/tests/atomic.c
24index 7d2459f3a..14e6e454e 100644
25--- a/glib/tests/atomic.c
26+++ b/glib/tests/atomic.c
27@@ -94,6 +94,9 @@ test_types (void)
28 res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, str);
29 g_assert_true (res);
30
31+ /* Note that atomic variables should almost certainly not be marked as
32+ * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists
33+ * to make sure that we don’t warn when built against older third party code. */
34 g_atomic_pointer_set (&vp_str_vol, NULL);
35 res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, str);
36 g_assert_true (res);
37@@ -210,6 +213,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
38 res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, (char *) str);
39 g_assert_true (res);
40
41+ /* Note that atomic variables should almost certainly not be marked as
42+ * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists
43+ * to make sure that we don’t warn when built against older third party code. */
44 g_atomic_pointer_set (&vp_str_vol, NULL);
45 res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, (char *) str);
46 g_assert_true (res);
47--
482.30.1
49