8a5e135
From 366e6d7e90d3bebc98a1af3cfb04b4cfc8cff6f5 Mon Sep 17 00:00:00 2001
8a5e135
From: Arun Raghavan <arun.raghavan@collabora.co.uk>
8a5e135
Date: Sun, 6 Dec 2009 12:20:53 +0530
4fd38b9
Subject: [PATCH 21/62] Mark shared variables as volatile
8a5e135
8a5e135
'n_waiting' and 'n_waiting_for_accept' may be accessed from mulitple
8a5e135
threads, and thus need to be marked as volatile to suppres certain
8a5e135
compiler optimisations. All uses are protected by a mutex, so we don't
8a5e135
need to worry about cache issues (added documentation for this as well).
8a5e135
8a5e135
This addresses bug #738.
8a5e135
---
8a5e135
 src/pulse/thread-mainloop.c |    5 ++++-
8a5e135
 1 files changed, 4 insertions(+), 1 deletions(-)
8a5e135
8a5e135
diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c
8a5e135
index a2b98ce..14ed926 100644
8a5e135
--- a/src/pulse/thread-mainloop.c
8a5e135
+++ b/src/pulse/thread-mainloop.c
8a5e135
@@ -51,7 +51,7 @@
8a5e135
 
8a5e135
 struct pa_threaded_mainloop {
8a5e135
     pa_mainloop *real_mainloop;
8a5e135
-    int n_waiting, n_waiting_for_accept;
8a5e135
+    volatile int n_waiting, n_waiting_for_accept;
8a5e135
 
8a5e135
     pa_thread* thread;
8a5e135
     pa_mutex* mutex;
8a5e135
@@ -185,6 +185,7 @@ void pa_threaded_mainloop_unlock(pa_threaded_mainloop *m) {
8a5e135
     pa_mutex_unlock(m->mutex);
8a5e135
 }
8a5e135
 
8a5e135
+/* Called with the lock taken */
8a5e135
 void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) {
8a5e135
     pa_assert(m);
8a5e135
 
8a5e135
@@ -198,6 +199,7 @@ void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) {
8a5e135
     }
8a5e135
 }
8a5e135
 
8a5e135
+/* Called with the lock taken */
8a5e135
 void pa_threaded_mainloop_wait(pa_threaded_mainloop *m) {
8a5e135
     pa_assert(m);
8a5e135
 
8a5e135
@@ -212,6 +214,7 @@ void pa_threaded_mainloop_wait(pa_threaded_mainloop *m) {
8a5e135
     m->n_waiting --;
8a5e135
 }
8a5e135
 
8a5e135
+/* Called with the lock taken */
8a5e135
 void pa_threaded_mainloop_accept(pa_threaded_mainloop *m) {
8a5e135
     pa_assert(m);
8a5e135
 
8a5e135
-- 
4fd38b9
1.7.0
8a5e135