aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/tm/pr45940-4.C
blob: d1cb8d55ae6772385d1189a3e0d02f89b8369974 (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
// { dg-do compile }
// { dg-options "-fgnu-tm -O1" }

__attribute__((transaction_safe))
void* operator new (__SIZE_TYPE__);

__attribute__((transaction_pure))
inline int atomic_exchange_and_add( int * pw, int dv )
{
    int r;
    __asm__ ("" : "=r"(r));
    return r;
}

class sp_counted_base
{
protected:
    int use_count_;        // #shared
public:
    __attribute__((transaction_safe))
    virtual void dispose() = 0; // nothrow

    __attribute__((transaction_safe))
    void release() // nothrow
    {
	if( atomic_exchange_and_add( &use_count_, -1 ) == 1 )
	{
	    dispose();
	}
    }
};

class sp_counted_base_x86 : public sp_counted_base
{
public:
  void dispose()
  {
    release();
  }
};

class shared_count
{
private:
    sp_counted_base * pi_;
public:
    int j;
    __attribute__((transaction_safe))
    shared_count(): pi_(new sp_counted_base_x86()), j(0)
    {
    }
    __attribute__((transaction_safe))
    ~shared_count() // nothrow
    {
	if( pi_ != 0 ) pi_->release();
    }
};

volatile int i = 1;
shared_count * c;
int main()
{
  if ( i == 0) {
    __transaction_atomic {
     shared_count sc;
    }
  }
  return 0;
}