Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
DatabaseWorker.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "DatabaseEnv.h"
7#include "DatabaseWorker.h"
8#include "MySQLConnection.h"
9#include "MySQLThreading.h"
10#include "SQLOperation.h"
12
13#include <stdexcept>
14
15DatabaseWorker::DatabaseWorker(Skyfire::DatabaseQueue* new_queue, MySQLConnection* con) :
16 m_queue(new_queue),
17 m_conn(con)
18{
19 if (!m_queue || !m_conn)
20 return;
21
23
24 if (m_thread->Start(m_queue->GetExecutor(),
25 [this]
26 {
27 m_queue->BindConnection(m_conn);
28 },
29 [this]
30 {
31 m_queue->ClearConnection();
32 }) == -1)
33 throw std::runtime_error("Failed to start database worker thread");
34}
35
40
42{
43 if (!m_queue)
44 return -1;
45
46 return m_queue->run(m_conn);
47}
48
50{
51 if (!m_thread)
52 return 0;
53
54 return m_thread->Join();
55}
MySQLConnection * m_conn
Skyfire::DatabaseQueue * m_queue
std::unique_ptr< Skyfire::Asio::IoContextThread > m_thread
DatabaseWorker(Skyfire::DatabaseQueue *new_queue, MySQLConnection *con)