Browse Source

for mult-thread

zhengwei 8 years ago
parent
commit
accdb30d09
12 changed files with 430 additions and 37 deletions
  1. 300 0
      ProcessRemodule.cpp
  2. 53 0
      ProcessRemodule.h
  3. 11 3
      QueueStrManager.cpp
  4. 6 0
      YAServer.cpp
  5. BIN
      YAServer.rar
  6. 4 2
      YAServer.vcxproj
  7. 2 0
      YAServer.vcxproj.filters
  8. 34 20
      YAServerDlg.cpp
  9. 20 2
      YAServerDlg.h
  10. 0 10
      classdef.cpp
  11. BIN
      libmysql.dll
  12. BIN
      libmysql.lib

+ 300 - 0
ProcessRemodule.cpp

@@ -0,0 +1,300 @@
+#include "stdafx.h"
+#include "ProcessRemodule.h"
+
+#include<Windows.h>
+#include<iostream>
+using namespace std;
+//#include <thread>
+//#include <mutex>
+//#include <chrono>
+
+#define BUF_SIZE    5001
+#define REAL_BUF    BUF_SIZE-1
+ParseData* gBuf = NULL;
+unsigned int gBufFlag[BUF_SIZE] = {0};
+HANDLE gBufMutex;
+
+HANDLE hThread[MSG_PROCESS_THREAD_NUM];
+unsigned nThreadID[MSG_PROCESS_THREAD_NUM];
+
+HANDLE hSqlThread[SQL_PROCESS_THREAD_NUM];
+unsigned nSqlThreadID[SQL_PROCESS_THREAD_NUM];
+
+HANDLE hErrLogThread[ERR_LOG_PROCESS_THREAD_NUM];
+unsigned nErrLogThreadID[ERR_LOG_PROCESS_THREAD_NUM];
+
+
+
+
+BufferUtility* BufferUtility::instance = NULL;
+BufferUtility* BufferUtility::getInstance()
+{
+	if (instance == NULL)
+    {
+    	if (instance == NULL)
+    	{
+       		instance = new BufferUtility();
+    	}
+    }
+    return instance;
+}
+
+int BufferUtility::init()
+{
+	gBuf = (ParseData *)malloc(sizeof(ParseData) * BUF_SIZE);
+	memset(gBuf, 0, sizeof(ParseData) * BUF_SIZE);
+	memset(gBufFlag, 0, sizeof(gBufFlag));
+	gBufMutex  =CreateMutex(NULL, FALSE, NULL);
+	return 0;
+}
+
+ParseData* BufferUtility::getItem()
+{
+	int i = 0;
+	WaitForSingleObject(gBufMutex,INFINITE);
+	for(i=0; i<REAL_BUF; i++)
+	{
+		if(0 == gBufFlag[i])
+		{
+			break;
+		}
+	}
+	if(i == REAL_BUF)
+	{
+		return NULL;
+	}
+	gBufFlag[i] = 1;
+    ReleaseMutex(gBufMutex);
+	return &(gBuf[i]);
+}
+
+int BufferUtility::releaseItem(int i)
+{
+	WaitForSingleObject(gBufMutex,INFINITE);
+	gBufFlag[i] = 0;
+	memset(&(gBuf[i]), 0, sizeof(ParseData));
+    ReleaseMutex(gBufMutex);
+	return 0;
+}
+
+int BufferUtility::releaseItem(ParseData* itemPtr)
+{
+	int i = 0;
+	WaitForSingleObject(gBufMutex,INFINITE);
+	for(i=0; i<REAL_BUF; i++)
+	{
+		if(itemPtr == (ParseData*)(&(gBuf[i])))
+		{
+			break;
+		}
+	}
+	gBufFlag[i] = 0;
+	memset(&(gBuf[i]), 0, sizeof(ParseData));
+    ReleaseMutex(gBufMutex);
+	return 0;
+}
+
+
+int message_process_thread_init()
+{
+    //登录时初始化缓冲区
+	BufferUtility* bufferInstance = BufferUtility::getInstance();
+	bufferInstance->init();
+	//初始化消息处理线程
+
+	int i = 0;
+	for(i=0; i<MSG_PROCESS_THREAD_NUM; i++)
+	{
+	    hThread[i] = (HANDLE)_beginthreadex( NULL, 0, &message_process_entry, NULL, 0, &(nThreadID[i]) );
+        if(hThread[i] == 0)
+        {
+            printf("start thread failed,errno:%d\n",::GetLastError());
+            return 1;
+        }
+	}
+    
+	return 0;
+}
+
+
+unsigned __stdcall message_process_entry(void *param)
+{
+	 printf("thread message_process_entry start\n");
+
+	 MSG msg;
+	 //check for msg quene isExist or not
+	 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+	
+	 while(true)
+	 {
+		if(GetMessage(&msg,0,0,0)) //get msg from message queue
+		 {
+             switch(msg.message)
+             {
+                 case TCP_MSG:
+					 //add message process
+					 ParseData* data =  (ParseData*)(msg.wParam);
+					 #ifndef  UT_TEST
+                     CYAServerDlg* dlg = reinterpret_cast<CYAServerDlg*>(data->handle);
+                     //#ifdef TRACE_MEMORY_PARSE_PACKAGE
+                     dlg->parse_package_data(data->buf, data->len, data->dwConnID);
+                     //#endif // TRACE_MEMORY_PARSE_PACKAGE
+                     BufferUtility::getInstance()->releaseItem(data);
+                     break;
+                     #else
+                     //printf("current thread id: %d, receive tcp msg:%d\n", GetCurrentThreadId(), data->a);
+					 BufferUtility::getInstance()->releaseItem(data);
+                     #endif
+					 
+             }
+		 }
+	 };
+	return 0;
+}
+
+
+int send_tcp_thread_message(ParseData* data)
+{
+    //send thread message
+	unsigned thread_id = rand() % MSG_PROCESS_THREAD_NUM;
+	if(!PostThreadMessage(nThreadID[thread_id], TCP_MSG, (WPARAM)data, 0))//post thread msg
+    {
+        PostThreadMessage(nThreadID[thread_id], TCP_MSG, (WPARAM)data, 0);
+        printf("post message failed,errno:%d\n",::GetLastError());
+        BufferUtility::getInstance()->releaseItem(data);
+		return 1;
+    }
+	return 0;
+}
+
+
+int sql_process_thread_init()
+{
+	int i = 0;
+	for(i=0; i<SQL_PROCESS_THREAD_NUM; i++)
+	{
+	    hSqlThread[i] = (HANDLE)_beginthreadex( NULL, 0, &sql_process_entry, NULL, 0, &(nSqlThreadID[i]) );
+        if(hSqlThread[i] == 0)
+        {
+            printf("start thread failed,errno:%d\n",::GetLastError());
+            return 1;
+        }
+	}
+	return 0;
+}
+
+// thread function
+unsigned __stdcall sql_process_entry(void *param)
+{
+     printf("thread sql_process_entry start\n");
+
+     MSG msg;
+	 //check for msg quene isExist or not
+     PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+     while(true)
+     {
+        if(GetMessage(&msg,0,0,0)) //get msg from message queue
+         {
+            switch(msg.message)
+             {
+                 case SQL_MSG:
+                 char * pInfo = (char *)msg.wParam;
+                 //printf("current thread id: %d,recv %s\n", GetCurrentThreadId(), pInfo);
+                 //process sql command
+				 
+				 #ifndef  UT_TEST
+                 _exec_sql(pInfo);
+                 #endif
+                 delete[] pInfo;
+                 break;
+             }
+         }
+     };
+    return 0;
+}
+int send_sql_message(char* pchr)
+{
+    //send thread message
+	unsigned thread_id = rand() % SQL_PROCESS_THREAD_NUM;
+	if(!PostThreadMessage(nSqlThreadID[thread_id], SQL_MSG, (WPARAM)pchr, 0))//post thread msg
+    {
+        PostThreadMessage(nSqlThreadID[thread_id], SQL_MSG, (WPARAM)pchr, 0);
+        printf("post message failed,errno:%d\n",::GetLastError());
+        delete[] pchr;
+		return 1;
+    }
+	return 0;
+}
+
+int err_log_process_thread_init()
+{
+	int i = 0;
+	for(i=0; i<ERR_LOG_PROCESS_THREAD_NUM; i++)
+	{
+	    hErrLogThread[i] = (HANDLE)_beginthreadex( NULL, 0, &err_log_process_entry, NULL, 0, &(nErrLogThreadID[i]) );
+        if(hErrLogThread[i] == 0)
+        {
+            printf("start thread failed,errno:%d\n",::GetLastError());
+            return 1;
+        }
+	}
+	return 0;
+}
+
+// thread function
+unsigned __stdcall err_log_process_entry(void *param)
+{
+     //printf("thread err log_process_entry start\n");
+
+     MSG msg;
+	 //check for msg quene isExist or not
+     PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
+     while(true)
+     {
+        if(GetMessage(&msg,0,0,0)) //get msg from message queue
+         {
+            switch(msg.message)
+             {
+                 case ERR_LOG_MSG:
+                     char * pInfo = (char *)msg.wParam;
+				 
+				     #ifndef  UT_TEST
+                     _write_error_log(pInfo);
+                     #else
+                     delete[] pInfo;
+                     #endif
+                     break;
+             }
+         }
+     };
+    return 0;
+}
+int send_err_log_message(char* pchr)
+{
+    //send thread message
+	unsigned thread_id = rand() % ERR_LOG_PROCESS_THREAD_NUM;
+	if(!PostThreadMessage(nErrLogThreadID[thread_id], ERR_LOG_MSG, (WPARAM)pchr, 0))//post thread msg
+    {
+        PostThreadMessage(nErrLogThreadID[thread_id], ERR_LOG_MSG, (WPARAM)pchr, 0);
+        printf("post message failed,errno:%d\n",::GetLastError());
+        delete[] pchr;
+		return 1;
+    }
+	return 0;
+}
+
+int service_task_init()
+{
+	BufferUtility* bufPtr = BufferUtility::getInstance();
+	bufPtr->init();
+	message_process_thread_init();
+	sql_process_thread_init();
+	err_log_process_thread_init();
+	::Sleep(1000);
+	return 0;
+}
+
+
+
+
+

+ 53 - 0
ProcessRemodule.h

@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <windows.h>
+#include <cstdio>
+#include <process.h>
+#ifndef  UT_TEST
+#include "YAServerDlg.h"
+#else
+#include "stun_for_process_remodule.h"
+#endif
+
+
+//message process thread function
+#define  TCP_MSG WM_USER+100
+#define  MAX_INFO_SIZE     20
+#define    MSG_PROCESS_THREAD_NUM    5
+extern HANDLE hThread[MSG_PROCESS_THREAD_NUM];
+extern unsigned nThreadID[MSG_PROCESS_THREAD_NUM];
+extern int message_process_thread_init();
+extern unsigned __stdcall message_process_entry(void *param);
+extern int send_tcp_thread_message(ParseData* pchr);
+
+//SQL thread function
+#define SQL_MSG WM_USER+200
+#define    SQL_PROCESS_THREAD_NUM    3
+extern HANDLE hSqlThread[SQL_PROCESS_THREAD_NUM];
+extern unsigned nSqlThreadID[SQL_PROCESS_THREAD_NUM];
+extern int sql_process_thread_init();
+extern unsigned __stdcall sql_process_entry(void *param);
+extern int send_sql_message(char* pchr);
+
+//err log thread function
+#define ERR_LOG_MSG WM_USER+300
+#define    ERR_LOG_PROCESS_THREAD_NUM    3
+extern HANDLE hErrLogThread[ERR_LOG_PROCESS_THREAD_NUM];
+extern unsigned nErrLogThreadID[ERR_LOG_PROCESS_THREAD_NUM];
+extern int err_log_process_thread_init();
+extern unsigned __stdcall err_log_process_entry(void *param);
+extern int send_err_log_message(char* pchr);
+
+int service_task_init();
+
+class BufferUtility
+{
+private:
+	static BufferUtility* instance;
+	
+public:
+	static BufferUtility* getInstance();
+	int init();
+	ParseData* getItem();
+	int releaseItem(int index);
+	int releaseItem(ParseData* itemPtr);
+};

+ 11 - 3
QueueStrManager.cpp

@@ -1,5 +1,11 @@
 #include "stdafx.h"
 #include "QueueStrManager.h"
+#include <stdio.h>
+#include <windows.h>
+#include <cstdio>
+#include <process.h>
+#include "ProcessRemodule.h"
+
 
 
 QueueStrManager::QueueStrManager(void)
@@ -31,7 +37,8 @@ void QueueStrManager::AddString(const char * chr)
 		{
 			char* pchr = new char[m_max_length];
 			strcpy(pchr, m_chr);
-			QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
+			//QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
+			send_sql_message(pchr);
 			strcpy(m_chr, chr);
 			m_couter = 1;
 			m_length = strlen(chr);
@@ -47,7 +54,7 @@ void QueueStrManager::AddString(const char * chr)
 		}
 		m_couter++;
 		m_length += strlen(chr);
-		//TRACE(_T("sql counts: %d \r\n"),m_couter);
+		TRACE(_T("sql counts: %d \r\n"),m_couter);
 	}
 	LeaveCriticalSection(&m_csQueueList);
 }
@@ -64,7 +71,8 @@ void QueueStrManager::Execute()
 		{
 			char* pchr = new char[m_length + 2]; // Ô¤Áô½áÊø·û
 			strcpy(pchr, m_chr);
-			QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
+			//QueueUserWorkItem(m_pfunc, (LPVOID)pchr, WT_EXECUTEDEFAULT);
+			send_sql_message(pchr);
 		}
 		catch(...){
 

+ 6 - 0
YAServer.cpp

@@ -11,6 +11,9 @@
 #include "minidupm.h"
 #include "tlhelp32.h"
 
+#include "ProcessRemodule.h"
+
+
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #endif
@@ -270,6 +273,9 @@ void CYAServerApp::load_sys_conf()
 		time_send_call = atoi(ini.read(CONF_SECT_SERVER_SETTING, CONF_SEND_CALLINFO_INTERVAL).c_str());
 		time_send_help = atoi(ini.read(CONF_SECT_SERVER_SETTING, CONF_SEND_HELPINFO_INTERVAL).c_str());
 	}
+
+	service_task_init();
+	
 }
 
 /*

BIN
YAServer.rar


+ 4 - 2
YAServer.vcxproj

@@ -72,7 +72,7 @@
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <ProgramDatabaseFile>$(OutDir)\..\Symbol\$(TargetName).pdb</ProgramDatabaseFile>
       <AdditionalLibraryDirectories>..\lib\$(Configuration)\;..\thirdparty\lib\mysql\</AdditionalLibraryDirectories>
-      <AdditionalDependencies>jsoncpp_110.lib;libmysql.lib;libboost_system-vc110-mt-gd-1_58.lib;libboost_date_time-vc110-mt-gd-1_58.lib;libboost_random-vc110-mt-gd-1_58.lib</AdditionalDependencies>
+      <AdditionalDependencies>jsoncpp_110.lib;libmysql.lib;libboost_system-vc110-mt-gd-1_63.lib;libboost_date_time-vc110-mt-gd-1_63.lib;libboost_random-vc110-mt-gd-1_63.lib</AdditionalDependencies>
     </Link>
     <Midl>
       <MkTypLibCompatible>false</MkTypLibCompatible>
@@ -105,7 +105,7 @@
       <OptimizeReferences>true</OptimizeReferences>
       <ProgramDatabaseFile>$(OutDir)\..\Symbol\$(TargetName).pdb</ProgramDatabaseFile>
       <AdditionalLibraryDirectories>..\lib\$(Configuration)\;..\thirdparty\lib\mysql\</AdditionalLibraryDirectories>
-      <AdditionalDependencies>jsoncpp_110.lib;libmysql.lib;libboost_system-vc110-mt-1_58.lib;libboost_date_time-vc110-mt-1_58.lib;libboost_random-vc110-mt-1_58.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>jsoncpp_110.lib;libmysql.lib;libboost_system-vc110-mt-1_63.lib;libboost_date_time-vc110-mt-1_63.lib;libboost_random-vc110-mt-1_63.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <Midl>
       <MkTypLibCompatible>false</MkTypLibCompatible>
@@ -173,6 +173,7 @@ xcopy "$(SolutionDir)..\config.ini" "D:\0a-share\$(Configuration)\" /Y /C /D /S<
     <ClInclude Include="log_def.h" />
     <ClInclude Include="minidupm.h" />
     <ClInclude Include="MysqlConnPool.h" />
+    <ClInclude Include="ProcessRemodule.h" />
     <ClInclude Include="QueueStrManager.h" />
     <ClInclude Include="Resource.h" />
     <ClInclude Include="stdafx.h" />
@@ -247,6 +248,7 @@ xcopy "$(SolutionDir)..\config.ini" "D:\0a-share\$(Configuration)\" /Y /C /D /S<
     <ClCompile Include="LogSetting.cpp" />
     <ClCompile Include="minidump.cpp" />
     <ClCompile Include="MysqlConnPool.cpp" />
+    <ClCompile Include="ProcessRemodule.cpp" />
     <ClCompile Include="QueueStrManager.cpp" />
     <ClCompile Include="stdafx.cpp">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

+ 2 - 0
YAServer.vcxproj.filters

@@ -97,6 +97,7 @@
     <ClCompile Include="..\thirdparty\include\iocp\Src\TcpServer.cpp">
       <Filter>hp-socket\socket</Filter>
     </ClCompile>
+    <ClCompile Include="ProcessRemodule.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\common\matrix\BaseMatrix.h">
@@ -264,6 +265,7 @@
     <ClInclude Include="..\thirdparty\include\iocp\Src\TcpServer.h">
       <Filter>hp-socket\socket</Filter>
     </ClInclude>
+    <ClInclude Include="ProcessRemodule.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\config.ini" />

+ 34 - 20
YAServerDlg.cpp

@@ -1,11 +1,16 @@
 // YAServerDlg.cpp : 实现文件
 //
+#include <stdio.h>
+#include <windows.h>
+#include <cstdio>
+#include <process.h>
+
 #include "stdafx.h"
 #include "YAServer.h"	
 #include "YAServerDlg.h"
 #include "afxdialogex.h"
 
-#include <stdio.h>
+
 #include <sio_client.h>
 //#include <functional>
 //#include <thread> // c++11init_reader
@@ -28,6 +33,7 @@
 #include "LogSetting.h"
 #include "SysSetting.h"
 
+
 // 用来跟踪内存使用情况
 #define TRACE_MEMORY_WRITELOG
 #define TRACE_MEMORY_PARSE_PACKAGE
@@ -44,6 +50,7 @@
 #endif
 #endif
 
+/*
 typedef struct {
 	CYAServerDlg* handle;
 	int len;
@@ -58,9 +65,9 @@ typedef struct
 	char* path;
 	char* strLog;
 }LogInfo;
-
+*/
 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
-
+#include "ProcessRemodule.h"
 DWORD g_tickcount;
 DWORD g_diffTickCount = 0;
 DWORD g_send_tickout;
@@ -228,7 +235,7 @@ DWORD WINAPI _exec_sql(LPVOID lparam)
 		sql = NULL;
 	}
 
-	Sleep(1);
+	//Sleep(1);
 	::InterlockedDecrement(&g_QueueItemCount);
 	return 0;
 }
@@ -251,7 +258,7 @@ DWORD WINAPI _write_error_log(LPVOID lparam)
 		delete err;
 		err = NULL;
 	}
-	Sleep(1);
+	//Sleep(1);
 	::InterlockedDecrement(&g_QueueItemCount);
 	return 0;
 }
@@ -266,7 +273,7 @@ DWORD WINAPI _parse_package_data(LPVOID lparam)
 #endif // TRACE_MEMORY_PARSE_PACKAGE
 
 	free(data);
-	Sleep(1);
+	//Sleep(1);
 	::InterlockedDecrement(&g_QueueItemCount);
 	return 0;
 }
@@ -284,7 +291,7 @@ DWORD WINAPI _parse_data_server(LPVOID lparam)
 	delete data;
 	data = NULL;
 	//TRACE(_T("free data \r\n"));
-	Sleep(1);
+	//Sleep(1);
 	::InterlockedDecrement(&g_QueueItemCount);
 	return 0;
 }
@@ -3748,7 +3755,7 @@ void CYAServerDlg::deal_areas()
 				if(!it_card_vehicle->second->is_area_over_time){
 					it_card_vehicle->second->is_area_over_time = true;
 					it_card_vehicle->second->time_area_over_time = current_time;
-					store_data_card(it_card_person->second, ALARM_CARD_OVER_TIME_AREA_START);
+					store_data_card(it_card_vehicle->second, ALARM_CARD_OVER_TIME_AREA_START);
 					deal_alarm_card(it_card_vehicle->second, mp_card_list_area_over_time_vehicle, is_true, AF_CARD_AREA_OVER_TIME);
 				}
 				over_time_vehicle++;
@@ -4161,7 +4168,8 @@ void CYAServerDlg::writeErrorLog( const CString strFile, const CString strErr, b
 	err->path = CFunctions::wc2c(strFile);
 	err->strLog  = CFunctions::wc2c(strErr);
 
-	QueueUserWorkItem(_write_error_log, (LPVOID)err, WT_EXECUTEDEFAULT);
+	//QueueUserWorkItem(_write_error_log, (LPVOID)err, WT_EXECUTEDEFAULT);
+    send_err_log_message((char *)err);
 }
 
 BOOL CYAServerDlg::openLogFile(CString strFile)
@@ -5163,7 +5171,7 @@ int CYAServerDlg::select_pos_output(std::shared_ptr<Card> card)
 							card->m_nOutputPosState = LEFT_POS;
 							it_vehicle->second->m_nOutputPosState = RIGHT_POS;
 						}
-					}
+					
 				}else{
 					card->m_nOutputPosState = CENTRAL_POS;
 					it_vehicle->second->m_nOutputPosState = CENTRAL_POS;
@@ -7443,18 +7451,20 @@ EnHandleResult CYAServerDlg::OnSend( ITcpServer* pSender, CONNID dwConnID, const
 }
 EnHandleResult CYAServerDlg::OnReceive( ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength )
 {
-	ParseData *data = NULL;
+	//ParseData *data = NULL;
 	//data = (ParseData*)malloc(sizeof(ParseData));
-	data = new ParseData;
-	if(data){
+	ParseData *data = BufferUtility::getInstance()->getItem();
+	if(data)
+	{
 		data->handle = this;
 		data->dwConnID = dwConnID;
 		data->len = iLength;
 		memset(data->buf, 0, LENGTH_MSG_4K);
-		TRACE(_T("malloc size = %dk \r\n"),sizeof(ParseData)/1024);
 		memcpy(data->buf, pData, iLength);
 		//WT_EXECUTELONGFUNCTION 线程间跳转 WT_EXECUTEDEFAULT 执行完一个再执行另一个
-		QueueUserWorkItem(_parse_data_server, (LPVOID)data, WT_EXECUTEDEFAULT);
+		//QueueUserWorkItem(_parse_data_server, (LPVOID)data, WT_EXECUTEDEFAULT);
+		this->parse_data_server(data->buf, data->len, data->dwConnID);
+		BufferUtility::getInstance()->releaseItem(data);
 	}
 
 	return HR_OK;
@@ -7981,7 +7991,8 @@ void CYAServerDlg::parse_data_server( const BYTE * pData, int nLen, DWORD dwConn
 				break; // 有半个包,溢出,保留与下个包合并
 			}
 			//将完整包送出
-			ParseData *data = (ParseData*)malloc(sizeof(ParseData));
+			//ParseData *data = (ParseData*)malloc(sizeof(ParseData));
+			ParseData *data = (ParseData *)(BufferUtility::getInstance()->getItem());
 			if(data){
 				data->handle = this;
 				data->dwConnID = dwConnId;
@@ -7998,14 +8009,17 @@ void CYAServerDlg::parse_data_server( const BYTE * pData, int nLen, DWORD dwConn
 						mp_socket_buffer_list.erase(it);
 					}
 
-					free(data);
-					data = NULL;
+					//free(data);
+					//data = NULL;
+					BufferUtility::getInstance()->releaseItem(data);
 
 					LeaveCriticalSection(&m_csParseDataServer);
 					return;
 				}
 				memcpy(data->buf, buf + read_length, pkg_len);
-				QueueUserWorkItem(_parse_package_data, (LPVOID)data, WT_EXECUTEDEFAULT);
+				//QueueUserWorkItem(_parse_package_data, (LPVOID)data, WT_EXECUTEDEFAULT);
+				//send thread message
+				send_tcp_thread_message(data);
 			}
 			read_length += pkg_len;
 		}
@@ -9026,5 +9040,5 @@ void CYAServerDlg::deal_card_lost_state()
 			it_vehicle->second->status_lost = nLost;
 		}
 	}
->>>>>>> 1709f93146b0e7cdc75ba352d4cc8a9162bdefd2
+
 }

+ 20 - 2
YAServerDlg.h

@@ -67,7 +67,10 @@ struct _SOCKET_BUFFER
 	}
 };
 
-// CYAServerDlg ¶Ô»°¿ò
+extern DWORD WINAPI _exec_sql(LPVOID lparam);
+extern DWORD WINAPI _write_error_log(LPVOID lparam);
+
+// CYAServerDlg ???¡ã?¨°
 class CYAServerDlg : public CDialogEx, public CTcpServerListener
 {
 	//typedef map<string, Card*> CardMap;
@@ -454,4 +457,19 @@ public:
 	UINT m_reader_id_hist;
 	afx_msg void OnEnUpdateEditReaderid();
 	afx_msg void OnAbout();
-};
+};
+
+typedef struct {
+	CYAServerDlg* handle;
+	int len;
+	DWORD dwConnID;
+	BYTE buf[LENGTH_MSG_4K];
+}ParseData;
+
+typedef struct 
+{
+	CYAServerDlg* handle;
+	bool useTime;
+	char* path;
+	char* strLog;
+}LogInfo;

+ 0 - 10
classdef.cpp

@@ -541,16 +541,6 @@ void Card::algo_tdoa(int cnt)
 		this->origin_locate.x = p->posx / (this->map_scale*1.0);
 		this->origin_locate.y = p->posy / (this->map_scale*1.0);
 
-		//TRACE(_T("%d,%f,%f"),this->time_stamp_cal,p->posx/this->map_scale,p->posy/this->map_scale);
-		//bool bRet = false;
-		//bRet = LocateAlgorithm::CheckPosInValid(p,&pRdm,this->map_scale);
-		//if(bRet){
-		//	p->posx = INVALID_COORDINATE ;
-		//	p->posy = INVALID_COORDINATE ;
-		//	p->posz = 0 ;
-		//	//p->posz = -2 ;
-		//}
-
 		double interval_time = this->p_reader->reader_interval_time;
 
 		double deltaT = 0.0;

BIN
libmysql.dll


BIN
libmysql.lib