[asterisk-commits] file: branch file/bucket r395727 - in /team/file/bucket: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 30 07:13:31 CDT 2013
Author: file
Date: Tue Jul 30 07:13:29 2013
New Revision: 395727
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395727
Log:
Add module reference counting.
Modified:
team/file/bucket/include/asterisk/bucket.h
team/file/bucket/main/bucket.c
Modified: team/file/bucket/include/asterisk/bucket.h
URL: http://svnview.digium.com/svn/asterisk/team/file/bucket/include/asterisk/bucket.h?view=diff&rev=395727&r1=395726&r2=395727
==============================================================================
--- team/file/bucket/include/asterisk/bucket.h (original)
+++ team/file/bucket/include/asterisk/bucket.h Tue Jul 30 07:13:29 2013
@@ -109,8 +109,21 @@
* \retval 0 success
* \retval -1 failure
*/
-int ast_bucket_scheme_register(const char *name, struct ast_sorcery_wizard *bucket,
- struct ast_sorcery_wizard *file);
+#define ast_bucket_scheme_register(name, bucket, file) __ast_bucket_scheme_register(name, bucket, file, ast_module_info ? ast_module_info->self : NULL)
+
+/*!
+ * \brief Register support for a specific scheme
+ *
+ * \param name Name of the scheme, used to find based on scheme in URIs
+ * \param bucket Sorcery wizard used for buckets
+ * \param file Sorcery wizard used for files
+ * \param module The module which implements this scheme
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int __ast_bucket_scheme_register(const char *name, struct ast_sorcery_wizard *bucket,
+ struct ast_sorcery_wizard *file, struct ast_module *module);
/*!
* \brief Unregister support for a specific scheme
Modified: team/file/bucket/main/bucket.c
URL: http://svnview.digium.com/svn/asterisk/team/file/bucket/main/bucket.c?view=diff&rev=395727&r1=395726&r2=395727
==============================================================================
--- team/file/bucket/main/bucket.c (original)
+++ team/file/bucket/main/bucket.c Tue Jul 30 07:13:29 2013
@@ -39,6 +39,7 @@
#include "asterisk/strings.h"
#include "asterisk/json.h"
#include "asterisk/file.h"
+#include "asterisk/module.h"
/*! \brief Default scheme for when one is not specified */
#define DEFAULT_UNSPECIFIED_SCHEME "local"
@@ -67,6 +68,8 @@
struct ast_sorcery_wizard *bucket;
/*! \brief Wizard for files */
struct ast_sorcery_wizard *file;
+ /*! \brief Module which implements this scheme */
+ struct ast_module *module;
/*! \brief Name of the scheme */
char name[0];
};
@@ -113,15 +116,26 @@
return 0;
}
+/*! \brief Helper function which increases reference count of a module and returns it */
+static struct ast_module *module_ref(struct ast_module *module)
+{
+ ast_module_ref(module);
+ return module;
+}
+
/*! \brief Callback function for creating a bucket */
static int bucket_wizard_create(const struct ast_sorcery *sorcery, void *data, void *object)
{
struct ast_bucket *bucket = object;
- RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, bucket->scheme, OBJ_KEY), ao2_cleanup);
+ SCOPED_AO2RDLOCK(lock, schemes);
+ RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, bucket->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!scheme) {
return -1;
}
+
+ module = module_ref(scheme->module);
return scheme->bucket->create(sorcery, data, object);
}
@@ -131,7 +145,9 @@
const char *id)
{
char *uri, *uri_scheme, *uri_name;
+ SCOPED_AO2RDLOCK(lock, schemes);
RAII_VAR(struct bucket_scheme *, scheme, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!(uri = ast_strdupa(id))) {
return NULL;
@@ -142,10 +158,12 @@
return NULL;
}
- scheme = ao2_find(schemes, uri_scheme, OBJ_KEY);
+ scheme = ao2_find(schemes, uri_scheme, OBJ_KEY | OBJ_NOLOCK);
if (!scheme) {
return NULL;
}
+
+ module = module_ref(scheme->module);
return scheme->bucket->retrieve_id(sorcery, data, type, id);
}
@@ -154,11 +172,15 @@
static int bucket_wizard_delete(const struct ast_sorcery *sorcery, void *data, void *object)
{
struct ast_bucket *bucket = object;
- RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, bucket->scheme, OBJ_KEY), ao2_cleanup);
+ SCOPED_AO2RDLOCK(lock, schemes);
+ RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, bucket->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!scheme) {
return -1;
}
+
+ module = module_ref(scheme->module);
return scheme->bucket->delete(sorcery, data, object);
}
@@ -175,11 +197,15 @@
static int bucket_file_wizard_create(const struct ast_sorcery *sorcery, void *data, void *object)
{
struct ast_bucket_file *file = object;
- RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, file->scheme, OBJ_KEY), ao2_cleanup);
+ SCOPED_AO2RDLOCK(lock, schemes);
+ RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, file->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!scheme) {
return -1;
}
+
+ module = module_ref(scheme->module);
return scheme->file->create(sorcery, data, object);
}
@@ -189,7 +215,9 @@
const char *id)
{
char *uri, *uri_scheme, *uri_name;
+ SCOPED_AO2RDLOCK(lock, schemes);
RAII_VAR(struct bucket_scheme *, scheme, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!(uri = ast_strdupa(id))) {
return NULL;
@@ -200,10 +228,12 @@
return NULL;
}
- scheme = ao2_find(schemes, uri_scheme, OBJ_KEY);
+ scheme = ao2_find(schemes, uri_scheme, OBJ_KEY | OBJ_NOLOCK);
if (!scheme) {
return NULL;
}
+
+ module = module_ref(scheme->module);
return scheme->file->retrieve_id(sorcery, data, type, id);
}
@@ -212,11 +242,15 @@
static int bucket_file_wizard_update(const struct ast_sorcery *sorcery, void *data, void *object)
{
struct ast_bucket_file *file = object;
- RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, file->scheme, OBJ_KEY), ao2_cleanup);
+ SCOPED_AO2RDLOCK(lock, schemes);
+ RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, file->scheme, OBJ_KEY | OBJ_NOLOCK), ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!scheme) {
return -1;
}
+
+ module = module_ref(scheme->module);
return scheme->file->update(sorcery, data, object);
}
@@ -225,11 +259,15 @@
static int bucket_file_wizard_delete(const struct ast_sorcery *sorcery, void *data, void *object)
{
struct ast_bucket_file *file = object;
+ SCOPED_AO2RDLOCK(lock, schemes);
RAII_VAR(struct bucket_scheme *, scheme, ao2_find(schemes, file->scheme, OBJ_KEY), ao2_cleanup);
+ RAII_VAR(struct ast_module *, module, NULL, ast_module_unref);
if (!scheme) {
return -1;
}
+
+ module = module_ref(scheme->module);
return scheme->file->delete(sorcery, data, object);
}
@@ -243,8 +281,8 @@
.delete = bucket_file_wizard_delete,
};
-int ast_bucket_scheme_register(const char *name, struct ast_sorcery_wizard *bucket,
- struct ast_sorcery_wizard *file)
+int __ast_bucket_scheme_register(const char *name, struct ast_sorcery_wizard *bucket,
+ struct ast_sorcery_wizard *file, struct ast_module *module)
{
SCOPED_AO2WRLOCK(lock, schemes);
struct bucket_scheme *scheme;
@@ -264,6 +302,7 @@
return -1;
}
+ scheme->module = module;
strcpy(scheme->name, name);
scheme->bucket = bucket;
scheme->file = file;
More information about the asterisk-commits
mailing list