FreeBSD/contrib/subversion/subversion/libsvn_subr/cache-membuffer.c
/* Construct a svn_cache__t object on top of a shared memcache.
 */
Construct a svn_cache__t object on top of a shared memcache.
Construct a svn_cache__t object on top of a shared memcache .
svn_error_t *
svn_cache__create_membuffer_cache(svn_cache__t **cache_p,
                                  svn_membuffer_t *membuffer,
                                  svn_cache__serialize_func_t serializer,
                                  svn_cache__deserialize_func_t deserializer,
                                  apr_ssize_t klen,
                                  const char *prefix,
                                  apr_uint32_t priority,
                                  svn_boolean_t thread_safe,
                                  apr_pool_t *result_pool,
                                  apr_pool_t *scratch_pool)
{
  svn_checksum_t *checksum;
  apr_size_t prefix_len, prefix_orig_len;
  svn_cache__t *wrapper = apr_pcalloc(result_pool, sizeof(*wrapper));
  svn_membuffer_cache_t *cache = apr_pcalloc(result_pool, sizeof(*cache));
  cache->membuffer = membuffer;
  cache->serializer = serializer
                    ? serializer
                    : serialize_svn_stringbuf;
  cache->deserializer = deserializer
                      ? deserializer
                      : deserialize_svn_stringbuf;
  cache->priority = priority;
  cache->key_len = klen;
  SVN_ERR(svn_mutex__init(&cache->mutex, thread_safe, result_pool));
  prefix_orig_len = strlen(prefix) + 1;
  prefix_len = ALIGN_VALUE(prefix_orig_len);
  svn_membuf__create(&cache->prefix.full_key, prefix_len, result_pool);
  memcpy((char *)cache->prefix.full_key.data, prefix, prefix_orig_len);
  memset((char *)cache->prefix.full_key.data + prefix_orig_len, 0,
         prefix_len - prefix_orig_len);
  SVN_ERR(svn_checksum(&checksum,
                       svn_checksum_md5,
                       prefix,
                       strlen(prefix),
                       scratch_pool));
  memcpy(cache->prefix.entry_key.fingerprint, checksum->digest,
         sizeof(cache->prefix.entry_key.fingerprint));
  cache->prefix.entry_key.key_len = prefix_len;
  cache->combined_key.entry_key = cache->prefix.entry_key;
  svn_membuf__create(&cache->combined_key.full_key, prefix_len + 200,
                     result_pool);
  memcpy(cache->combined_key.full_key.data, cache->prefix.full_key.data,
         prefix_len);
  wrapper->vtable = thread_safe ? &membuffer_cache_synced_vtable
                                : &membuffer_cache_vtable;
  wrapper->cache_internal = cache;
  wrapper->error_handler = 0;
  wrapper->error_baton = 0;
  wrapper->pretend_empty = !!getenv("SVN_X_DOES_NOT_MARK_THE_SPOT");
  *cache_p = wrapper;
  return SVN_NO_ERROR;
}
svn_error_t * svn_cache__create_membuffer_cache ( svn_cache__t * * cache_p , svn_membuffer_t * membuffer , svn_cache__serialize_func_t serializer , svn_cache__deserialize_func_t deserializer , apr_ssize_t klen , const char * prefix , apr_uint32_t priority , svn_boolean_t thread_safe , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_checksum_t * checksum ; apr_size_t prefix_len , prefix_orig_len ; svn_cache__t * wrapper = apr_pcalloc ( result_pool , sizeof ( * wrapper ) ) ; svn_membuffer_cache_t * cache = apr_pcalloc ( result_pool , sizeof ( * cache ) ) ; cache -> membuffer = membuffer ; cache -> serializer = serializer ? serializer : serialize_svn_stringbuf ; cache -> deserializer = deserializer ? deserializer : deserialize_svn_stringbuf ; cache -> priority = priority ; cache -> key_len = klen ; SVN_ERR ( svn_mutex__init ( & cache -> mutex , thread_safe , result_pool ) ) ; prefix_orig_len = strlen ( prefix ) + 1 ; prefix_len = ALIGN_VALUE ( prefix_orig_len ) ; svn_membuf__create ( & cache -> prefix . full_key , prefix_len , result_pool ) ; memcpy ( ( char * ) cache -> prefix . full_key . data , prefix , prefix_orig_len ) ; memset ( ( char * ) cache -> prefix . full_key . data + prefix_orig_len , 0 , prefix_len - prefix_orig_len ) ; SVN_ERR ( svn_checksum ( & checksum , svn_checksum_md5 , prefix , strlen ( prefix ) , scratch_pool ) ) ; memcpy ( cache -> prefix . entry_key . fingerprint , checksum -> digest , sizeof ( cache -> prefix . entry_key . fingerprint ) ) ; cache -> prefix . entry_key . key_len = prefix_len ; cache -> combined_key . entry_key = cache -> prefix . entry_key ; svn_membuf__create ( & cache -> combined_key . full_key , prefix_len + 200 , result_pool ) ; memcpy ( cache -> combined_key . full_key . data , cache -> prefix . full_key . data , prefix_len ) ; wrapper -> vtable = thread_safe ? & membuffer_cache_synced_vtable : & membuffer_cache_vtable ; wrapper -> cache_internal = cache ; wrapper -> error_handler = 0 ; wrapper -> error_baton = 0 ; wrapper -> pretend_empty = ! ! getenv ( " " ) ; * cache_p = wrapper ; return SVN_NO_ERROR ; }
Construct a svn_cache__t object on top of a shared memcache.
Construct a svn_cache__t object on top of a shared memcache .
/* allocate the cache header structures
   */ /* initialize our internal cache header
   */ /* Copy the prefix into the prefix full key. Align it to ITEM_ALIGMENT.
   * Don't forget to include the terminating NUL. */ /* Construct the folded prefix key. */ /* Initialize the combined key. Pre-allocate some extra room in the full
   * key such that we probably don't need to re-alloc. */ /* initialize the generic cache wrapper
   */