DCL 3.7.4
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#include <dcl/Object.h>
9
10__DCL_BEGIN_NAMESPACE
11
13{
14public:
15 // _name을위해 내부에서 메모리를 할당하지 않는다.
16 // InternalMutext를 사용하는 곳에서 문자열을 유지해야 한다.
17 InternalMutex(const char* _name);
19 void lock();
20 void unlock();
21private:
22#if __DCL_PTHREAD
23 pthread_mutex_t __mutex;
24#elif defined(__WINNT__)
25 CRITICAL_SECTION __cs;
26#endif
27 const char* __name;
28};
29
30#if __DCL_HAVE_ALLOC_DEBUG
31class AllocList
32{
33public:
34 struct NodeBase
35 {
36 struct NodeBase* prev;
37 struct NodeBase* next;
38 };
39
40#define __DCL_DEBUG_PATH_MAX 76
41 struct Node : public NodeBase
42 {
43 thread_t thread; // 4 8
44 char pad; // 5 9
45 bool check; // 6 10
46 DCLAllocFunc func; // 8 12
47 char_t filename[__DCL_DEBUG_PATH_MAX + 3 + 1]; // "..." + '\0'
48 // 168 172 332
49 unsigned int line; // 172 176 336
50 size_t size; // 176 184 344
51 void* data; // 180 192 352
52
53 static size_t SIZE();
54 void setFilename(const char_t* _filename);
55 void* DATA() const;
56 };
57
58protected:
59 NodeBase __masterNode;
60 size_t __nodeCount;
61
62 // _size 만큼을 할당하고 초기화된 노드 리턴
63 // 메모리 할당할 수 없으면 NULL
64 Node* allocNode(
65 size_t _size,
66 bool _check,
67 DCLAllocFunc _func,
68 const char_t* _filename,
69 unsigned int _line
70 );
71
72 // 노드를 tail에 추가
73 void* addTail(Node* _newNode);
74
75public:
76 // realloc 하고 초기화된 노드 리턴
77 // 메모리 할당할 수 없으면 NULL
78 Node* reallocNode(
79 Node* _node,
80 size_t _size,
81 const char_t* _filename,
82 unsigned int _line
83 );
84
85 AllocList();
86 ~AllocList();
87
88 // 리스트가 비어있으면 NULL
89 Node* begin() const;
90
91 // 리스트가 비어있으면 NULL
92 Node* end() const;
93
94 // 마지막 노드를 지나면 NULL, _node 리턴
95 Node* next(Node*& _node) const;
96
97 // 처음 노드를 지나면 NULL, _node 리턴
98 Node* prev(Node*& _node) const;
99
100 size_t count() const { return __nodeCount; }
101
102 // 찾고자 하는 노드가 없으면 NULL
103 // reverse 찾고자 하는 노드가 없으면 NULL
104 Node* find(const void* _ptr) const;
105 Node* rfind(const void* _ptr) const;
106
107 // _size malloc하고 노드를 tail에 추가
108 // 메모리 할당할수 없으면 NULL
109 void* allocAddTail(
110 size_t _size,
111 bool _check,
112 DCLAllocFunc _func,
113 const char_t* _filename,
114 unsigned int _line
115 );
116
117 // realloc 하고 노드 update
118 // 메모리 할당할 수 없으면 NULL
119 void* reallocUpdate(
120 void* _ptr,
121 size_t _size,
122 bool _check,
123 DCLAllocFunc _func,
124 const char_t* _filename,
125 unsigned int _line
126 );
127
128 // pNode를 삭제하고 메모리 해제
129 void erase(Node* _node);
130
131 // 전체 노드 삭제
132 void clear();
133};
134#endif // __DCL_HAVE_ALLOC_DEBUG
135
137{
138public:
139 struct NodeBase
140 {
141 struct NodeBase* prev;
142 struct NodeBase* next;
143 };
144
145 struct Node : public NodeBase
146 {
147 const void* key;
148 const void* value;
149 };
150
151protected:
152 size_t bucketIndex(const void* _key) const;
153
154public:
155 PtrHashMap(size_t _buckerCount);
156 ~PtrHashMap();
157
158 const void*& operator [] (const void* _key);
159
160 // 찾지 못하면 NULL
161 Node* find(const void* _key) const;
162
163 // find의 리턴값
164 void erase(Node* _node);
165
166 size_t count() const;
167
168protected:
172};
173
174inline size_t PtrHashMap::bucketIndex(const void* _key) const
175{
176 return (size_t)_key % __bucketCount;
177}
178
179inline size_t PtrHashMap::count() const
180{
181 return __nodeCount;
182}
183
185{
186 InternalMutex lockSQLDriverPool; // for SQLDriver in SQLDriver.cpp
188#ifdef __DCL_DEBUG
189 InternalMutex lockGlobalOutput;
190#define MAP_THREAD_OUTPUT_BUCKET_COUNT 50
191 PtrHashMap mapThreadOutput;
192 InternalMutex lockThreadOutput;
193#if __DCL_HAVE_ALLOC_DEBUG
194 AllocList listAlloc;
195 InternalMutex lockAlloc;
196#endif // __DCL_HAVE_ALLOC_DEBUG
197
198#endif
199
200 LibState();
201 ~LibState();
202};
203
204__DCL_END_NAMESPACE
205
206#endif // __DCL_LIB_STATE_H__
wchar_t char_t
Definition Config.h:247
pthread_t thread_t
Definition Object.h:27
void(* DCLCleanupCallback)()
Definition Object.h:290
InternalMutex(const char *_name)
Definition LibState.cpp:36
void unlock()
Definition LibState.cpp:64
void erase(Node *_node)
Definition LibState.cpp:386
size_t bucketIndex(const void *_key) const
Definition LibState.h:174
NodeBase * __buckets
Definition LibState.h:169
size_t __nodeCount
Definition LibState.h:171
size_t count() const
Definition LibState.h:179
const void *& operator[](const void *_key)
Definition LibState.cpp:352
size_t __bucketCount
Definition LibState.h:170
Node * find(const void *_key) const
Definition LibState.cpp:372
PtrHashMap(size_t _buckerCount)
Definition LibState.cpp:326
DCLCleanupCallback pfnSQLCleanup
Definition LibState.h:187
InternalMutex lockSQLDriverPool
Definition LibState.h:186
struct NodeBase * prev
Definition LibState.h:141
struct NodeBase * next
Definition LibState.h:142
const void * key
Definition LibState.h:147
const void * value
Definition LibState.h:148