dovecot-2.0: lib-storage: Added refcounting support for namespaces

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 26 21:11:19 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/edb8f06c7346
changeset: 11901:edb8f06c7346
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jul 26 19:10:52 2010 +0100
description:
lib-storage: Added refcounting support for namespaces

diffstat:

 src/lib-storage/mail-namespace.c |  28 +++++++++++++++++++++++++++-
 src/lib-storage/mail-namespace.h |   6 ++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diffs (97 lines):

diff -r 25a1c1739a63 -r edb8f06c7346 src/lib-storage/mail-namespace.c
--- a/src/lib-storage/mail-namespace.c	Mon Jul 26 19:10:21 2010 +0100
+++ b/src/lib-storage/mail-namespace.c	Mon Jul 26 19:10:52 2010 +0100
@@ -68,6 +68,7 @@
 	const char *driver, *error;
 
 	ns = i_new(struct mail_namespace, 1);
+	ns->refcount = 1;
 	ns->user = user;
 	if (strncmp(ns_set->type, "private", 7) == 0) {
 		ns->owner = user;
@@ -303,6 +304,7 @@
 
 	/* no namespaces defined, create a default one */
 	ns = i_new(struct mail_namespace, 1);
+	ns->refcount = 1;
 	ns->type = NAMESPACE_PRIVATE;
 	ns->flags = NAMESPACE_FLAG_INBOX_USER | NAMESPACE_FLAG_INBOX_ANY |
 		NAMESPACE_FLAG_LIST_PREFIX | NAMESPACE_FLAG_SUBSCRIPTIONS;
@@ -376,6 +378,7 @@
 	struct mail_namespace *ns;
 
 	ns = i_new(struct mail_namespace, 1);
+	ns->refcount = 1;
 	ns->user = user;
 	ns->owner = user;
 	ns->prefix = i_strdup("");
@@ -412,6 +415,28 @@
 		mail_storage_set_callbacks(ns->storage, callbacks, context);
 }
 
+void mail_namespace_ref(struct mail_namespace *ns)
+{
+	i_assert(ns->refcount > 0);
+
+	ns->refcount++;
+}
+
+void mail_namespace_unref(struct mail_namespace **_ns)
+{
+	struct mail_namespace *ns = *_ns;
+
+	i_assert(ns->refcount > 0);
+
+	*_ns = NULL;
+
+	if (--ns->refcount > 0)
+		return;
+
+	i_assert(ns->destroyed);
+	mail_namespace_free(ns);
+}
+
 void mail_namespace_destroy(struct mail_namespace *ns)
 {
 	struct mail_namespace **nsp;
@@ -423,8 +448,9 @@
 			break;
 		}
 	}
+	ns->destroyed = TRUE;
 
-	mail_namespace_free(ns);
+	mail_namespace_unref(&ns);
 }
 
 const char *mail_namespace_fix_sep(struct mail_namespace *ns, const char *name)
diff -r 25a1c1739a63 -r edb8f06c7346 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h	Mon Jul 26 19:10:21 2010 +0100
+++ b/src/lib-storage/mail-namespace.h	Mon Jul 26 19:10:52 2010 +0100
@@ -43,6 +43,7 @@
 struct mail_namespace {
 	/* Namespaces are sorted by their prefix length, "" comes first */
 	struct mail_namespace *next;
+	int refcount;
 
         enum namespace_type type;
 	char sep, real_sep, sep_str[3];
@@ -68,6 +69,8 @@
 
 	const struct mail_namespace_settings *set, *unexpanded_set;
 	const struct mail_storage_settings *mail_set;
+
+	unsigned int destroyed:1;
 };
 
 int mail_namespaces_init(struct mail_user *user, const char **error_r);
@@ -76,6 +79,9 @@
    for user's namespaces. */
 void mail_namespaces_deinit(struct mail_namespace **namespaces);
 
+void mail_namespace_ref(struct mail_namespace *ns);
+void mail_namespace_unref(struct mail_namespace **ns);
+
 /* Set storage callback functions to use in all namespaces. */
 void mail_namespaces_set_storage_callbacks(struct mail_namespace *namespaces,
 					   struct mail_storage_callbacks *callbacks,


More information about the dovecot-cvs mailing list