Mercurial > dovecot > core-2.2
changeset 18514:0b297bc94746
lib-fs: Added fs_ref() and fs_unref() for reference counting.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 04 May 2015 19:06:11 +0300 |
parents | 8c49fb6d789b |
children | 6403ccd2f5f9 |
files | src/lib-fs/fs-api-private.h src/lib-fs/fs-api.c src/lib-fs/fs-api.h |
diffstat | 3 files changed, 24 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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));
--- 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);