aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.4.3/gcc/testsuite/g++.dg/thread-ann/thread_annot_lock-66.C
blob: c341973e747d2fce960b133f01c3e36eb3b28138 (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
// Test annotations on out-of-line definitions of member functions where the
// annotations refer to locks that are also data members in the class.
// 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"

Mutex mu;

class Foo {
 public:
  int method1(int i);
  int data GUARDED_BY(mu1);
  Mutex *mu1;
  Mutex *mu2;
};

int Foo::method1(int i) SHARED_LOCKS_REQUIRED(mu1, mu, mu2)
{
  return data + i;
}

main()
{
  Foo a;

  MutexLock l(a.mu2);
  a.mu1->Lock();
  mu.Lock();
  a.method1(1);
  mu.Unlock();
  a.mu1->Unlock();
}