To sync the mailbox a thread is started which reads the local files while in the parent thread the id list from the server is fetched. To sync both threads a BLocker was used. BLocker does not block when locked from the same thread so use a semaphore now.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40412 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler 2011-02-09 22:11:50 +00:00
parent 9b533c387c
commit 81d1d0e504
3 changed files with 24 additions and 7 deletions

View File

@ -10,6 +10,7 @@
#include "MailProtocol.h"
#include <Handler.h>
#include <Locker.h>
#include <Message.h>
#include "MailSettings.h"

View File

@ -40,6 +40,7 @@ IMAPMailboxSync::Sync(IMAPStorage& storage, IMAPMailbox& mailbox)
found = true;
if (mailEntry.flags != minMessage.flags)
storage.SetFlags(mailEntry.uid, minMessage.flags);
break;
}
}
if (!found)
@ -109,6 +110,18 @@ ReadDirThreadFunction(void *data)
}
IMAPStorage::IMAPStorage()
{
fLoadDatabaseLock = create_sem(1, "sync lock");
}
IMAPStorage::~IMAPStorage()
{
delete_sem(fLoadDatabaseLock);
}
void
IMAPStorage::SetTo(const char* dir)
{
@ -129,10 +142,10 @@ IMAPStorage::StartReadDatabase()
return id;
// will be unlocked from thread
fLoadDatabaseLock.Lock();
acquire_sem(fLoadDatabaseLock);
status = resume_thread(id);
if (status != B_OK)
fLoadDatabaseLock.Unlock();
release_sem(fLoadDatabaseLock);
return status;
}
@ -141,9 +154,9 @@ status_t
IMAPStorage::WaitForDatabaseReaded()
{
// just wait for thread
if (!fLoadDatabaseLock.Lock())
if (acquire_sem(fLoadDatabaseLock) != B_OK)
return B_ERROR;
fLoadDatabaseLock.Unlock();
release_sem(fLoadDatabaseLock);
return B_OK;
}
@ -440,7 +453,7 @@ IMAPStorage::_ReadFilesThread()
fMailEntryMap[entry.uid] = entry;
}
fLoadDatabaseLock.Unlock();
release_sem(fLoadDatabaseLock);
return B_OK;
}

View File

@ -12,7 +12,7 @@
#include <string.h>
#include <File.h>
#include <Locker.h>
#include <kernel/OS.h>
#include <Path.h>
#include <String.h>
@ -46,6 +46,9 @@ public:
kBodyDownloaded = 0x02
};
IMAPStorage();
~IMAPStorage();
void SetTo(const char* dir);
status_t StartReadDatabase();
@ -88,7 +91,7 @@ private:
BPath fMailboxPath;
BLocker fLoadDatabaseLock;
sem_id fLoadDatabaseLock;
MailEntryMap fMailEntryMap;
};