summaryrefslogtreecommitdiff
path: root/ACE/tests/TSS_Leak_Test.cpp
blob: e405fa2a216f61976b7007a47e1f8997c9608fd1 (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
#include "test_config.h"

#include "ace/TSS_T.h"
#include "ace/Task.h"
#include "ace/Barrier.h"

struct X : private ACE_Copy_Disabled
{
  static int count_;

  X() { ++count_; }
  ~X() { --count_; }
};

int X::count_;

ACE_Barrier barrier (2);

struct Task : ACE_Task_Base
{
  explicit Task (ACE_TSS<X> *tss) : tss_(tss) {}

  int svc () override
  {
    X *x = *tss_;
    ACE_UNUSED_ARG (x);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d X objects created\n"), X::count_));
    barrier.wait ();
    // tss deleted here
    barrier.wait ();
    return 0;
  }

  ACE_TSS<X> *const tss_;
};

int run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("TSS_Leak_Test"));

  ACE_TSS<X> *const tss = new ACE_TSS<X>;
  X *x = *tss;
  ACE_UNUSED_ARG (x);
  Task task (tss);
  task.activate ();
  barrier.wait ();
  delete tss;
  barrier.wait ();
  task.wait ();

  if (X::count_)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: %d X objects (should be 0)\n"),
                  X::count_));
    }

  ACE_END_TEST;
  return X::count_;
}