From 4462ce0d83ac5d0960eb5753f4b1d28bda5a17f5 Mon Sep 17 00:00:00 2001 From: Clemens Zeidler Date: Thu, 28 Oct 2010 15:11:02 +0000 Subject: [PATCH] - The purpose of the SwapEntryRefVector is to exchange entry_ref's between the watcher thread and the worker thread. The idea is to use two list, the first list is filled by the watcher and the second is passed to the worker. When the worker finished both lists are swapped. This was totally broken, the list swap was not locked and SwapList always returned the wrong list. - Use BAutolock class. - Write the correct sync time in micro seconds. - Fix the event dispatching in the worker thread. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39171 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/Jamfile | 1 + src/servers/index_server/AnalyserDispatcher.h | 2 +- src/servers/index_server/CatchUpManager.cpp | 7 ++- src/servers/index_server/VolumeWatcher.cpp | 44 +++++++++---------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/servers/Jamfile b/src/servers/Jamfile index 77f3dc77eb..afe9ac36d2 100644 --- a/src/servers/Jamfile +++ b/src/servers/Jamfile @@ -4,6 +4,7 @@ SubInclude HAIKU_TOP src servers app ; SubInclude HAIKU_TOP src servers bluetooth ; SubInclude HAIKU_TOP src servers cddb_daemon ; SubInclude HAIKU_TOP src servers debug ; +SubInclude HAIKU_TOP src servers index_server ; SubInclude HAIKU_TOP src servers input ; SubInclude HAIKU_TOP src servers mail ; SubInclude HAIKU_TOP src servers media ; diff --git a/src/servers/index_server/AnalyserDispatcher.h b/src/servers/index_server/AnalyserDispatcher.h index 6e90ceef4a..95e596ba46 100644 --- a/src/servers/index_server/AnalyserDispatcher.h +++ b/src/servers/index_server/AnalyserDispatcher.h @@ -20,7 +20,7 @@ class FileAnalyser; class AnalyserDispatcher : public BLooper { public: - AnalyserDispatcher(); + AnalyserDispatcher(const char* name); ~AnalyserDispatcher(); void Stop(); diff --git a/src/servers/index_server/CatchUpManager.cpp b/src/servers/index_server/CatchUpManager.cpp index 72985ce800..f2c675011d 100644 --- a/src/servers/index_server/CatchUpManager.cpp +++ b/src/servers/index_server/CatchUpManager.cpp @@ -25,6 +25,8 @@ const bigtime_t kSecond = 1000000; CatchUpAnalyser::CatchUpAnalyser(const BVolume& volume, time_t start, time_t end, BHandler* manager) : + AnalyserDispatcher("CatchUpAnalyser"), + fVolume(volume), fStart(start), fEnd(end), @@ -101,11 +103,14 @@ CatchUpAnalyser::_CatchUp() for (uint32 i = 0; i < entryList.size(); i++) { if (Stopped()) return; + if (i % 100 == 0) + printf("Catch up: %i/%i\n", (int)i,(int)entryList.size()); AnalyseEntry(entryList[i]); } LastEntry(); - _WriteSyncSatus(fEnd); + _WriteSyncSatus(fEnd * kSecond); + printf("Catched up.\n"); BMessenger managerMessenger(fCatchUpManager); BMessage msg(kCatchUpDone); diff --git a/src/servers/index_server/VolumeWatcher.cpp b/src/servers/index_server/VolumeWatcher.cpp index ced593e6f9..c153d88c64 100644 --- a/src/servers/index_server/VolumeWatcher.cpp +++ b/src/servers/index_server/VolumeWatcher.cpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -73,9 +74,9 @@ WatchNameHandler::StatChanged(ino_t node, dev_t device, int32 statFields) } -AnalyserDispatcher::AnalyserDispatcher() +AnalyserDispatcher::AnalyserDispatcher(const char* name) : - BLooper(NULL, B_LOW_PRIORITY), + BLooper(name, B_LOW_PRIORITY), fStopped(0) { @@ -143,13 +144,11 @@ AnalyserDispatcher::AddAnalyser(FileAnalyser* analyser) return false; bool result; - Lock(); - if (_FindAnalyser(analyser->Name())) { - Unlock(); + BAutolock _(this); + if (_FindAnalyser(analyser->Name())) return false; - } + result = fFileAnalyserList.AddItem(analyser); - Unlock(); return result; } @@ -157,15 +156,13 @@ AnalyserDispatcher::AddAnalyser(FileAnalyser* analyser) bool AnalyserDispatcher::RemoveAnalyser(const BString& name) { - Lock(); + BAutolock _(this); FileAnalyser* analyser = _FindAnalyser(name); if (analyser) { fFileAnalyserList.RemoveItem(analyser); delete analyser; - Unlock(); return true; } - Unlock(); return false; } @@ -216,6 +213,8 @@ AnalyserDispatcher::SetWatchingPosition(bigtime_t time) VolumeWorker::VolumeWorker(VolumeWatcher* watcher) : + AnalyserDispatcher("VolumeWorker"), + fVolumeWatcher(watcher), fBusy(0) { @@ -262,16 +261,16 @@ VolumeWorker::_Work() AnalyseEntry(collection.createdList->at(i)); collection.createdList->clear(); + for (unsigned int i = 0; i < collection.deletedList->size() || Stopped(); + i++) + DeleteEntry(collection.deletedList->at(i)); + collection.deletedList->clear(); + for (unsigned int i = 0; i < collection.modifiedList->size() || Stopped(); i++) AnalyseEntry(collection.modifiedList->at(i)); collection.modifiedList->clear(); - for (unsigned int i = 0; i < collection.createdList->size() || Stopped(); - i++) - AnalyseEntry(collection.createdList->at(i)); - collection.createdList->clear(); - for (unsigned int i = 0; i < collection.movedList->size() || Stopped(); i++) MoveEntry(collection.movedFromList->at(i), collection.movedList->at(i)); @@ -372,7 +371,7 @@ SwapEntryRefVector::SwapList() EntryRefVector* temp = fCurrentList; fCurrentList = fNextList; fNextList = temp; - return fCurrentList; + return temp; } @@ -400,7 +399,6 @@ VolumeWatcher::VolumeWatcher(const BVolume& volume) VolumeWatcher::~VolumeWatcher() { -printf("~VolumeWatcher()\n"); Stop(); thread_id threadId = fVolumeWorker->Thread(); fVolumeWorker->PostMessage(B_QUIT_REQUESTED); @@ -486,14 +484,12 @@ VolumeWatcher::AddAnalyser(FileAnalyser* analyser) if (!fVolumeWorker->AddAnalyser(analyser)) return false; - Lock(); - if (!fCatchUpManager.AddAnalyser(analyser)) { - Unlock(); + BAutolock _(this); + if (!fCatchUpManager.AddAnalyser(analyser)) return false; - } + if (fWatching) fCatchUpManager.CatchUp(); - Unlock(); return true; } @@ -505,9 +501,8 @@ VolumeWatcher::RemoveAnalyser(const BString& name) if (!fVolumeWorker->RemoveAnalyser(name)) return false; - Lock(); + BAutolock _(this); fCatchUpManager.RemoveAnalyser(name); - Unlock(); return true; } @@ -515,6 +510,7 @@ VolumeWatcher::RemoveAnalyser(const BString& name) void VolumeWatcher::GetSecureEntries(list_collection& collection) { + BAutolock _(this); collection.createdList = fCreatedList.SwapList(); collection.deletedList = fDeleteList.SwapList(); collection.modifiedList = fModifiedList.SwapList();