dovecot-2.2: lib-fs: Added fs_ref() and fs_unref() for reference...
dovecot at dovecot.org
dovecot at dovecot.org
Mon May 4 16:08:20 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/0b297bc94746
changeset: 18514:0b297bc94746
user: Timo Sirainen <tss at iki.fi>
date: Mon May 04 19:06:11 2015 +0300
description:
lib-fs: Added fs_ref() and fs_unref() for reference counting.
diffstat:
src/lib-fs/fs-api-private.h | 1 +
src/lib-fs/fs-api.c | 21 +++++++++++++++++++--
src/lib-fs/fs-api.h | 4 ++++
3 files changed, 24 insertions(+), 2 deletions(-)
diffs (72 lines):
diff -r 8c49fb6d789b -r 0b297bc94746 src/lib-fs/fs-api-private.h
--- a/src/lib-fs/fs-api-private.h Mon May 04 18:44:29 2015 +0300
+++ b/src/lib-fs/fs-api-private.h Mon May 04 19:06:11 2015 +0300
@@ -69,6 +69,7 @@
const char *name;
struct fs_vfuncs v;
char *temp_path_prefix;
+ int refcount;
char *username, *session_id;
diff -r 8c49fb6d789b -r 0b297bc94746 src/lib-fs/fs-api.c
--- a/src/lib-fs/fs-api.c Mon May 04 18:44:29 2015 +0300
+++ b/src/lib-fs/fs-api.c Mon May 04 19:06:11 2015 +0300
@@ -38,7 +38,7 @@
data stack. */
*error_r = t_strdup_printf("%s: %s", fs_class->name,
fs_last_error(fs));
- fs_deinit(&fs);
+ fs_unref(&fs);
return -1;
}
fs->username = i_strdup(set->username);
@@ -147,14 +147,31 @@
return 0;
}
-void fs_deinit(struct fs **_fs)
+void fs_deinit(struct fs **fs)
+{
+ fs_unref(fs);
+}
+
+void fs_ref(struct fs *fs)
+{
+ i_assert(fs->refcount > 0);
+
+ fs->refcount++;
+}
+
+void fs_unref(struct fs **_fs)
{
struct fs *fs = *_fs;
string_t *last_error = fs->last_error;
struct array module_contexts_arr = fs->module_contexts.arr;
+ i_assert(fs->refcount > 0);
+
*_fs = NULL;
+ if (--fs->refcount > 0)
+ return;
+
if (fs->files_open_count > 0) {
i_panic("fs-%s: %u files still open (first = %s)",
fs->name, fs->files_open_count, fs_file_path(fs->files));
diff -r 8c49fb6d789b -r 0b297bc94746 src/lib-fs/fs-api.h
--- a/src/lib-fs/fs-api.h Mon May 04 18:44:29 2015 +0300
+++ b/src/lib-fs/fs-api.h Mon May 04 19:06:11 2015 +0300
@@ -166,8 +166,12 @@
int fs_init(const char *driver, const char *args,
const struct fs_settings *set,
struct fs **fs_r, const char **error_r);
+/* same as fs_unref() */
void fs_deinit(struct fs **fs);
+void fs_ref(struct fs *fs);
+void fs_unref(struct fs **fs);
+
/* Returns the parent filesystem (if this is a wrapper fs) or NULL if
there's no parent. */
struct fs *fs_get_parent(struct fs *fs);
More information about the dovecot-cvs
mailing list