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:
@@ -10,6 +10,7 @@
|
|||||||
#include "MailProtocol.h"
|
#include "MailProtocol.h"
|
||||||
|
|
||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
|
#include <Locker.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
#include "MailSettings.h"
|
#include "MailSettings.h"
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ IMAPMailboxSync::Sync(IMAPStorage& storage, IMAPMailbox& mailbox)
|
|||||||
found = true;
|
found = true;
|
||||||
if (mailEntry.flags != minMessage.flags)
|
if (mailEntry.flags != minMessage.flags)
|
||||||
storage.SetFlags(mailEntry.uid, minMessage.flags);
|
storage.SetFlags(mailEntry.uid, minMessage.flags);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
@@ -109,6 +110,18 @@ ReadDirThreadFunction(void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IMAPStorage::IMAPStorage()
|
||||||
|
{
|
||||||
|
fLoadDatabaseLock = create_sem(1, "sync lock");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IMAPStorage::~IMAPStorage()
|
||||||
|
{
|
||||||
|
delete_sem(fLoadDatabaseLock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
IMAPStorage::SetTo(const char* dir)
|
IMAPStorage::SetTo(const char* dir)
|
||||||
{
|
{
|
||||||
@@ -129,10 +142,10 @@ IMAPStorage::StartReadDatabase()
|
|||||||
return id;
|
return id;
|
||||||
|
|
||||||
// will be unlocked from thread
|
// will be unlocked from thread
|
||||||
fLoadDatabaseLock.Lock();
|
acquire_sem(fLoadDatabaseLock);
|
||||||
status = resume_thread(id);
|
status = resume_thread(id);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
fLoadDatabaseLock.Unlock();
|
release_sem(fLoadDatabaseLock);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,9 +154,9 @@ status_t
|
|||||||
IMAPStorage::WaitForDatabaseReaded()
|
IMAPStorage::WaitForDatabaseReaded()
|
||||||
{
|
{
|
||||||
// just wait for thread
|
// just wait for thread
|
||||||
if (!fLoadDatabaseLock.Lock())
|
if (acquire_sem(fLoadDatabaseLock) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
fLoadDatabaseLock.Unlock();
|
release_sem(fLoadDatabaseLock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +453,7 @@ IMAPStorage::_ReadFilesThread()
|
|||||||
fMailEntryMap[entry.uid] = entry;
|
fMailEntryMap[entry.uid] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
fLoadDatabaseLock.Unlock();
|
release_sem(fLoadDatabaseLock);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Locker.h>
|
#include <kernel/OS.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
@@ -46,6 +46,9 @@ public:
|
|||||||
kBodyDownloaded = 0x02
|
kBodyDownloaded = 0x02
|
||||||
};
|
};
|
||||||
|
|
||||||
|
IMAPStorage();
|
||||||
|
~IMAPStorage();
|
||||||
|
|
||||||
void SetTo(const char* dir);
|
void SetTo(const char* dir);
|
||||||
|
|
||||||
status_t StartReadDatabase();
|
status_t StartReadDatabase();
|
||||||
@@ -88,7 +91,7 @@ private:
|
|||||||
|
|
||||||
BPath fMailboxPath;
|
BPath fMailboxPath;
|
||||||
|
|
||||||
BLocker fLoadDatabaseLock;
|
sem_id fLoadDatabaseLock;
|
||||||
MailEntryMap fMailEntryMap;
|
MailEntryMap fMailEntryMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user