@@ -39,17 +39,25 @@ CMemoryCache_DBData::~CMemoryCache_DBData()
3939 意思:是否成功
4040备注:
4141*********************************************************************/
42- bool CMemoryCache_DBData::MemoryCache_DBData_Init (int nTimeLast, int nTimeStart)
42+ bool CMemoryCache_DBData::MemoryCache_DBData_Init (int nTimeLast /* = 3600 */ , int nTimeStart /* = 0 */ )
4343{
4444 MemoryCache_IsErrorOccur = false ;
4545
4646 bIsRun = true ;
4747
48+
4849 m_nTimeLast = nTimeLast;
4950 m_nTimeStart = nTimeStart;
5051
51- pSTDThread = std::make_unique<std::thread>(DBModule_MQUser_TimeThread, this );
52- if (NULL == pSTDThread)
52+ pSTDThread_Query = std::make_unique<std::thread>(DBModule_MQUser_TimeThread, this );
53+ if (NULL == pSTDThread_Query)
54+ {
55+ MemoryCache_IsErrorOccur = true ;
56+ MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD;
57+ return false ;
58+ }
59+ pSTDThread_Insert = std::make_unique<std::thread>(DBModule_MQUser_InsertThread, this );
60+ if (NULL == pSTDThread_Insert)
5361 {
5462 MemoryCache_IsErrorOccur = true ;
5563 MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_THREAD;
@@ -58,6 +66,27 @@ bool CMemoryCache_DBData::MemoryCache_DBData_Init(int nTimeLast, int nTimeStart)
5866 return true ;
5967}
6068/* *******************************************************************
69+ 函数名称:MemoryCache_DBData_SetHandle
70+ 函数功能:设置句柄
71+ 参数.一:xhDBSQL
72+ In/Out:In
73+ 类型:句柄
74+ 可空:N
75+ 意思:数据库句柄
76+ 返回值
77+ 类型:逻辑型
78+ 意思:是否成功
79+ 备注:
80+ *********************************************************************/
81+ bool CMemoryCache_DBData::MemoryCache_DBData_SetHandle (XNETHANDLE xhDBSQL)
82+ {
83+ MemoryCache_IsErrorOccur = false ;
84+
85+ m_xhDBSQL = xhDBSQL;
86+
87+ return true ;
88+ }
89+ /* *******************************************************************
6190函数名称:MemoryCache_DBData_Destory
6291函数功能:销毁高速缓存管理器
6392返回值
@@ -70,9 +99,13 @@ bool CMemoryCache_DBData::MemoryCache_DBData_Destory()
7099 MemoryCache_IsErrorOccur = false ;
71100
72101 bIsRun = false ;
73- if (NULL != pSTDThread)
102+ if (NULL != pSTDThread_Query)
103+ {
104+ pSTDThread_Query->join ();
105+ }
106+ if (NULL != pSTDThread_Insert)
74107 {
75- pSTDThread ->join ();
108+ pSTDThread_Insert ->join ();
76109 }
77110 return true ;
78111}
@@ -211,6 +244,35 @@ bool CMemoryCache_DBData::MemoryCache_DBData_DataDelete(XENGINE_DBMESSAGEQUEUE*
211244 st_LockerQuery.unlock ();
212245 return true ;
213246}
247+ /* *******************************************************************
248+ 函数名称:MemoryCache_DBData_QueueInsert
249+ 函数功能:队列插入工具
250+ 参数.一:lpszSQLStr
251+ In/Out:In
252+ 类型:常量字符指针
253+ 可空:N
254+ 意思:输入要插入的语句
255+ 返回值
256+ 类型:逻辑型
257+ 意思:是否成功
258+ 备注:
259+ *********************************************************************/
260+ bool CMemoryCache_DBData::MemoryCache_DBData_QueueInsert (LPCXSTR lpszSQLStr)
261+ {
262+ MemoryCache_IsErrorOccur = false ;
263+
264+ if (NULL == lpszSQLStr)
265+ {
266+ MemoryCache_IsErrorOccur = true ;
267+ MemoryCache_dwErrorCode = ERROR_XENGINE_MQCORE_MEMORYCACHE_DBDATA_PARAMENT;
268+ return false ;
269+ }
270+
271+ st_LockerList.lock ();
272+ stl_ListInsert.push_back (lpszSQLStr);
273+ st_LockerList.unlock ();
274+ return true ;
275+ }
214276// ////////////////////////////////////////////////////////////////////////
215277// 线程函数
216278// ////////////////////////////////////////////////////////////////////////
@@ -244,4 +306,26 @@ XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_TimeThread(XPVOID lParam)
244306 std::this_thread::sleep_for (std::chrono::seconds (1 ));
245307 }
246308 return 0 ;
309+ }
310+ XHTHREAD CALLBACK CMemoryCache_DBData::DBModule_MQUser_InsertThread (XPVOID lParam)
311+ {
312+ CMemoryCache_DBData* pClass_This = (CMemoryCache_DBData*)lParam;
313+
314+ while (pClass_This->bIsRun )
315+ {
316+ if (!pClass_This->stl_ListInsert .empty ())
317+ {
318+ pClass_This->st_LockerList .lock ();
319+ std::string m_StrSQLInsert = pClass_This->stl_ListInsert .front ();
320+ pClass_This->stl_ListInsert .pop_front ();
321+ pClass_This->st_LockerList .unlock ();
322+
323+ if (!DataBase_MySQL_Execute (pClass_This->m_xhDBSQL , m_StrSQLInsert.c_str ()))
324+ {
325+
326+ }
327+ }
328+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
329+ }
330+ return 0 ;
247331}
0 commit comments