Use a simple Thread in SqliteDatabase

This commit is contained in:
Vinnie Falco
2013-10-03 18:29:20 -07:00
parent 5fc823ae08
commit b76443dbde
2 changed files with 32 additions and 7 deletions

View File

@@ -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();
}
}