mirror of https://github.com/kiwix/libkiwix.git
Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix
This commit is contained in:
commit
9bc88497df
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011-2012 Emmanuel Engelhart <kelson@kiwix.org>
|
* Copyright 2011-2014 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -54,6 +54,10 @@ namespace kiwix {
|
||||||
pthread_mutex_init(&verboseMutex, NULL);
|
pthread_mutex_init(&verboseMutex, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Destructor */
|
||||||
|
Indexer::~Indexer() {
|
||||||
|
}
|
||||||
|
|
||||||
/* Read the stopwords */
|
/* Read the stopwords */
|
||||||
void Indexer::readStopWords(const string languageCode) {
|
void Indexer::readStopWords(const string languageCode) {
|
||||||
std::string stopWord;
|
std::string stopWord;
|
||||||
|
@ -246,11 +250,8 @@ namespace kiwix {
|
||||||
writeTextFile(path, self->getZimId());
|
writeTextFile(path, self->getZimId());
|
||||||
|
|
||||||
self->setProgression(100);
|
self->setProgression(100);
|
||||||
#ifdef _WIN32
|
kiwix::sleep(100);
|
||||||
Sleep(100);
|
|
||||||
#else
|
|
||||||
usleep(100000);
|
|
||||||
#endif
|
|
||||||
self->articleIndexerRunning(false);
|
self->articleIndexerRunning(false);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -281,21 +282,12 @@ namespace kiwix {
|
||||||
pthread_mutex_lock(&toParseQueueMutex);
|
pthread_mutex_lock(&toParseQueueMutex);
|
||||||
this->toParseQueue.push(token);
|
this->toParseQueue.push(token);
|
||||||
pthread_mutex_unlock(&toParseQueueMutex);
|
pthread_mutex_unlock(&toParseQueueMutex);
|
||||||
#ifdef _WIN32
|
kiwix::sleep(int(this->toParseQueue.size() / 200) / 10 * 1000);
|
||||||
Sleep(int(this->toParseQueue.size() / 200) / 10 * 1000);
|
|
||||||
#else
|
|
||||||
usleep(int(this->toParseQueue.size() / 200) / 10 * 1000000);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Indexer::popFromToParseQueue(indexerToken &token) {
|
bool Indexer::popFromToParseQueue(indexerToken &token) {
|
||||||
while (this->isToParseQueueEmpty() && this->isArticleExtractorRunning()) {
|
while (this->isToParseQueueEmpty() && this->isArticleExtractorRunning()) {
|
||||||
#ifdef _WIN32
|
kiwix::sleep(500);
|
||||||
Sleep(500);
|
|
||||||
#else
|
|
||||||
usleep(500000);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (this->getVerboseFlag()) {
|
if (this->getVerboseFlag()) {
|
||||||
std::cout << "Waiting... ToParseQueue is empty for now..." << std::endl;
|
std::cout << "Waiting... ToParseQueue is empty for now..." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -327,20 +319,12 @@ namespace kiwix {
|
||||||
pthread_mutex_lock(&toIndexQueueMutex);
|
pthread_mutex_lock(&toIndexQueueMutex);
|
||||||
this->toIndexQueue.push(token);
|
this->toIndexQueue.push(token);
|
||||||
pthread_mutex_unlock(&toIndexQueueMutex);
|
pthread_mutex_unlock(&toIndexQueueMutex);
|
||||||
#ifdef _WIN32
|
kiwix::sleep(int(this->toIndexQueue.size() / 200) / 10 * 1000);
|
||||||
Sleep(int(this->toIndexQueue.size() / 200) / 10 * 1000);
|
|
||||||
#else
|
|
||||||
usleep(int(this->toIndexQueue.size() / 200) / 10 * 1000000);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Indexer::popFromToIndexQueue(indexerToken &token) {
|
bool Indexer::popFromToIndexQueue(indexerToken &token) {
|
||||||
while (this->isToIndexQueueEmpty() && this->isArticleParserRunning()) {
|
while (this->isToIndexQueueEmpty() && this->isArticleParserRunning()) {
|
||||||
#ifdef _WIN32
|
kiwix::sleep(500);
|
||||||
Sleep(500);
|
|
||||||
#else
|
|
||||||
usleep(500000);
|
|
||||||
#endif
|
|
||||||
if (this->getVerboseFlag()) {
|
if (this->getVerboseFlag()) {
|
||||||
std::cout << "Waiting... ToIndexQueue is empty for now..." << std::endl;
|
std::cout << "Waiting... ToIndexQueue is empty for now..." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -443,11 +427,7 @@ namespace kiwix {
|
||||||
pthread_detach(this->articleExtractor);
|
pthread_detach(this->articleExtractor);
|
||||||
|
|
||||||
while(this->isArticleExtractorRunning() && this->getArticleCount() == 0) {
|
while(this->isArticleExtractorRunning() && this->getArticleCount() == 0) {
|
||||||
#ifdef _WIN32
|
kiwix::sleep(100);
|
||||||
Sleep(100);
|
|
||||||
#else
|
|
||||||
usleep(100000);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this->articleParserRunning(true);
|
this->articleParserRunning(true);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
|
* Copyright 2014 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,14 +28,9 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <Windows.h>
|
|
||||||
#else
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stringTools.h>
|
#include <stringTools.h>
|
||||||
|
#include <otherTools.h>
|
||||||
#include <resourceTools.h>
|
#include <resourceTools.h>
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
#include <zim/article.h>
|
#include <zim/article.h>
|
||||||
|
@ -62,6 +57,8 @@ namespace kiwix {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Indexer();
|
Indexer();
|
||||||
|
virtual ~Indexer();
|
||||||
|
|
||||||
bool start(const string zimPath, const string indexPath);
|
bool start(const string zimPath, const string indexPath);
|
||||||
bool stop();
|
bool stop();
|
||||||
bool isRunning();
|
bool isRunning();
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "otherTools.h"
|
||||||
|
|
||||||
|
void kiwix::sleep(unsigned int milliseconds) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
Sleep(milliseconds);
|
||||||
|
#else
|
||||||
|
usleep(1000 * milliseconds);
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef KIWIX_OTHERTOOLS_H
|
||||||
|
#define KIWIX_OTHERTOOLS_H
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace kiwix {
|
||||||
|
void sleep(unsigned int milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue