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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// $Id$
// ============================================================================
//
// = LIBRARY
// tests
//
// = DESCRIPTION
// This program tests both the ACE_Framework_Compondent and ACE_Repository.
//
// = AUTHOR
// Don Hinton <dhinton@ieee.org>
//
// ============================================================================
#include "ace/Framework_Component.h"
#include "ace/OS.h"
#include "ace/Get_Opt.h"
#include "ace/ARGV.h"
#include "ace/Object_Manager.h"
#include "ace/SString.h"
#include "tests/test_config.h"
#include "tests/Framework_Component_Test.h"
ACE_RCSID(tests, Framework_Component_Test, "$Id$")
My_Singleton *My_Singleton::instance_ = 0;
void
My_Singleton::close_singleton (void)
{
ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("My_Singleton::close_singleton\n")));
delete My_Singleton::instance_;
My_Singleton::instance_ = 0;
}
My_Singleton *
My_Singleton::instance (void)
{
ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("My_Singleton::instance\n")));
if (My_Singleton::instance_ == 0)
{
// Perform Double-Checked Locking Optimization.
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (), 0));
if (My_Singleton::instance_ == 0)
{
ACE_NEW_RETURN (My_Singleton::instance_,
My_Singleton (),
0);
ACE_REGISTER_FRAMEWORK_COMPONENT(My_Singleton, My_Singleton::instance_);
}
}
return My_Singleton::instance_;
}
int
ACE_TMAIN (int, ACE_TCHAR *argv[])
{
ACE_START_TEST (ACE_LIB_TEXT("Framework_Component_Test"));
ACE_UNUSED_ARG (argv);
// Create an instance of My_Singleton that will be managed
// by the ACE_Framework_Repository and keep a pointer to
// instance.
My_Singleton *first = My_Singleton::instance ();
// Now, close down the repository.
ACE_Framework_Repository::close_singleton ();
ACE_Framework_Repository::instance ();
// Now get another pointer to My_Singleton and make sure
// that it's different. We could also test other pointers
// like ACE_Reactor, ACE_Proactor, or the repository itself
// if we wanted.
My_Singleton *second = My_Singleton::instance ();
if (first == second)
ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("Pointer are equal, but shouldn't be.\n")));
// Close down the repository again since we are writing debug messages.
// And want all of them to go to the log.
ACE_Framework_Repository::close_singleton ();
ACE_END_TEST;
return 0;
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Framework_Component_T<My_Singleton>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Framework_Component_T<My_Singleton>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|