DCL 4.0
Loading...
Searching...
No Matches
LibState.h
Go to the documentation of this file.
1#ifndef __DCL_LIB_STATE_H__
2#define __DCL_LIB_STATE_H__ 20061115
3
4#ifndef __DCL_CONFIG_H__
5#include <dcl/_Config.h>
6#endif
7
8#if __DCL_PTHREAD
9#include <pthread.h>
10#endif
11
12#include <dcl/Object.h>
13
14__DCL_BEGIN_NAMESPACE
15
17{
18public:
19 // pszName을위해 내부에서 메모리를 할당하지 않는다.
20 // InternalMutext를 사용하는 곳에서 문자열을 유지해야 한다.
21 InternalMutex(const char* pszName);
23 void lock();
24 void unlock();
25private:
26#if __DCL_PTHREAD
27 pthread_mutex_t m_mutex;
28#elif __DCL_WINDOWS
29 CRITICAL_SECTION m_cs;
30#endif
31 const char* m_pszName;
32};
33
34#if __DCL_HAVE_ALLOC_DEBUG
35
36#define __DCL_DEBUG_PATH_MAX 76
37
38class AllocList
39{
40public:
41 struct NodeBase
42 {
43 struct NodeBase* pPrev;
44 struct NodeBase* pNext;
45 };
46
47 struct Node : public NodeBase
48 {
49 unsigned long uThreadId; // 4
50 bool bCheck; // 8
51 DCLAllocFunction allocFunction; // 12
52 char_t szFileName[__DCL_DEBUG_PATH_MAX + 3 + 1]; // "..." + '\0' 148, 172, 332
53 unsigned int nLine; // 152
54 size_t nSize; // 158
55
56 static size_t size();
57 void assignFileName(const char_t* _filename);
58 void* data() const;
59 };
60
61protected:
62 NodeBase m_masterNode;
63 size_t m_nCount;
64
65 // nSize 만큼을 할당하고 초기화된 노드 리턴
66 // 메모리 할당할 수 없으면 NULL
67 Node* allocNode(size_t nSize,
68 bool bCheck,
69 DCLAllocFunction allocFunction,
70 const char_t* _filename,
71 unsigned int _line);
72
73 // 노드를 tail에 추가
74 void* addTail(Node* pNewNode);
75
76public:
77 // realloc 하고 초기화된 노드 리턴
78 // 메모리 할당할 수 없으면 NULL
79 Node* reallocNode(Node* pNode,
80 size_t nSize,
81 const char_t* _filename,
82 unsigned int _line);
83
84 AllocList();
85 ~AllocList();
86
87 // 리스트가 비어있으면 NULL
88 Node* begin() const;
89
90 // 리스트가 비어있으면 NULL
91 Node* end() const;
92
93 // 마지막 노드를 지나면 NULL, pNode 리턴
94 Node* next(Node*& pNode) const;
95
96 // 처음 노드를 지나면 NULL, pNode 리턴
97 Node* prev(Node*& pNode) const;
98
99 size_t count() const { return m_nCount; }
100
101 // 찾고자 하는 노드가 없으면 NULL
102 // reverse 찾고자 하는 노드가 없으면 NULL
103 Node* find(const void* p) const;
104 Node* rfind(const void* p) const;
105
106 // nSize malloc하고 노드를 tail에 추가
107 // 메모리 할당할수 없으면 NULL
108
109 void* allocAddTail(
110 size_t nSize,
111 bool bCheck,
112 DCLAllocFunction allocFunction,
113 const char_t* _filename,
114 unsigned int _line
115 );
116
117 // realloc 하고 노드 update
118 // 메모리 할당할 수 없으면 NULL
119 void* reallocUpdate(
120 void* p,
121 size_t nSize,
122 bool bCheck,
123 DCLAllocFunction allocFunction,
124 const char_t* _filename,
125 unsigned int _line
126 );
127
128 // pNode를 삭제하고 메모리 해제
129 void erase(Node* pNode);
130
131 // 전체 노드 삭제
132 void clear();
133};
134
135#endif // __DCL_HAVE_ALLOC_DEBUG
136
138{
139public:
140 struct NodeBase
141 {
144 };
145
146 struct Node : public NodeBase
147 {
148 const void* key;
149 const void* value;
150 };
151
152protected:
153 size_t bucketNumber(const void* key) const;
154
155public:
156 PtrHashMap(size_t nBuckets);
157 ~PtrHashMap();
158
159 const void*& operator [] (const void* key);
160
161 // 찾지 못하면 NULL
162 Node* find(const void* key) const;
163
164 // find의 리턴값
165 void erase(Node* pNode);
166
167 size_t count() const;
168
169protected:
173};
174
175inline size_t PtrHashMap::bucketNumber(const void* key) const
176{
177 return (size_t)key % m_nBuckets;
178}
179
180inline size_t PtrHashMap::count() const
181{
182 return m_nCount;
183}
184
186{
187 InternalMutex lockSQLDriverPool; // for SQLDriver in SQLDriver.cpp
189#if __DCL_DEBUG
190 InternalMutex lockGlobalOutput;
191#define MAP_THREAD_OUTPUT_BUCKET_COUNT 50
192 PtrHashMap mapThreadOutput;
193 InternalMutex lockThreadOutput;
194#if __DCL_HAVE_ALLOC_DEBUG
195 AllocList listAlloc;
196 InternalMutex lockAlloc;
197#endif // __DCL_HAVE_ALLOC_DEBUG
198
199#endif
200
201 LibState();
202 ~LibState();
203};
204
205__DCL_END_NAMESPACE
206
207#endif // __DCL_LIB_STATE_H__
wchar_t char_t
Definition Config.h:275
void(* DCLCleanupCallback)()
Definition Object.h:273
void CharsetConvertException *__fields clear()
InternalMutex(const char *pszName)
Definition LibState.cpp:34
void unlock()
Definition LibState.cpp:62
int m_nCount
Definition LibState.h:172
void erase(Node *pNode)
Definition LibState.cpp:394
size_t m_nBuckets
Definition LibState.h:171
size_t bucketNumber(const void *key) const
Definition LibState.h:175
PtrHashMap(size_t nBuckets)
Definition LibState.cpp:328
size_t count() const
Definition LibState.h:180
NodeBase * m_buckets
Definition LibState.h:170
Node * find(const void *key) const
Definition LibState.cpp:378
const void *& operator[](const void *key)
Definition LibState.cpp:357
DCLCleanupCallback pfnSQLCleanup
Definition LibState.h:188
InternalMutex lockSQLDriverPool
Definition LibState.h:187
struct NodeBase * pPrev
Definition LibState.h:142
struct NodeBase * pNext
Definition LibState.h:143
const void * key
Definition LibState.h:148
const void * value
Definition LibState.h:149