summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/glib-2.0/glib-2.0/0012-tests-Fix-non-atomic-access-to-some-shared-variables.patch
blob: be7fcba8c86695d896694274832370461eee5329 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
From 1a7f0002a052725fb646e136fadd5dad66222d7f Mon Sep 17 00:00:00 2001
From: Philip Withnall <pwithnall@endlessos.org>
Date: Wed, 11 Nov 2020 18:31:01 +0000
Subject: [PATCH 12/29] tests: Fix non-atomic access to some shared variables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

And drop the `volatile` qualifier from the variables, as that doesn’t
help with thread safety.

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

Helps: #600
Upstream-Status: Backport [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719]
---
 tests/refcount/objects.c     | 8 ++++----
 tests/refcount/properties3.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/refcount/objects.c b/tests/refcount/objects.c
index 963766d00..0c471a42b 100644
--- a/tests/refcount/objects.c
+++ b/tests/refcount/objects.c
@@ -26,7 +26,7 @@ struct _GTestClass
 };
 
 static GType my_test_get_type (void);
-static volatile gboolean stopping;
+static gint stopping;  /* (atomic) */
 
 static void my_test_class_init (GTestClass * klass);
 static void my_test_init (GTest * test);
@@ -101,7 +101,7 @@ run_thread (GTest * test)
 {
   gint i = 1;
 
-  while (!stopping) {
+  while (!g_atomic_int_get (&stopping)) {
     my_test_do_refcount (test);
     if ((i++ % 10000) == 0) {
       g_print (".");
@@ -128,7 +128,7 @@ main (int argc, char **argv)
 
   test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
 
-  stopping = FALSE;
+  g_atomic_int_set (&stopping, 0);
 
   for (i = 0; i < n_threads; i++) {
     GThread *thread;
@@ -141,7 +141,7 @@ main (int argc, char **argv)
   }
   g_usleep (5000000);
 
-  stopping = TRUE;
+  g_atomic_int_set (&stopping, 1);
 
   g_print ("\nstopping\n");
 
diff --git a/tests/refcount/properties3.c b/tests/refcount/properties3.c
index bc8820661..31f26a46e 100644
--- a/tests/refcount/properties3.c
+++ b/tests/refcount/properties3.c
@@ -34,7 +34,7 @@ struct _GTestClass
 static GType my_test_get_type (void);
 G_DEFINE_TYPE (GTest, my_test, G_TYPE_OBJECT)
 
-static volatile gboolean stopping;
+static gint stopping;  /* (atomic) */
 
 static void my_test_get_property (GObject    *object,
 				  guint       prop_id,
@@ -140,7 +140,7 @@ run_thread (GTest * test)
 {
   gint i = 1;
 
-  while (!stopping) {
+  while (!g_atomic_int_get (&stopping)) {
     my_test_do_property (test);
     if ((i++ % 10000) == 0)
       {
@@ -170,7 +170,7 @@ main (int argc, char **argv)
 
   test_threads = g_array_new (FALSE, FALSE, sizeof (GThread *));
 
-  stopping = FALSE;
+  g_atomic_int_set (&stopping, 0);
 
   for (i = 0; i < n_threads; i++) {
     GThread *thread;
@@ -180,7 +180,7 @@ main (int argc, char **argv)
   }
   g_usleep (30000000);
 
-  stopping = TRUE;
+  g_atomic_int_set (&stopping, 1);
   g_print ("\nstopping\n");
 
   /* join all threads */
-- 
2.30.1