metin2united
flygun

[RLS]AsyncSQL with std::mutex and std::thread

17 posts in this topic

I edited Async Class to use C++ Standard mutex and thread support

AsyncSQL.h

ASyncSQL.cpp

 

plus if you have this line in main.cpp inside the main function inside the db core source delete it 

DBManager.Quit();

this line will close MySQL connections  before making sure that all the queries are done (which may not save the last thing a player do before closing the server) plus it will dump a core file since the db core will abort without successful exit! 

 

#edited

  • Using std::gurad (which unlock the mutex when the object is destroyed) instead of manually lock and unlock mutex 
  • rewrote the Profiler class with std::chrono 

#Note : Don't  just copy and paste .. make a backup , test , then use it

Best regards.

  • Like 4
  • Thanks 2

Share this post


Link to post
Share on other sites
12 minutes ago, martysama0134 said:

AsyncSQL.h

This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff.
 

sorry i edited the file after putting the link .. didn't thought that the link will change!
thanks for noticing 

Share this post


Link to post
Share on other sites

You can edit a little more, I think it will look better.

 

Use nullptr instead of NULL

Please stop usage header guards in 2019, go for pragma once

Use smart pointers instead of raw pointers

Use lock_guard instead of lock manually everytime

Clear dirty korean commands, unused veriables etc.

 

Anyway thanks for publishing.

  • Like 1

Share this post


Link to post
Share on other sites
15 minutes ago, Koray said:

You can edit a little more, I think it will look better.

 

Use nullptr instead of NULL

Please stop usage header guards in 2019, go for pragma once

Use smart pointers instead of raw pointers

Use lock_guard instead of lock manually everytime

Clear dirty korean commands, unused veriables etc.

 

Anyway thanks for publishing.

i'll rewrite the whole file today or tomorrow maximum .. i just wanted to see if actually someone want it ... 

Share this post


Link to post
Share on other sites
3 hours ago, flatik said:

Thank you for your public!

I found an error!

 

Here's the picture of it

https://i.imgur.com/O6LaJw1.png

show me real error message ... see if their is a ".core" file and back trace it 


 

1 hour ago, ReFresh said:

Which requirements are needed for use this AsyncSQL?

c++11 and above 

  • Thanks 1

Share this post


Link to post
Share on other sites

You should check if the thread is already joined, or just simply check if you already called Quit, cus db is crashing at the very end of the process, because quit is called from the db too (and also from the destructor of CAsyncSQL).
NpEVRji.png

5lM7g8a.png

  • Sad 1

Share this post


Link to post
Share on other sites
17 hours ago, masodikbela said:

You should check if the thread is already joined, or just simply check if you already called Quit, cus db is crashing at the very end of the process, because quit is called from the db too (and also from the destructor of CAsyncSQL).
NpEVRji.png

5lM7g8a.png

i've already mentioned this in the post

 

Share this post


Link to post
Share on other sites
Le 09/03/2019 à 17:45, flatik a dit :

Thank you for your public!

I found an error!

 

Here's the picture of it

https://i.imgur.com/O6LaJw1.png

m_pThread

Should be initialized in constructor to avoid undefined behavior, the constructor should look like this

CAsyncSQL::CAsyncSQL()
	: m_stHost(""), m_stUser(""), m_stPassword(""), m_stDB(""), m_stLocale(""),
	m_iMsgCount(0), m_iPort(0), m_bEnd(false),
	m_mtxQuery(), m_mtxResult(),
	m_iQueryFinished(0), m_ulThreadID(0), m_bConnected(false),
	m_iCopiedQuery(0),
	m_pThread(nullptr)
{
	memset(&m_hDB, 0, sizeof(m_hDB));

	m_aiPipe[0] = 0;
	m_aiPipe[1] = 0;
}

 

  • Like 1

Share this post


Link to post
Share on other sites
On 7/19/2019 at 12:51 AM, Trial said:

m_pThread

Should be initialized in constructor to avoid undefined behavior, the constructor should look like this


CAsyncSQL::CAsyncSQL()
	: m_stHost(""), m_stUser(""), m_stPassword(""), m_stDB(""), m_stLocale(""),
	m_iMsgCount(0), m_iPort(0), m_bEnd(false),
	m_mtxQuery(), m_mtxResult(),
	m_iQueryFinished(0), m_ulThreadID(0), m_bConnected(false),
	m_iCopiedQuery(0),
	m_pThread(nullptr)
{
	memset(&m_hDB, 0, sizeof(m_hDB));

	m_aiPipe[0] = 0;
	m_aiPipe[1] = 0;
}

 

this was the case but somehow it changed ...

 

Now it's updated !!

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.