aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C')
-rw-r--r--gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C58
1 files changed, 58 insertions, 0 deletions
diff --git a/gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C b/gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C
new file mode 100644
index 000000000..4b1618818
--- /dev/null
+++ b/gcc-4.4.0/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-44.C
@@ -0,0 +1,58 @@
+// Test the support for releasable scoped lock (e.g std::unique_lock).
+// This is a good test case. (i.e. There should be no warning emitted by the
+// compiler.)
+// { dg-do compile }
+// { dg-options "-Wthread-safety -O" }
+
+#include "thread_annot_common.h"
+
+extern void bar();
+
+Mutex mu1, mu2;
+int a GUARDED_BY(mu1);
+
+void foo(int x) {
+ if (x > 2) {
+ ReleasableMutexLock l(&mu1);
+ if (a < 3) {
+ a = x + 1;
+ l.Release();
+ bar();
+ }
+ else {
+ a = x + 2;
+ }
+ }
+}
+
+void func(int x) {
+ ReleasableMutexLock l(&mu1);
+ ReleasableMutexLock m(&mu2);
+ switch (x) {
+ case 1:
+ {
+ a = x + 1;
+ l.Release();
+ bar();
+ break;
+ }
+ case 3:
+ {
+ a = x + 3;
+ m.Release();
+ break;
+ }
+ case 2:
+ {
+ a = x + 2;
+ l.Release();
+ bar();
+ break;
+ }
+ default:
+ {
+ a = x + 3;
+ break;
+ }
+ }
+}