|
a/src/qtgui/idxthread.cpp |
|
b/src/qtgui/idxthread.cpp |
|
... |
|
... |
18 |
*/
|
18 |
*/
|
19 |
|
19 |
|
20 |
|
20 |
|
21 |
#include <qthread.h>
|
21 |
#include <qthread.h>
|
22 |
#include <qmutex.h>
|
22 |
#include <qmutex.h>
|
|
|
23 |
#include <qwaitcondition.h>
|
23 |
|
24 |
|
24 |
#include "indexer.h"
|
25 |
#include "indexer.h"
|
25 |
#include "debuglog.h"
|
26 |
#include "debuglog.h"
|
26 |
#include "idxthread.h"
|
27 |
#include "idxthread.h"
|
27 |
#include "smallut.h"
|
28 |
#include "smallut.h"
|
|
... |
|
... |
33 |
static IdxThreadStatus indexingstatus = IDXTS_OK;
|
34 |
static IdxThreadStatus indexingstatus = IDXTS_OK;
|
34 |
static string indexingReason;
|
35 |
static string indexingReason;
|
35 |
static int stopidxthread;
|
36 |
static int stopidxthread;
|
36 |
|
37 |
|
37 |
static QMutex curfile_mutex;
|
38 |
static QMutex curfile_mutex;
|
|
|
39 |
static QMutex action_mutex;
|
|
|
40 |
static QWaitCondition action_wait;
|
38 |
|
41 |
|
39 |
class IdxThread : public QThread , public DbIxStatusUpdater {
|
42 |
class IdxThread : public QThread , public DbIxStatusUpdater {
|
40 |
virtual void run();
|
43 |
virtual void run();
|
41 |
public:
|
44 |
public:
|
|
|
45 |
// This gets called at intervals by the file system walker to check for
|
|
|
46 |
// a requested interrupt and update the current status.
|
42 |
virtual bool update() {
|
47 |
virtual bool update() {
|
43 |
QMutexLocker locker(&curfile_mutex);
|
48 |
QMutexLocker locker(&curfile_mutex);
|
44 |
m_statusSnap = status;
|
49 |
m_statusSnap = status;
|
45 |
LOGDEB1(("IdxThread::update: indexing %s\n", m_statusSnap.fn.c_str()));
|
50 |
LOGDEB1(("IdxThread::update: indexing %s\n", m_statusSnap.fn.c_str()));
|
46 |
if (stopindexing) {
|
51 |
if (stopindexing) {
|
|
... |
|
... |
57 |
};
|
62 |
};
|
58 |
|
63 |
|
59 |
void IdxThread::run()
|
64 |
void IdxThread::run()
|
60 |
{
|
65 |
{
|
61 |
recoll_threadinit();
|
66 |
recoll_threadinit();
|
|
|
67 |
action_mutex.lock();
|
62 |
for (;;) {
|
68 |
for (;;) {
|
63 |
if (stopidxthread) {
|
|
|
64 |
return;
|
|
|
65 |
}
|
|
|
66 |
if (startindexing) {
|
69 |
if (startindexing) {
|
67 |
startindexing = 0;
|
70 |
startindexing = 0;
|
|
|
71 |
action_mutex.unlock();
|
|
|
72 |
|
68 |
m_interrupted = false;
|
73 |
m_interrupted = false;
|
69 |
indexingstatus = IDXTS_NULL;
|
74 |
indexingstatus = IDXTS_NULL;
|
70 |
// We have to make a copy of the config (setKeydir changes
|
75 |
// We have to make a copy of the config (setKeydir changes
|
71 |
// it during indexation)
|
76 |
// it during indexation)
|
72 |
RclConfig *myconf = new RclConfig(*cnf);
|
77 |
RclConfig *myconf = new RclConfig(*cnf);
|
|
... |
|
... |
82 |
indexingstatus = IDXTS_ERROR;
|
87 |
indexingstatus = IDXTS_ERROR;
|
83 |
indexingReason = "Indexing failed: " + indexer->getReason();
|
88 |
indexingReason = "Indexing failed: " + indexer->getReason();
|
84 |
}
|
89 |
}
|
85 |
rezero = false;
|
90 |
rezero = false;
|
86 |
delete indexer;
|
91 |
delete indexer;
|
|
|
92 |
action_mutex.lock();
|
87 |
}
|
93 |
}
|
88 |
msleep(100);
|
94 |
|
|
|
95 |
if (stopidxthread) {
|
|
|
96 |
action_mutex.unlock();
|
|
|
97 |
return;
|
|
|
98 |
}
|
|
|
99 |
action_wait.wait(&action_mutex);
|
89 |
}
|
100 |
}
|
90 |
}
|
101 |
}
|
91 |
|
102 |
|
92 |
static IdxThread idxthread;
|
103 |
static IdxThread idxthread;
|
|
|
104 |
|
|
|
105 |
// Functions called by the main thread
|
93 |
|
106 |
|
94 |
void start_idxthread(const RclConfig& cnf)
|
107 |
void start_idxthread(const RclConfig& cnf)
|
95 |
{
|
108 |
{
|
96 |
idxthread.cnf = &cnf;
|
109 |
idxthread.cnf = &cnf;
|
97 |
idxthread.start();
|
110 |
idxthread.start();
|
98 |
}
|
111 |
}
|
99 |
|
112 |
|
100 |
void stop_idxthread()
|
113 |
void stop_idxthread()
|
101 |
{
|
114 |
{
|
|
|
115 |
action_mutex.lock();
|
|
|
116 |
startindexing = 0;
|
102 |
stopindexing = 1;
|
117 |
stopindexing = 1;
|
103 |
stopidxthread = 1;
|
118 |
stopidxthread = 1;
|
|
|
119 |
action_mutex.unlock();
|
|
|
120 |
action_wait.wakeAll();
|
104 |
idxthread.wait();
|
121 |
idxthread.wait();
|
105 |
}
|
122 |
}
|
|
|
123 |
|
106 |
void stop_indexing()
|
124 |
void stop_indexing()
|
107 |
{
|
125 |
{
|
|
|
126 |
action_mutex.lock();
|
|
|
127 |
startindexing = 0;
|
108 |
stopindexing = 1;
|
128 |
stopindexing = 1;
|
|
|
129 |
action_mutex.unlock();
|
|
|
130 |
action_wait.wakeAll();
|
109 |
}
|
131 |
}
|
|
|
132 |
|
110 |
void start_indexing(bool raz)
|
133 |
void start_indexing(bool raz)
|
111 |
{
|
134 |
{
|
|
|
135 |
action_mutex.lock();
|
112 |
startindexing = 1;
|
136 |
startindexing = 1;
|
113 |
rezero = raz;
|
137 |
rezero = raz;
|
|
|
138 |
action_mutex.unlock();
|
|
|
139 |
action_wait.wakeAll();
|
114 |
}
|
140 |
}
|
|
|
141 |
|
115 |
DbIxStatus idxthread_idxStatus()
|
142 |
DbIxStatus idxthread_idxStatus()
|
116 |
{
|
143 |
{
|
117 |
QMutexLocker locker(&curfile_mutex);
|
144 |
QMutexLocker locker(&curfile_mutex);
|
118 |
return idxthread.m_statusSnap;
|
145 |
return idxthread.m_statusSnap;
|
119 |
}
|
146 |
}
|
|
|
147 |
|
120 |
bool idxthread_idxInterrupted()
|
148 |
bool idxthread_idxInterrupted()
|
121 |
{
|
149 |
{
|
122 |
return idxthread.m_interrupted;
|
150 |
return idxthread.m_interrupted;
|
123 |
}
|
151 |
}
|
|
|
152 |
|
124 |
string idxthread_getReason()
|
153 |
string idxthread_getReason()
|
125 |
{
|
154 |
{
|
126 |
return indexingReason;
|
155 |
return indexingReason;
|
127 |
}
|
156 |
}
|
|
|
157 |
|
128 |
IdxThreadStatus idxthread_getStatus()
|
158 |
IdxThreadStatus idxthread_getStatus()
|
129 |
{
|
159 |
{
|
130 |
return indexingstatus;
|
160 |
return indexingstatus;
|
131 |
}
|
161 |
}
|