+ introduce Sleep() for Windows

This commit is contained in:
kelson42 2012-04-19 12:10:05 +00:00
parent 9c3c3a1f68
commit b40a317bf0
2 changed files with 29 additions and 1 deletions

View File

@ -189,7 +189,11 @@ namespace kiwix {
/* Wait that the extraction has started, and so on a few /* Wait that the extraction has started, and so on a few
initialisations, to really start */ initialisations, to really start */
while(self->isToIndexQueueEmpty() && self->isArticleExtractorRunning()) { while(self->isToIndexQueueEmpty() && self->isArticleExtractorRunning()) {
#ifdef _WIN32
Sleep(100);
#else
sleep(0.1); sleep(0.1);
#endif
} }
indexerToken token; indexerToken token;
@ -228,7 +232,11 @@ namespace kiwix {
} }
self->setProgression(100); self->setProgression(100);
self->indexingPostlude(); self->indexingPostlude();
#ifdef _WIN32
Sleep(100);
#else
sleep(1); sleep(1);
#endif
self->articleIndexerRunning(false); self->articleIndexerRunning(false);
pthread_exit(NULL); pthread_exit(NULL);
return NULL; return NULL;
@ -259,12 +267,20 @@ 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
Sleep(int(this->toParseQueue.size() / 200) / 10 * 1000);
#else
sleep(int(this->toParseQueue.size() / 200) / 10); sleep(int(this->toParseQueue.size() / 200) / 10);
#endif
} }
bool Indexer::popFromToParseQueue(indexerToken &token) { bool Indexer::popFromToParseQueue(indexerToken &token) {
while (this->isToParseQueueEmpty() && this->isArticleExtractorRunning()) { while (this->isToParseQueueEmpty() && this->isArticleExtractorRunning()) {
#ifdef _WIN32
Sleep(500);
#else
sleep(0.5); sleep(0.5);
#endif
pthread_testcancel(); pthread_testcancel();
} }
@ -291,13 +307,21 @@ namespace kiwix {
void Indexer::pushToIndexQueue(indexerToken &token) { void Indexer::pushToIndexQueue(indexerToken &token) {
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
Sleep(int(this->toIndexQueue.size() / 200) / 10 * 1000);
#else
sleep(int(this->toIndexQueue.size() / 200) / 10); sleep(int(this->toIndexQueue.size() / 200) / 10);
#endif
} }
bool Indexer::popFromToIndexQueue(indexerToken &token) { bool Indexer::popFromToIndexQueue(indexerToken &token) {
while (this->isToIndexQueueEmpty() && this->isArticleParserRunning()) { while (this->isToIndexQueueEmpty() && this->isArticleParserRunning()) {
#ifdef _WIN32
Sleep(500);
#else
sleep(0.5); sleep(0.5);
#endif
pthread_testcancel(); pthread_testcancel();
} }

View File

@ -28,6 +28,10 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#ifdef _WIN32
#include <Windows.h>
#endif
#include <pthread.h> #include <pthread.h>
#include <unaccent.h> #include <unaccent.h>
#include <zim/file.h> #include <zim/file.h>