Ver código fonte

Improvement to async query code to not have subsequent query held on main client/spawn process threads

Fixed the queue being used while we process existing queries from the same query id group.  We subsequently check at the end of the thread if more queries are available to process and start a new thread to build a new temp queue.
Image 4 anos atrás
pai
commit
66c23cf771
1 arquivos alterados com 15 adições e 2 exclusões
  1. 15 2
      EQ2/source/common/database.cpp

+ 15 - 2
EQ2/source/common/database.cpp

@@ -90,7 +90,6 @@ bool Database::Init(bool silentLoad) {
 	int32 port=0;
 	bool compression = false;
 	bool items[6] = {false, false, false, false, false, false};
-	const char* itemsNames[6] = { "host", "user", "passwd", "database", "port", "compression" };
 	const char* exampleIni[] = { "[Database]", "host = localhost", "user = root", "password = pass", "database = dbname", "### --- Assure each parameter is on a new line!" };
 
 	if(!ReadDBINI(host, user, passwd, database, port, compression, items)) {
@@ -360,6 +359,7 @@ void Database::RunAsyncQueries(int32 queryid)
 	itr->second.clear();
 	asyncQueries.erase(itr);
 	DBAsyncMutex.releasewritelock();
+	asyncQueriesMutex[queryid]->releasewritelock();
 
 	int32 count = 0;
 	while (queries.size() > 0)
@@ -372,7 +372,20 @@ void Database::RunAsyncQueries(int32 queryid)
 	}
 	FreeDBInstance(asyncdb);
 
-	asyncQueriesMutex[queryid]->releasewritelock();
+	bool isActive = IsActiveQuery(queryid);
+	if (isActive)
+	{
+		printf("Need to startup new thread, more queries to process.\n");
+		continueAsync = true;
+		DBStruct* tmp = new DBStruct;
+		tmp->queryid = queryid;
+#ifdef WIN32
+		_beginthread(DBAsyncQueries, 0, (void*)tmp);
+#else
+		pthread_create(&t1, NULL, DBAsyncQueries, (void*)tmp);
+		pthread_detach(t1);
+#endif
+	}
 }
 
 void Database::AddAsyncQuery(Query* query)