mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use a simple Thread in SqliteDatabase
This commit is contained in:
@@ -51,18 +51,24 @@ SqliteStatement::~SqliteStatement ()
|
||||
|
||||
SqliteDatabase::SqliteDatabase (const char* host)
|
||||
: Database (host)
|
||||
, Thread ("sqlitedb")
|
||||
, m_walMutex (this, "SqliteDB", __FILE__, __LINE__)
|
||||
, m_thread ("sqlitedb")
|
||||
, mWalQ (NULL)
|
||||
, walRunning (false)
|
||||
{
|
||||
m_thread.start ();
|
||||
startThread ();
|
||||
|
||||
mConnection = NULL;
|
||||
mAuxConnection = NULL;
|
||||
mCurrentStmt = NULL;
|
||||
}
|
||||
|
||||
SqliteDatabase::~SqliteDatabase ()
|
||||
{
|
||||
// Blocks until the thread exits in an orderly fashion
|
||||
stopThread ();
|
||||
}
|
||||
|
||||
void SqliteDatabase::connect ()
|
||||
{
|
||||
int rc = sqlite3_open_v2 (mHost.c_str (), &mConnection,
|
||||
@@ -317,7 +323,22 @@ void SqliteDatabase::doHook (const char* db, int pages)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_thread.call (&SqliteDatabase::runWal, this);
|
||||
notify();
|
||||
}
|
||||
}
|
||||
|
||||
void SqliteDatabase::run ()
|
||||
{
|
||||
// Simple thread loop runs Wal every time it wakes up via
|
||||
// the call to Thread::notify, unless Thread::threadShouldExit returns
|
||||
// true in which case we simply break.
|
||||
//
|
||||
for (;;)
|
||||
{
|
||||
wait ();
|
||||
if (threadShouldExit())
|
||||
break;
|
||||
runWal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,12 @@
|
||||
|
||||
class SqliteDatabase
|
||||
: public Database
|
||||
, LeakChecked <SqliteDatabase>
|
||||
, private Thread
|
||||
, private LeakChecked <SqliteDatabase>
|
||||
{
|
||||
public:
|
||||
explicit SqliteDatabase (char const* host);
|
||||
~SqliteDatabase ();
|
||||
|
||||
void connect ();
|
||||
void disconnect ();
|
||||
@@ -66,19 +68,19 @@ public:
|
||||
return this;
|
||||
}
|
||||
|
||||
void runWal ();
|
||||
void doHook (const char* db, int walSize);
|
||||
|
||||
int getKBUsedDB ();
|
||||
int getKBUsedAll ();
|
||||
|
||||
private:
|
||||
void run ();
|
||||
void runWal ();
|
||||
|
||||
typedef RippleMutex LockType;
|
||||
typedef LockType::ScopedLockType ScopedLockType;
|
||||
LockType m_walMutex;
|
||||
|
||||
ThreadWithCallQueue m_thread;
|
||||
|
||||
sqlite3* mConnection;
|
||||
// VFALCO TODO Why do we need an "aux" connection? Should just use a second SqliteDatabase object.
|
||||
sqlite3* mAuxConnection;
|
||||
@@ -89,6 +91,8 @@ private:
|
||||
bool walRunning;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class SqliteStatement
|
||||
{
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user