aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2002-12-09 08:28:06 +0800
committerMichael Zucci <zucchi@src.gnome.org>2002-12-09 08:28:06 +0800
commit24b06cb2a4030282763c8f60ba3b0b8b806d15d3 (patch)
tree44b57fbee23cb93c7b1e0d26aa2aac5eb360ee5f /camel/providers
parentc43c83145ab56f5422665f8a9c8468033064ce95 (diff)
downloadgsoc2013-evolution-24b06cb2a4030282763c8f60ba3b0b8b806d15d3.tar.gz
gsoc2013-evolution-24b06cb2a4030282763c8f60ba3b0b8b806d15d3.tar.zst
gsoc2013-evolution-24b06cb2a4030282763c8f60ba3b0b8b806d15d3.zip
Use a bag instead of a hashtable to track the cache streams.
2002-12-07 Not Zed <NotZed@Ximian.com> * camel-data-cache.c (data_cache_init): Use a bag instead of a hashtable to track the cache streams. (data_cache_finalise): Same. (free_busy): No longer needed. (data_cache_expire): use bag instead of hashtable. (stream_finalised): No longer required. (camel_data_cache_add): objectbagise (camel_data_cache_get): " (camel_data_cache_remove): " (data_cache_path): Set the now expired date before running expiry, so it plays better with multiple threads. Still a couple of harmless races. 2002-12-06 Not Zed <NotZed@Ximian.com> * providers/local/camel-spool-store.c (scan_dir): folders -> object bag. (get_folder_info_mbox): folders -> object bag. * providers/local/camel-mh-store.c (folder_info_new): folders -> object bag. * providers/local/camel-maildir-store.c (scan_dir): folders -> object bag. * providers/local/camel-local-store.c (rename_folder): folders -> object bag. * camel-private.h (CamelStorePrivate): Remove 'cache' lock, handled by the objectbag. * providers/imap/camel-imap-store.c (copy_folder): Removed. (imap_store_refresh_folders): folders -> object bag. (get_folder_counts): folders -> object bag. * camel-vee-store.c (vee_get_folder): changes for folders objectbag. (vee_get_folder_info): Change to use folders objectbag. Also, dont refresh the base folder if we're in FAST mode. (build_info): Removed, no longer needed. (vee_rename_folder): Fixed for folders objectbag. * camel-store.c (camel_store_init): init the folders objectbag. (camel_store_finalize): Destroy the folders object bag. (folder_matches): (folder_finalize): Removed, now handled implicitly by the objectbag. (camel_store_get_folder): object bag changes. (camel_store_delete_folder): " (get_subfolders): Removed, now handled without a callback. (camel_store_rename_folder): Changed to use object bag of folders. (trash_add_folder): Removed. (init_trash): use folders object bag. (copy_folder_cache): (sync_folder): Removed, no longer needed. Weird arsed code anyway. (store_sync): Use folder object bag instead of hashtable. (camel_store_unsubscribe_folder): " (camel_store_init): remove cache_lock init, no longer used. (camel_store_finalize): Same for cleanup. 2002-12-05 Not Zed <NotZed@Ximian.com> * camel-store.h (struct _CamelStore): change folders from a hashtable into a CamelObjectBag. * camel-object.c (camel_object_ref): Use type_lock instead of class lock for ref counting. (camel_object_unref): Use type_lock instead of class lock for unref. (camel_object_unref): If the object is 'bagged', then also look hooks, and remove it from any bags. (camel_object_bag_new): (camel_object_bag_destroy): (camel_object_bag_add): (camel_object_bag_get): (camel_object_bag_remove_unlocked): (camel_object_bag_list): (camel_object_bag_abort): (camel_object_bag_remove): New functions to implement a utility object which can manage a 'bag' of weakly ref'd children in an atomic & threadsafe way. svn path=/trunk/; revision=19056
Diffstat (limited to 'camel/providers')
-rw-r--r--camel/providers/imap/camel-imap-store.c43
-rw-r--r--camel/providers/local/camel-local-store.c14
-rw-r--r--camel/providers/local/camel-maildir-store.c9
-rw-r--r--camel/providers/local/camel-mh-store.c5
-rw-r--r--camel/providers/local/camel-spool-store.c29
5 files changed, 42 insertions, 58 deletions
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 0fba62fe36..01a9dcc79f 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -906,8 +906,8 @@ imap_forget_folder (CamelImapStore *imap_store, const char *folder_name, CamelEx
if (cache)
camel_imap_message_cache_clear (cache);
- camel_object_unref (CAMEL_OBJECT (cache));
- camel_object_unref (CAMEL_OBJECT (summary));
+ camel_object_unref (cache);
+ camel_object_unref (summary);
unlink (summary_file);
g_free (summary_file);
@@ -951,13 +951,6 @@ imap_check_folder_still_extant (CamelImapStore *imap_store, const char *full_nam
return TRUE;
}
-static void
-copy_folder(char *key, CamelFolder *folder, GPtrArray *out)
-{
- g_ptr_array_add(out, folder);
- camel_object_ref((CamelObject *)folder);
-}
-
/* This is a little 'hack' to avoid the deadlock conditions that would otherwise
ensue when calling camel_folder_refresh_info from inside a lock */
/* NB: on second thougts this is probably not entirely safe, but it'll do for now */
@@ -972,10 +965,7 @@ imap_store_refresh_folders (CamelImapStore *store, CamelException *ex)
GPtrArray *folders;
int i;
- folders = g_ptr_array_new();
- CAMEL_STORE_LOCK(store, cache_lock);
- g_hash_table_foreach (CAMEL_STORE (store)->folders, (GHFunc)copy_folder, folders);
- CAMEL_STORE_UNLOCK(store, cache_lock);
+ folders = camel_object_bag_list(CAMEL_STORE (store)->folders);
for (i = 0; i <folders->len; i++) {
CamelFolder *folder = folders->pdata[i];
@@ -992,12 +982,12 @@ imap_store_refresh_folders (CamelImapStore *store, CamelException *ex)
* after being offline */
namedup = g_strdup (folder->full_name);
- camel_object_unref((CamelObject *)folder);
+ camel_object_unref(folder);
imap_folder_effectively_unsubscribed (store, namedup, ex);
imap_forget_folder (store, namedup, ex);
g_free (namedup);
} else
- camel_object_unref((CamelObject *)folder);
+ camel_object_unref(folder);
}
g_ptr_array_free (folders, TRUE);
@@ -2198,30 +2188,25 @@ get_folder_counts(CamelImapStore *imap_store, CamelFolderInfo *fi, CamelExceptio
} else {
fi->unread_message_count = get_folder_status (imap_store, fi->full_name, "UNSEEN");
/* if we have this folder open, and the unread count has changed, update */
- CAMEL_STORE_LOCK(imap_store, cache_lock);
- folder = g_hash_table_lookup(CAMEL_STORE(imap_store)->folders, fi->full_name);
- if (folder && fi->unread_message_count != camel_folder_get_unread_message_count(folder))
- camel_object_ref(folder);
- else
- folder = NULL;
- CAMEL_STORE_UNLOCK(imap_store, cache_lock);
- if (folder) {
+ folder = camel_object_bag_get(CAMEL_STORE(imap_store)->folders, fi->full_name);
+ if (folder && fi->unread_message_count != camel_folder_get_unread_message_count(folder)) {
CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(folder))->refresh_info(folder, ex);
fi->unread_message_count = camel_folder_get_unread_message_count(folder);
- camel_object_unref(folder);
}
+ if (folder)
+ camel_object_unref(folder);
+
}
CAMEL_SERVICE_UNLOCK (imap_store, connect_lock);
} else {
/* since its cheap, get it if they're open */
- CAMEL_STORE_LOCK(imap_store, cache_lock);
- folder = g_hash_table_lookup(CAMEL_STORE(imap_store)->folders, fi->full_name);
- if (folder)
+ folder = camel_object_bag_get(CAMEL_STORE(imap_store)->folders, fi->full_name);
+ if (folder) {
fi->unread_message_count = camel_folder_get_unread_message_count(folder);
- else
+ camel_object_unref(folder);
+ } else
fi->unread_message_count = -1;
- CAMEL_STORE_UNLOCK(imap_store, cache_lock);
}
if (fi->child)
diff --git a/camel/providers/local/camel-local-store.c b/camel/providers/local/camel-local-store.c
index b325df769a..a794b778f3 100644
--- a/camel/providers/local/camel-local-store.c
+++ b/camel/providers/local/camel-local-store.c
@@ -319,7 +319,7 @@ static void
rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex)
{
char *path = CAMEL_LOCAL_STORE (store)->toplevel_dir;
- CamelLocalFolder *folder;
+ CamelLocalFolder *folder = NULL;
char *newibex = g_strdup_printf("%s%s.ibex", path, new);
char *oldibex = g_strdup_printf("%s%s.ibex", path, old);
@@ -327,8 +327,7 @@ rename_folder(CamelStore *store, const char *old, const char *new, CamelExceptio
d(printf("local rename folder '%s' '%s'\n", old, new));
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, old);
+ folder = camel_object_bag_get(store->folders, old);
if (folder && folder->index) {
if (camel_index_rename(folder->index, newibex) == -1)
goto ibex_failed;
@@ -344,11 +343,12 @@ rename_folder(CamelStore *store, const char *old, const char *new, CamelExceptio
if (xrename(old, new, path, "", FALSE, ex))
goto base_failed;
- CAMEL_STORE_UNLOCK(store, cache_lock);
-
g_free(newibex);
g_free(oldibex);
+ if (folder)
+ camel_object_unref(folder);
+
return;
base_failed:
@@ -365,9 +365,11 @@ ibex_failed:
_("Could not rename '%s': %s"),
old, g_strerror (errno));
- CAMEL_STORE_UNLOCK(store, cache_lock);
g_free(newibex);
g_free(oldibex);
+
+ if (folder)
+ camel_object_unref(folder);
}
/* default implementation, only delete metadata */
diff --git a/camel/providers/local/camel-maildir-store.c b/camel/providers/local/camel-maildir-store.c
index 8e6cc1ee9d..c84c37158c 100644
--- a/camel/providers/local/camel-maildir-store.c
+++ b/camel/providers/local/camel-maildir-store.c
@@ -273,16 +273,15 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
base = path;
/* if we have this folder open, get the real unread count */
- unread = -1;
-
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, path);
+ folder = camel_object_bag_get(store->folders, path);
if (folder) {
if ((flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
camel_folder_refresh_info(folder, NULL);
unread = camel_folder_get_unread_message_count(folder);
+ camel_object_unref(folder);
+ } else {
+ unread = -1;
}
- CAMEL_STORE_UNLOCK(store, cache_lock);
/* if we dont have a folder, then scan the directory and get the unread
count from there, which is reasonably cheap (on decent filesystem) */
diff --git a/camel/providers/local/camel-mh-store.c b/camel/providers/local/camel-mh-store.c
index 6c442d335b..7fe68ef4b5 100644
--- a/camel/providers/local/camel-mh-store.c
+++ b/camel/providers/local/camel-mh-store.c
@@ -300,14 +300,13 @@ static CamelFolderInfo *folder_info_new(CamelStore *store, const char *root, con
fi->unread_message_count = 0;
/* check unread count if open */
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, path);
+ folder = camel_object_bag_get(store->folders, path);
if (folder) {
if ((((CamelMhStore *)store)->flags & CAMEL_STORE_FOLDER_INFO_FAST) == 0)
camel_folder_refresh_info(folder, NULL);
fi->unread_message_count = camel_folder_get_unread_message_count(folder);
+ camel_object_unref(folder);
}
- CAMEL_STORE_UNLOCK(store, cache_lock);
/* We could: if we have no folder, and FAST isn't specified, perform a full
scan of all messages for their status flags. But its probably not worth
diff --git a/camel/providers/local/camel-spool-store.c b/camel/providers/local/camel-spool-store.c
index f2cbdd1e55..9419d897a8 100644
--- a/camel/providers/local/camel-spool-store.c
+++ b/camel/providers/local/camel-spool-store.c
@@ -285,13 +285,13 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
} else if (S_ISREG(st.st_mode)) {
/* incase we start scanning from a file. messy duplication :-/ */
if (path) {
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, path);
- if (folder)
+ folder = camel_object_bag_get(store->folders, path);
+ if (folder) {
+ /* should this refresh if ! FAST? */
unread = camel_folder_get_unread_message_count(folder);
- else
+ camel_object_unref(folder);
+ } else
unread = -1;
- CAMEL_STORE_UNLOCK(store, cache_lock);
tmp = strrchr(path, '/');
if (tmp)
tmp++;
@@ -346,13 +346,13 @@ static int scan_dir(CamelStore *store, GHashTable *visited, char *root, const ch
if (S_ISREG(st.st_mode)) {
/* first, see if we already have it open */
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, fname);
- if (folder)
+ folder = camel_object_bag_get(store->folders, path);
+ if (folder) {
+ /* should this refresh if ! FAST? */
unread = camel_folder_get_unread_message_count(folder);
- else
+ camel_object_unref(folder);
+ } else
unread = -1;
- CAMEL_STORE_UNLOCK(store, cache_lock);
/* no? check its content to see if its a folder or not */
if (folder == NULL) {
@@ -457,13 +457,12 @@ get_folder_info_mbox(CamelStore *store, const char *top, guint32 flags, CamelExc
fi->name = g_strdup("INBOX");
fi->url = g_strdup_printf("%s:%s#%s", service->url->protocol, service->url->path, fi->name);
- CAMEL_STORE_LOCK(store, cache_lock);
- folder = g_hash_table_lookup(store->folders, fi->full_name);
- if (folder)
+ folder = camel_object_bag_get(store->folders, fi->full_name);
+ if (folder) {
fi->unread_message_count = camel_folder_get_unread_message_count(folder);
- else
+ camel_object_unref(folder);
+ } else
fi->unread_message_count = -1;
- CAMEL_STORE_UNLOCK(store, cache_lock);
camel_folder_info_build_path(fi, '/');
}