003 File Manager
Current Path:
/usr/src/contrib/subversion/subversion/libsvn_subr
usr
/
src
/
contrib
/
subversion
/
subversion
/
libsvn_subr
/
📁
..
📄
adler32.c
(3.16 KB)
📄
atomic.c
(7.23 KB)
📄
auth.c
(32.4 KB)
📄
auth.h
(6.1 KB)
📄
base64.c
(19.18 KB)
📄
bit_array.c
(6.26 KB)
📄
cache-inprocess.c
(21.2 KB)
📄
cache-membuffer.c
(116.43 KB)
📄
cache-memcache.c
(17.35 KB)
📄
cache-null.c
(4.35 KB)
📄
cache.c
(10.22 KB)
📄
cache.h
(4.03 KB)
📄
cache_config.c
(6.01 KB)
📄
checksum.c
(24.17 KB)
📄
checksum.h
(2.32 KB)
📄
cmdline.c
(58.99 KB)
📄
compat.c
(5.28 KB)
📄
compress_lz4.c
(4.51 KB)
📄
compress_zlib.c
(6.85 KB)
📄
config.c
(39.66 KB)
📄
config_auth.c
(8.65 KB)
📄
config_file.c
(70.25 KB)
📄
config_impl.h
(6.15 KB)
📄
config_keys.inc
(2.65 KB)
📄
config_win.c
(9.61 KB)
📄
crypto.c
(25.19 KB)
📄
crypto.h
(5.43 KB)
📄
ctype.c
(13.81 KB)
📄
date.c
(12.86 KB)
📄
debug.c
(3.77 KB)
📄
deprecated.c
(64.3 KB)
📄
dirent_uri.c
(80.17 KB)
📄
dirent_uri.h
(1.43 KB)
📄
dso.c
(3.74 KB)
📄
encode.c
(2.69 KB)
📄
eol.c
(2.79 KB)
📄
error.c
(24.52 KB)
📄
errorcode.inc
(4.27 KB)
📄
fnv1a.c
(6.92 KB)
📄
fnv1a.h
(3.04 KB)
📄
genctype.py
(3.84 KB)
📄
gpg_agent.c
(22.29 KB)
📄
hash.c
(19.59 KB)
📄
internal_statements.h
(1.87 KB)
📄
internal_statements.sql
(1.58 KB)
📄
io.c
(182.6 KB)
📄
iter.c
(3.84 KB)
📄
libsvn_subr.pc.in
(515 B)
📄
lock.c
(1.69 KB)
📄
log.c
(14 KB)
📁
lz4
📄
macos_keychain.c
(9.7 KB)
📄
magic.c
(5.25 KB)
📄
md5.c
(1.8 KB)
📄
mergeinfo.c
(89.24 KB)
📄
mutex.c
(3.06 KB)
📄
nls.c
(3.06 KB)
📄
object_pool.c
(9.76 KB)
📄
opt.c
(39.34 KB)
📄
opt.h
(1.89 KB)
📄
packed_data.c
(33.43 KB)
📄
path.c
(35.99 KB)
📄
pool.c
(4.35 KB)
📄
pools.h
(1.45 KB)
📄
prefix_string.c
(10.65 KB)
📄
prompt.c
(28.82 KB)
📄
properties.c
(13.59 KB)
📄
quoprint.c
(8.96 KB)
📄
root_pools.c
(3.15 KB)
📄
simple_providers.c
(25.54 KB)
📄
skel.c
(23.04 KB)
📄
sorts.c
(15.9 KB)
📄
spillbuf.c
(19.78 KB)
📄
sqlite.c
(49.68 KB)
📄
sqlite3wrapper.c
(3.16 KB)
📄
ssl_client_cert_providers.c
(6.66 KB)
📄
ssl_client_cert_pw_providers.c
(18.93 KB)
📄
ssl_server_trust_providers.c
(7.77 KB)
📄
stream.c
(65.69 KB)
📄
string.c
(40.2 KB)
📄
subst.c
(67.57 KB)
📄
sysinfo.c
(43.67 KB)
📄
sysinfo.h
(2.58 KB)
📄
target.c
(11.58 KB)
📄
temp_serializer.c
(14.02 KB)
📄
time.c
(9.08 KB)
📄
token.c
(2.58 KB)
📄
types.c
(9.43 KB)
📄
user.c
(2.66 KB)
📄
username_providers.c
(9.2 KB)
📄
utf.c
(40.38 KB)
📁
utf8proc
📄
utf8proc.c
(20.71 KB)
📄
utf_validate.c
(13.3 KB)
📄
utf_width.c
(10.85 KB)
📄
validate.c
(3.35 KB)
📄
version.c
(9.89 KB)
📄
win32_crashrpt.c
(25.06 KB)
📄
win32_crashrpt.h
(1.35 KB)
📄
win32_crashrpt_dll.h
(4 KB)
📄
win32_crypto.c
(18.12 KB)
📄
win32_xlate.c
(7.3 KB)
📄
win32_xlate.h
(2.11 KB)
📄
x509.h
(3.75 KB)
📄
x509info.c
(9.53 KB)
📄
x509parse.c
(35.77 KB)
📄
xml.c
(20.01 KB)
Editing: object_pool.c
/* * object_pool.c : generic pool of reference-counted objects * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * ==================================================================== */ #include <assert.h> #include "svn_error.h" #include "svn_hash.h" #include "svn_pools.h" #include "private/svn_atomic.h" #include "private/svn_object_pool.h" #include "private/svn_subr_private.h" #include "private/svn_dep_compat.h" /* A reference counting wrapper around the user-provided object. */ typedef struct object_ref_t { /* reference to the parent container */ svn_object_pool__t *object_pool; /* identifies the bucket in OBJECT_POOL->OBJECTS in which this entry * belongs. */ svn_membuf_t key; /* User provided object. Usually a wrapper. */ void *object; /* private pool. This instance and its other members got allocated in it. * Will be destroyed when this instance is cleaned up. */ apr_pool_t *pool; /* Number of references to this data struct */ volatile svn_atomic_t ref_count; } object_ref_t; /* Core data structure. All access to it must be serialized using MUTEX. */ struct svn_object_pool__t { /* serialization object for all non-atomic data in this struct */ svn_mutex__t *mutex; /* object_ref_t.KEY -> object_ref_t* mapping. * * In shared object mode, there is at most one such entry per key and it * may or may not be in use. In exclusive mode, only unused references * will be put here and they form chains if there are multiple unused * instances for the key. */ apr_hash_t *objects; /* same as objects->count but allows for non-sync'ed access */ volatile svn_atomic_t object_count; /* Number of entries in OBJECTS with a reference count 0. Due to races, this may be *temporarily* off by one or more. Hence we must not strictly depend on it. */ volatile svn_atomic_t unused_count; /* the root pool owning this structure */ apr_pool_t *pool; }; /* Pool cleanup function for the whole object pool. */ static apr_status_t object_pool_cleanup(void *baton) { svn_object_pool__t *object_pool = baton; /* all entries must have been released up by now */ SVN_ERR_ASSERT_NO_RETURN( object_pool->object_count == object_pool->unused_count); return APR_SUCCESS; } /* Remove entries from OBJECTS in OBJECT_POOL that have a ref-count of 0. * * Requires external serialization on OBJECT_POOL. */ static void remove_unused_objects(svn_object_pool__t *object_pool) { apr_pool_t *subpool = svn_pool_create(object_pool->pool); /* process all hash buckets */ apr_hash_index_t *hi; for (hi = apr_hash_first(subpool, object_pool->objects); hi != NULL; hi = apr_hash_next(hi)) { object_ref_t *object_ref = apr_hash_this_val(hi); /* note that we won't hand out new references while access to the hash is serialized */ if (svn_atomic_read(&object_ref->ref_count) == 0) { apr_hash_set(object_pool->objects, object_ref->key.data, object_ref->key.size, NULL); svn_atomic_dec(&object_pool->object_count); svn_atomic_dec(&object_pool->unused_count); svn_pool_destroy(object_ref->pool); } } svn_pool_destroy(subpool); } /* Cleanup function called when an object_ref_t gets released. */ static apr_status_t object_ref_cleanup(void *baton) { object_ref_t *object = baton; svn_object_pool__t *object_pool = object->object_pool; /* If we released the last reference to object, there is one more unused entry. Note that unused_count does not need to be always exact but only needs to become exact *eventually* (we use it to check whether we should remove unused objects every now and then). I.e. it must never drift off / get stuck but always reflect the true value once all threads left the racy sections. */ if (svn_atomic_dec(&object->ref_count) == 0) svn_atomic_inc(&object_pool->unused_count); return APR_SUCCESS; } /* Handle reference counting for the OBJECT_REF that the caller is about * to return. The reference will be released when POOL gets cleaned up. * * Requires external serialization on OBJECT_REF->OBJECT_POOL. */ static void add_object_ref(object_ref_t *object_ref, apr_pool_t *pool) { /* Update ref counter. Note that this is racy with object_ref_cleanup; see comment there. */ if (svn_atomic_inc(&object_ref->ref_count) == 0) svn_atomic_dec(&object_ref->object_pool->unused_count); /* Make sure the reference gets released automatically. Since POOL might be a parent pool of OBJECT_REF->OBJECT_POOL, to the reference counting update before destroing any of the pool hierarchy. */ apr_pool_pre_cleanup_register(pool, object_ref, object_ref_cleanup); } /* Actual implementation of svn_object_pool__lookup. * * Requires external serialization on OBJECT_POOL. */ static svn_error_t * lookup(void **object, svn_object_pool__t *object_pool, svn_membuf_t *key, apr_pool_t *result_pool) { object_ref_t *object_ref = apr_hash_get(object_pool->objects, key->data, key->size); if (object_ref) { *object = object_ref->object; add_object_ref(object_ref, result_pool); } else { *object = NULL; } return SVN_NO_ERROR; } /* Actual implementation of svn_object_pool__insert. * * Requires external serialization on OBJECT_POOL. */ static svn_error_t * insert(void **object, svn_object_pool__t *object_pool, const svn_membuf_t *key, 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) { /* 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(item_pool); } else { /* add new index entry */ object_ref = apr_pcalloc(item_pool, sizeof(*object_ref)); object_ref->object_pool = object_pool; object_ref->object = item; object_ref->pool = item_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); apr_hash_set(object_pool->objects, object_ref->key.data, object_ref->key.size, object_ref); svn_atomic_inc(&object_pool->object_count); /* the new entry is *not* in use yet. * add_object_ref will update counters again. */ svn_atomic_inc(&object_ref->object_pool->unused_count); } /* return a reference to the object we just added */ *object = object_ref->object; add_object_ref(object_ref, result_pool); /* limit memory usage */ if (svn_atomic_read(&object_pool->unused_count) * 2 > apr_hash_count(object_pool->objects) + 2) remove_unused_objects(object_pool); return SVN_NO_ERROR; } /* API implementation */ svn_error_t * svn_object_pool__create(svn_object_pool__t **object_pool, svn_boolean_t thread_safe, apr_pool_t *pool) { svn_object_pool__t *result; /* construct the object pool in our private ROOT_POOL to survive POOL * cleanup and to prevent threading issues with the allocator */ result = apr_pcalloc(pool, sizeof(*result)); SVN_ERR(svn_mutex__init(&result->mutex, thread_safe, pool)); result->pool = pool; result->objects = svn_hash__make(result->pool); /* make sure we clean up nicely. * We need two cleanup functions of which exactly one will be run * (disabling the respective other as the first step). If the owning * pool does not cleaned up / destroyed explicitly, it may live longer * than our allocator. So, we need do act upon cleanup requests from * either side - owning_pool and root_pool. */ apr_pool_cleanup_register(pool, result, object_pool_cleanup, apr_pool_cleanup_null); *object_pool = result; return SVN_NO_ERROR; } apr_pool_t * svn_object_pool__new_item_pool(svn_object_pool__t *object_pool) { return svn_pool_create(object_pool->pool); } svn_error_t * svn_object_pool__lookup(void **object, svn_object_pool__t *object_pool, svn_membuf_t *key, apr_pool_t *result_pool) { *object = NULL; SVN_MUTEX__WITH_LOCK(object_pool->mutex, lookup(object, object_pool, key, result_pool)); return SVN_NO_ERROR; } svn_error_t * svn_object_pool__insert(void **object, svn_object_pool__t *object_pool, const svn_membuf_t *key, 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, item, item_pool, result_pool)); return SVN_NO_ERROR; }
Upload File
Create Folder