- 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
This commit is contained in:
Clemens Zeidler
2010-10-28 15:11:02 +00:00
parent 20bf353a79
commit 4462ce0d83
4 changed files with 28 additions and 26 deletions
+1
View File
@@ -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 ;
@@ -20,7 +20,7 @@ class FileAnalyser;
class AnalyserDispatcher : public BLooper {
public:
AnalyserDispatcher();
AnalyserDispatcher(const char* name);
~AnalyserDispatcher();
void Stop();
+6 -1
View File
@@ -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);
+20 -24
View File
@@ -10,6 +10,7 @@
#include <sys/stat.h>
#include <Autolock.h>
#include <Directory.h>
#include <NodeMonitor.h>
#include <Path.h>
@@ -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();