Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / TSS_Leak_Test.cpp
blobe405fa2a216f61976b7007a47e1f8997c9608fd1
1 #include "test_config.h"
3 #include "ace/TSS_T.h"
4 #include "ace/Task.h"
5 #include "ace/Barrier.h"
7 struct X : private ACE_Copy_Disabled
9 static int count_;
11 X() { ++count_; }
12 ~X() { --count_; }
15 int X::count_;
17 ACE_Barrier barrier (2);
19 struct Task : ACE_Task_Base
21 explicit Task (ACE_TSS<X> *tss) : tss_(tss) {}
23 int svc () override
25 X *x = *tss_;
26 ACE_UNUSED_ARG (x);
27 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d X objects created\n"), X::count_));
28 barrier.wait ();
29 // tss deleted here
30 barrier.wait ();
31 return 0;
34 ACE_TSS<X> *const tss_;
37 int run_main (int, ACE_TCHAR *[])
39 ACE_START_TEST (ACE_TEXT ("TSS_Leak_Test"));
41 ACE_TSS<X> *const tss = new ACE_TSS<X>;
42 X *x = *tss;
43 ACE_UNUSED_ARG (x);
44 Task task (tss);
45 task.activate ();
46 barrier.wait ();
47 delete tss;
48 barrier.wait ();
49 task.wait ();
51 if (X::count_)
53 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: %d X objects (should be 0)\n"),
54 X::count_));
57 ACE_END_TEST;
58 return X::count_;