blob: 5c4510d29222d34881e945d25c11fd723ec1abf8 (
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
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
99
100
101
102
103
|
/* -*- C++ -*- */
// $Id$
// ============================================================================
//
// = LIBRARY
// ace
//
// = FILENAME
// Singleton.h
//
// = DESCRIPTION
//
// = AUTHOR
// Tim Harrison (harrison@cs.wustl.edu), Douglas C. Schmidt, Chris Lahey, and Rich Christy
//
// ============================================================================
#if !defined (ACE_SINGLETON_H)
#define ACE_SINGLETON_H
#include "ace/Synch.h"
template <class TYPE, class LOCK>
class ACE_Singleton
// = TITLE
// A Singleton Adapter.
//
// = DESCRIPTION
// Uses the Adapter pattern to turn ordinary classes into
// Singletons optimized with the Double-Check pattern.
{
public:
static TYPE *instance (void);
// Global access point to the Singleton.
static TYPE *instance (TYPE*);
// Set the Singleton instance.
static void cleanup (void *object, void *);
// Cleanup method, used by ACE_Object_Manager to destroy the singleton.
static void dump (void);
// Dump the state of the object.
protected:
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
static TYPE *instance_;
// Pointer to the Singleton instance.
static LOCK ace_singleton_lock_;
// Lock the creation of the singleton.
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
static TYPE *&instance_i (void);
// Get pointer to the Singleton instance
static LOCK &singleton_lock_i (void);
// Get reference to Singleton lock;
};
template <class TYPE, class LOCK>
class ACE_TSS_Singleton
// = TITLE
// A Thread Specific Storage Singleton Adapter.
//
// = DESCRIPTION
// Uses the Adapter pattern to turn ordinary classes into
// Singletons optimized with the Double-Check pattern.
{
public:
static TYPE *instance (void);
// Global access point to the Singleton.
static void cleanup (void *object, void *);
// Cleanup method, used by ACE_Object_Manager to destroy the singleton.
static void dump (void);
// Dump the state of the object.
protected:
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
static ACE_TSS<TYPE> *instance_;
// Pointer to the Singleton instance.
static LOCK ace_singleton_lock_;
// Lock the creation of the singleton.
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
};
#if defined (__ACE_INLINE__)
#include "ace/Singleton.i"
#endif /* __ACE_INLINE__ */
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Singleton.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Singleton.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#endif /* ACE_SINGLETON_H */
|