use proper locking/sleeping object for idx thread sync

This commit is contained in:
dockes 2009-06-22 15:25:49 +00:00
parent e4f683f219
commit 8a377d135a
3 changed files with 46 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include <qthread.h>
#include <qmutex.h>
#include <qwaitcondition.h>
#include "indexer.h"
#include "debuglog.h"
@ -35,10 +36,14 @@ static string indexingReason;
static int stopidxthread;
static QMutex curfile_mutex;
static QMutex action_mutex;
static QWaitCondition action_wait;
class IdxThread : public QThread , public DbIxStatusUpdater {
virtual void run();
public:
// This gets called at intervals by the file system walker to check for
// a requested interrupt and update the current status.
virtual bool update() {
QMutexLocker locker(&curfile_mutex);
m_statusSnap = status;
@ -59,12 +64,12 @@ class IdxThread : public QThread , public DbIxStatusUpdater {
void IdxThread::run()
{
recoll_threadinit();
action_mutex.lock();
for (;;) {
if (stopidxthread) {
return;
}
if (startindexing) {
startindexing = 0;
action_mutex.unlock();
m_interrupted = false;
indexingstatus = IDXTS_NULL;
// We have to make a copy of the config (setKeydir changes
@ -84,13 +89,21 @@ void IdxThread::run()
}
rezero = false;
delete indexer;
}
msleep(100);
action_mutex.lock();
}
if (stopidxthread) {
action_mutex.unlock();
return;
}
action_wait.wait(&action_mutex);
}
}
static IdxThread idxthread;
// Functions called by the main thread
void start_idxthread(const RclConfig& cnf)
{
idxthread.cnf = &cnf;
@ -99,32 +112,49 @@ void start_idxthread(const RclConfig& cnf)
void stop_idxthread()
{
action_mutex.lock();
startindexing = 0;
stopindexing = 1;
stopidxthread = 1;
action_mutex.unlock();
action_wait.wakeAll();
idxthread.wait();
}
void stop_indexing()
{
action_mutex.lock();
startindexing = 0;
stopindexing = 1;
action_mutex.unlock();
action_wait.wakeAll();
}
void start_indexing(bool raz)
{
action_mutex.lock();
startindexing = 1;
rezero = raz;
action_mutex.unlock();
action_wait.wakeAll();
}
DbIxStatus idxthread_idxStatus()
{
QMutexLocker locker(&curfile_mutex);
return idxthread.m_statusSnap;
}
bool idxthread_idxInterrupted()
{
return idxthread.m_interrupted;
}
string idxthread_getReason()
{
return indexingReason;
}
IdxThreadStatus idxthread_getStatus()
{
return indexingstatus;

View File

@ -124,8 +124,6 @@ static void recollCleanup()
{
LOGDEB(("recollCleanup: writing settings\n"));
rwSettings(true);
LOGDEB2(("recollCleanup: stopping idx thread\n"));
stop_idxthread();
LOGDEB2(("recollCleanup: closing database\n"));
deleteZ(rcldb);
deleteZ(rclconfig);

View File

@ -172,7 +172,9 @@ void RclMain::init()
if (prefs.catgToolBar) {
catgCMB = new QComboBox(FALSE, new QToolBar(this), "catCMB");
catgCMB->insertItem(tr("All"));
#if (QT_VERSION >= 0x040000)
catgCMB->setToolTip(tr("Document category filter"));
#endif
}
// Document categories buttons
@ -379,7 +381,11 @@ void RclMain::fileExit()
prefs.ssearchTyp = sSearch->searchTypCMB->currentItem();
if (asearchform)
delete asearchform;
// Let the exit handler clean up things
// We'd prefer to do this in the exit handler, but it's apparently to late
// and some of the qt stuff is already dead at this point?
LOGDEB2(("RclMain::fileExit() : stopping idx thread\n"));
stop_idxthread();
// Let the exit handler clean up the rest (internal recoll stuff).
exit(0);
}
@ -417,6 +423,7 @@ void RclMain::periodic100()
// Indexing is running
m_idxStatusAck = false;
fileToggleIndexingAction->setText(tr("Stop &Indexing"));
fileToggleIndexingAction->setEnabled(TRUE);
// The toggle thing is for the status to flash
if (toggle == 0) {
QString msg = tr("Indexing in progress: ");
@ -455,6 +462,9 @@ void RclMain::periodic100()
fileExit();
}
// This gets called when the indexing action is activated. It starts
// the requested action, and disables the menu entry. This will be
// re-enabled by the indexing status check
void RclMain::toggleIndexing()
{
if (idxthread_getStatus() == IDXTS_NULL) {