summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/glib-2.0/glib-2.0/0024-tests-Add-comment-to-volatile-atomic-tests.patch
blob: 7350803c6fad55f04770273d1b91d05fe3a763a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From 2d03f99ae4de394cac0690717d96c2d884ccdae2 Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Mon, 16 Nov 2020 14:47:47 +0000
Subject: [PATCH 24/29] tests: Add comment to volatile atomic tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

`volatile` should not be used to indicate atomic variables, and we
shouldn’t encourage its use. Keep the tests, since they check that we
don’t emit warnings when built against incorrect old code which uses
`volatile`. But add a comment to stop copy/paste use of `volatile`
in the future.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #600
Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719]
---
 glib/tests/atomic.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/glib/tests/atomic.c b/glib/tests/atomic.c
index 7d2459f3a..14e6e454e 100644
--- a/glib/tests/atomic.c
+++ b/glib/tests/atomic.c
@@ -94,6 +94,9 @@ test_types (void)
   res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, str);
   g_assert_true (res);
 
+  /* Note that atomic variables should almost certainly not be marked as
+   * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists
+   * to make sure that we don’t warn when built against older third party code. */
   g_atomic_pointer_set (&vp_str_vol, NULL);
   res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, str);
   g_assert_true (res);
@@ -210,6 +213,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   res = g_atomic_pointer_compare_and_exchange (&vp_str, NULL, (char *) str);
   g_assert_true (res);
 
+  /* Note that atomic variables should almost certainly not be marked as
+   * `volatile` — see http://isvolatileusefulwiththreads.in/c/. This test exists
+   * to make sure that we don’t warn when built against older third party code. */
   g_atomic_pointer_set (&vp_str_vol, NULL);
   res = g_atomic_pointer_compare_and_exchange (&vp_str_vol, NULL, (char *) str);
   g_assert_true (res);
-- 
2.30.1