1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-20 09:07:14 +02:00

Asynchronous statements implementation for SQLite.

Extend worker threads to allow tasks to re-queue themselves during completion.
This commit is contained in:
Sandu Liviu Catalin
2022-07-23 19:27:40 +03:00
parent 0d927f5d72
commit 49df7b75ee
6 changed files with 324 additions and 37 deletions

View File

@ -47,9 +47,11 @@ struct CpBaseAction : public ThreadPoolItem
~CpBaseAction() override = default;
/* --------------------------------------------------------------------------------------------
* Task completed callback.
* Invoked in main thread by the thread pool after the task was completed.
* If it returns true then it will be put back into the queue to be processed again.
* If the boolean parameter is trye then the thread-pool is in the process of shutting down.
*/
void OnCompleted() override
SQMOD_NODISCARD bool OnCompleted(bool SQ_UNUSED_ARG(stop)) override
{
// Is there a callback?
if (!mCallback.IsNull())
@ -58,6 +60,8 @@ struct CpBaseAction : public ThreadPoolItem
}
// Unlock the session
mInstance->mPending = nullptr;
// Don't re-queue
return false;
}
/* --------------------------------------------------------------------------------------------

View File

@ -1716,6 +1716,15 @@ public:
SQMOD_GET_VALID(*this)->Create(query.mPtr, query.mLen);
}
/* --------------------------------------------------------------------------------------------
* Construct a statement under the specified connection using the specified string.
*/
SQLiteStatement(const SQLiteConnRef & connection, const SQChar * query, SQInteger length)
: m_Handle(new SQLiteStmtHnd(connection))
{
SQMOD_GET_VALID(*this)->Create(query, length);
}
/* --------------------------------------------------------------------------------------------
* Construct a statement under the specified connection using the specified string.
*/
@ -1724,7 +1733,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Direct handle constructor.
*/
explicit SQLiteStatement(SQLiteStmtRef s)
explicit SQLiteStatement(SQLiteStmtRef s)
: m_Handle(std::move(s))
{
/* ... */