You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2016/11/16 19:23:03 UTC
svn commit: r1770041 - in /subversion/branches/authzperf/subversion:
include/private/svn_object_pool.h libsvn_repos/authz_pool.c
libsvn_repos/config_pool.c libsvn_subr/object_pool.c
Author: stefan2
Date: Wed Nov 16 19:23:03 2016
New Revision: 1770041
URL: http://svn.apache.org/viewvc?rev=1770041&view=rev
Log:
On the authzperf branch:
Simplify the svn_object_pool__t API. There is no need for wrapper
objects anymore. Hence, drop the getter / setter feature.
Once at it, reduce the API and update the docstrings.
* subversion/include/private/svn_object_pool.h
(svn_object_pool__getter_t,
svn_object_pool__setter_t): These are no longer needed.
(svn_object_pool__create): Remove GETTER and SETTER support and clarify
the pool usage and object lifetime policy.
(svn_object_pool__new_wrapper_pool): Rename to ...
(svn_object_pool__new_item_pool): ... this.
(svn_object_pool__mutex,
svn_object_pool__count): No longer called.
(svn_object_pool__lookup,
svn_object_pool__insert): Remove wrapper object support.
* subversion/libsvn_subr/object_pool.c
(object_ref_t): We always store the OBJECT directly now.
(svn_object_pool__t,
lookup,
insert): Remove GETTER and SETTER support.
(default_getter,
default_setter): Drop.
(svn_object_pool__create): Remove GETTER and SETTER support.
(svn_object_pool__new_wrapper_pool): Rename to ...
(svn_object_pool__new_item_pool): ... this.
(svn_object_pool__mutex,
svn_object_pool__count): Drop.
(svn_object_pool__lookup): Update caller.
(svn_object_pool__insert): Same. Make sure to initialize the return value
just like *__lookup does.
* subversion/libsvn_repos/authz_pool.c
(getter): Drop.
(svn_repos__authz_pool_create): Adapt to API change. This code is currently
unused and will soon be rewritten.
* subversion/libsvn_repos/config_pool.c
(auto_parse,
find_repos_config,
svn_repos__config_pool_create): Update API callers.
Modified:
subversion/branches/authzperf/subversion/include/private/svn_object_pool.h
subversion/branches/authzperf/subversion/libsvn_repos/authz_pool.c
subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c
subversion/branches/authzperf/subversion/libsvn_subr/object_pool.c
Modified: subversion/branches/authzperf/subversion/include/private/svn_object_pool.h
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/include/private/svn_object_pool.h?rev=1770041&r1=1770040&r2=1770041&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/include/private/svn_object_pool.h (original)
+++ subversion/branches/authzperf/subversion/include/private/svn_object_pool.h Wed Nov 16 19:23:03 2016
@@ -65,80 +65,46 @@
/* The opaque object container type. */
typedef struct svn_object_pool__t svn_object_pool__t;
-/* Extract the actual object from the WRAPPER using optional information
- * from BATON (provided through #svn_object_pool__lookup) and return it.
- * The result will be used with POOL and must remain valid throughout
- * POOL's lifetime.
- *
- * It is legal to return a copy, allocated in POOL, of the wrapped object.
- */
-typedef void * (* svn_object_pool__getter_t)(void *wrapper,
- void *baton,
- apr_pool_t *pool);
-
-/* Copy the information from the SOURCE object wrapper into the already
- * existing *TARGET object wrapper using POOL for allocations and BATON
- * for optional context (provided through #svn_object_pool__insert).
- */
-typedef svn_error_t * (* svn_object_pool__setter_t)(void **target,
- void *source,
- void *baton,
- apr_pool_t *pool);
-
/* Create a new object pool in POOL and return it in *OBJECT_POOL.
- * Objects will be extracted using GETTER and updated using SETTER. Either
- * one (or both) may be NULL and the default implementation assumes that
- * wrapper == object and updating is a no-op.
+ * Objects are reference-counted and stored as opaque pointers. Each
+ * must be allocated in a separate pool ceated by
+ * svn_object_pool__new_item_pool. Unused objects get destroyed at
+ * the object pool's discretion.
*
* If THREAD_SAFE is not set, neither the object pool nor the object
* references returned from it may be accessed from multiple threads.
*
* It is not legal to call any API on the object pool after POOL got
- * cleared or destroyed. However, existing object references handed out
- * from the object pool remain valid and will keep the internal pool data
- * structures alive for as long as such object references exist.
+ * cleared or destroyed nor to use any objects from this object pool.
*/
svn_error_t *
svn_object_pool__create(svn_object_pool__t **object_pool,
- svn_object_pool__getter_t getter,
- svn_object_pool__setter_t setter,
svn_boolean_t thread_safe,
apr_pool_t *pool);
-/* Return the root pool containing the OBJECT_POOL and all sub-structures.
+/* Return a pool to allocate the new object.
*/
apr_pool_t *
-svn_object_pool__new_wrapper_pool(svn_object_pool__t *object_pool);
-
-/* Return the mutex used to serialize all OBJECT_POOL access.
- */
-svn_mutex__t *
-svn_object_pool__mutex(svn_object_pool__t *object_pool);
-
-/* Return the number of object instances (used or unused) in OBJECT_POOL.
- */
-unsigned
-svn_object_pool__count(svn_object_pool__t *object_pool);
+svn_object_pool__new_item_pool(svn_object_pool__t *object_pool);
/* In OBJECT_POOL, look for an available object by KEY and return a
* reference to it in *OBJECT. If none can be found, *OBJECT will be NULL.
- * BATON will be passed to OBJECT_POOL's getter function. The reference
- * will be returned when *RESULT_POOL gets cleaned up or destroyed.
+ *
+ * The reference will be returned when *RESULT_POOL and may be destroyed
+ * or recycled by OBJECT_POOL.
*/
svn_error_t *
svn_object_pool__lookup(void **object,
svn_object_pool__t *object_pool,
svn_membuf_t *key,
- void *baton,
apr_pool_t *result_pool);
-/* Store the wrapped object WRAPPER under KEY in OBJECT_POOL and return
- * a reference to the object in *OBJECT (just like lookup).
+/* Store the object ITEM under KEY in OBJECT_POOL and return a reference
+ * to the object in *OBJECT (just like lookup).
*
- * The object must have been created in WRAPPER_POOL and the latter must
- * be a sub-pool of OBJECT_POOL's root POOL (see #svn_object_pool__pool).
+ * The object must have been created in ITEM_POOL and the latter must
+ * have been created by svn_object_pool__new_item_pool.
*
- * BATON will be passed to OBJECT_POOL's setter and getter functions.
* The reference will be returned when *RESULT_POOL gets cleaned up or
* destroyed.
*/
@@ -146,9 +112,8 @@ svn_error_t *
svn_object_pool__insert(void **object,
svn_object_pool__t *object_pool,
const svn_membuf_t *key,
- void *wrapper,
- void *baton,
- apr_pool_t *wrapper_pool,
+ void *item,
+ apr_pool_t *item_pool,
apr_pool_t *result_pool);
#endif /* SVN_OBJECT_POOL_H */
Modified: subversion/branches/authzperf/subversion/libsvn_repos/authz_pool.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_repos/authz_pool.c?rev=1770041&r1=1770040&r2=1770041&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_repos/authz_pool.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_repos/authz_pool.c Wed Nov 16 19:23:03 2016
@@ -100,16 +100,6 @@ construct_key(svn_membuf_t *authz_key,
return result;
}
-/* Implement svn_object_pool__getter_t on authz_object_t structures.
- */
-static void *
-getter(void *object,
- void *baton,
- apr_pool_t *pool)
-{
- return ((authz_object_t *)object)->authz;
-}
-
/* API implementation */
svn_error_t *
@@ -122,8 +112,7 @@ svn_repos__authz_pool_create(svn_repos__
svn_object_pool__t *object_pool;
/* there is no setter as we don't need to update existing authz */
- SVN_ERR(svn_object_pool__create(&object_pool, getter, NULL, thread_safe,
- pool));
+ SVN_ERR(svn_object_pool__create(&object_pool, thread_safe, pool));
result = apr_pcalloc(pool, sizeof(*result));
result->object_pool = object_pool;
Modified: subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c?rev=1770041&r1=1770040&r2=1770041&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_repos/config_pool.c Wed Nov 16 19:23:03 2016
@@ -78,12 +78,12 @@ auto_parse(svn_config_t **cfg,
/* return reference to suitable config object if that already exists */
*key = checksum_as_key(checksum, result_pool);
SVN_ERR(svn_object_pool__lookup((void **)cfg, config_pool,
- *key, NULL, result_pool));
+ *key, result_pool));
if (*cfg)
return SVN_NO_ERROR;
/* create a pool for the new config object and parse the data into it */
- cfg_pool = svn_object_pool__new_wrapper_pool(config_pool);
+ cfg_pool = svn_object_pool__new_item_pool(config_pool);
SVN_ERR(svn_config_parse(&config,
svn_stream_from_stringbuf(contents, scratch_pool),
@@ -94,7 +94,7 @@ auto_parse(svn_config_t **cfg,
/* add config in pool, handle loads races and return the right config */
SVN_ERR(svn_object_pool__insert((void **)cfg, config_pool, *key, config,
- NULL, cfg_pool, result_pool));
+ cfg_pool, result_pool));
return SVN_NO_ERROR;
}
@@ -171,7 +171,7 @@ find_repos_config(svn_config_t **cfg,
{
*key = checksum_as_key(checksum, scratch_pool);
SVN_ERR(svn_object_pool__lookup((void **)cfg, config_pool,
- *key, NULL, result_pool));
+ *key, result_pool));
}
/* not parsed, yet? */
@@ -204,7 +204,7 @@ svn_repos__config_pool_create(svn_repos_
svn_boolean_t thread_safe,
apr_pool_t *pool)
{
- return svn_error_trace(svn_object_pool__create(config_pool, NULL, NULL,
+ return svn_error_trace(svn_object_pool__create(config_pool,
thread_safe, pool));
}
Modified: subversion/branches/authzperf/subversion/libsvn_subr/object_pool.c
URL: http://svn.apache.org/viewvc/subversion/branches/authzperf/subversion/libsvn_subr/object_pool.c?rev=1770041&r1=1770040&r2=1770041&view=diff
==============================================================================
--- subversion/branches/authzperf/subversion/libsvn_subr/object_pool.c (original)
+++ subversion/branches/authzperf/subversion/libsvn_subr/object_pool.c Wed Nov 16 19:23:03 2016
@@ -1,5 +1,5 @@
/*
- * config_pool.c : pool of configuration objects
+ * object_pool.c : generic pool of reference-counted objects
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
@@ -49,7 +49,7 @@ typedef struct object_ref_t
svn_membuf_t key;
/* User provided object. Usually a wrapper. */
- void *wrapper;
+ void *object;
/* private pool. This instance and its other members got allocated in it.
* Will be destroyed when this instance is cleaned up. */
@@ -85,10 +85,6 @@ struct svn_object_pool__t
/* the root pool owning this structure */
apr_pool_t *pool;
-
- /* extractor and updater for the user object wrappers */
- svn_object_pool__getter_t getter;
- svn_object_pool__setter_t setter;
};
@@ -189,7 +185,6 @@ static svn_error_t *
lookup(void **object,
svn_object_pool__t *object_pool,
svn_membuf_t *key,
- void *baton,
apr_pool_t *result_pool)
{
object_ref_t *object_ref
@@ -197,7 +192,7 @@ lookup(void **object,
if (object_ref)
{
- *object = object_pool->getter(object_ref->wrapper, baton, result_pool);
+ *object = object_ref->object;
add_object_ref(object_ref, result_pool);
}
else
@@ -216,57 +211,28 @@ static svn_error_t *
insert(void **object,
svn_object_pool__t *object_pool,
const svn_membuf_t *key,
- void *wrapper,
- void *baton,
- apr_pool_t *wrapper_pool,
+ void *item,
+ apr_pool_t *item_pool,
apr_pool_t *result_pool)
{
object_ref_t *object_ref
= apr_hash_get(object_pool->objects, key->data, key->size);
if (object_ref)
{
- /* entry already exists (e.g. race condition) */
- svn_error_t *err = object_pool->setter(&object_ref->wrapper,
- wrapper, baton,
- object_ref->pool);
- if (err)
- {
- /* if we had an issue in the setter, then OBJECT_REF is in an
- * unknown state now. Keep it around for the current users
- * (i.e. don't clean the pool) but remove it from the list of
- * available ones.
- */
- apr_hash_set(object_pool->objects, key->data, key->size, NULL);
- svn_atomic_dec(&object_pool->object_count);
-
- /* for the unlikely case that the object got created _and_
- * already released since we last checked: */
- if (svn_atomic_read(&object_ref->ref_count) == 0)
- svn_atomic_dec(&object_pool->unused_count);
-
- /* cleanup the new data as well because it's not safe to use
- * either.
- */
- svn_pool_destroy(wrapper_pool);
-
- /* propagate error */
- return svn_error_trace(err);
- }
-
/* Destroy the new one and return a reference to the existing one
* because the existing one may already have references on it.
*/
- svn_pool_destroy(wrapper_pool);
+ svn_pool_destroy(item_pool);
}
else
{
/* add new index entry */
- object_ref = apr_pcalloc(wrapper_pool, sizeof(*object_ref));
+ object_ref = apr_pcalloc(item_pool, sizeof(*object_ref));
object_ref->object_pool = object_pool;
- object_ref->wrapper = wrapper;
- object_ref->pool = wrapper_pool;
+ object_ref->object = item;
+ object_ref->pool = item_pool;
- svn_membuf__create(&object_ref->key, key->size, wrapper_pool);
+ svn_membuf__create(&object_ref->key, key->size, item_pool);
object_ref->key.size = key->size;
memcpy(object_ref->key.data, key->data, key->size);
@@ -281,7 +247,7 @@ insert(void **object,
}
/* return a reference to the object we just added */
- *object = object_pool->getter(object_ref->wrapper, baton, result_pool);
+ *object = object_ref->object;
add_object_ref(object_ref, result_pool);
/* limit memory usage */
@@ -292,34 +258,11 @@ insert(void **object,
return SVN_NO_ERROR;
}
-/* Implement svn_object_pool__getter_t as no-op.
- */
-static void *
-default_getter(void *object,
- void *baton,
- apr_pool_t *pool)
-{
- return object;
-}
-
-/* Implement svn_object_pool__setter_t as no-op.
- */
-static svn_error_t *
-default_setter(void **target,
- void *source,
- void *baton,
- apr_pool_t *pool)
-{
- return SVN_NO_ERROR;
-}
-
/* API implementation */
svn_error_t *
svn_object_pool__create(svn_object_pool__t **object_pool,
- svn_object_pool__getter_t getter,
- svn_object_pool__setter_t setter,
svn_boolean_t thread_safe,
apr_pool_t *pool)
{
@@ -333,8 +276,6 @@ svn_object_pool__create(svn_object_pool_
result->pool = pool;
result->objects = svn_hash__make(result->pool);
- result->getter = getter ? getter : default_getter;
- result->setter = setter ? setter : default_setter;
/* make sure we clean up nicely.
* We need two cleanup functions of which exactly one will be run
@@ -351,33 +292,20 @@ svn_object_pool__create(svn_object_pool_
}
apr_pool_t *
-svn_object_pool__new_wrapper_pool(svn_object_pool__t *object_pool)
+svn_object_pool__new_item_pool(svn_object_pool__t *object_pool)
{
return svn_pool_create(object_pool->pool);
}
-svn_mutex__t *
-svn_object_pool__mutex(svn_object_pool__t *object_pool)
-{
- return object_pool->mutex;
-}
-
-unsigned
-svn_object_pool__count(svn_object_pool__t *object_pool)
-{
- return svn_atomic_read(&object_pool->object_count);
-}
-
svn_error_t *
svn_object_pool__lookup(void **object,
svn_object_pool__t *object_pool,
svn_membuf_t *key,
- void *baton,
apr_pool_t *result_pool)
{
*object = NULL;
SVN_MUTEX__WITH_LOCK(object_pool->mutex,
- lookup(object, object_pool, key, baton, result_pool));
+ lookup(object, object_pool, key, result_pool));
return SVN_NO_ERROR;
}
@@ -385,13 +313,13 @@ svn_error_t *
svn_object_pool__insert(void **object,
svn_object_pool__t *object_pool,
const svn_membuf_t *key,
- void *wrapper,
- void *baton,
- apr_pool_t *wrapper_pool,
+ void *item,
+ apr_pool_t *item_pool,
apr_pool_t *result_pool)
{
+ *object = NULL;
SVN_MUTEX__WITH_LOCK(object_pool->mutex,
- insert(object, object_pool, key, wrapper, baton,
- wrapper_pool, result_pool));
+ insert(object, object_pool, key, item,
+ item_pool, result_pool));
return SVN_NO_ERROR;
}