Skip to content

Commit

Permalink
New APR function apr_mmap_dup.
Browse files Browse the repository at this point in the history
this is used in the MMAP bucket setaside function for a performance win.
Mod_file_cache will also use this
Submitted by:	Brian Pane <[email protected]>


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62536 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kryton committed Nov 21, 2001
1 parent c267c38 commit 1594bc7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Changes with APR b1
*) New function apr_mmap_dup. This is called in the mmap_setaside
[Brain Pane <[email protected]>]

*) speed up the apr_hash_t implementation's handling of APR_HASH_KEY_STRING.
[Brain Pane <[email protected]>]

*) Tweak apr_gethostname() so that it detects truncation of the
name and returns an error. [Jeff Trawick]
Expand Down
15 changes: 15 additions & 0 deletions include/apr_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct apr_mmap_t {
void *mm;
/** The amount of data in the mmap */
apr_size_t size;
/** Whether this object is reponsible for doing the munmap */
int is_owner;
};

#if APR_HAS_MMAP || defined(DOXYGEN)
Expand All @@ -135,6 +137,19 @@ APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **newmmap,
apr_size_t size, apr_int32_t flag,
apr_pool_t *cntxt);

/**
* Duplicate the specified MMAP.
* @param new_mmap The structure to duplicate into.
* @param old_mmap The file to duplicate.
* @param p The pool to use for the new file.
* @param transfer_ownership Whether responsibility for destroying
* the memory-mapped segment is transferred from old_mmap to new_mmap
*/
APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
apr_mmap_t *old_mmap,
apr_pool_t *p,
int transfer_ownership);

/**
* Remove a mmap'ed.
* @param mmap The mmap'ed file.
Expand Down
32 changes: 32 additions & 0 deletions mmap/unix/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ static apr_status_t mmap_cleanup(void *themmap)
{
apr_mmap_t *mm = themmap;
int rv;

if (!mm->is_owner) {
return APR_SUCCESS;
}

#ifdef BEOS
rv = delete_area(mm->area);

Expand Down Expand Up @@ -159,13 +164,40 @@ APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **new,
(*new)->mm = mm;
(*new)->size = size;
(*new)->cntxt = cont;
(*new)->is_owner = 1;

/* register the cleanup... */
apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}

APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
apr_mmap_t *old_mmap,
apr_pool_t *p,
int transfer_ownership)
{
*new_mmap = (apr_mmap_t *)apr_pmemdup(p, old_mmap, sizeof(apr_mmap_t));
(*new_mmap)->cntxt = p;

/* The old_mmap can transfer ownership only if the old_mmap itself
* is an owner of the mmap'ed segment.
*/
if (old_mmap->is_owner) {
if (transfer_ownership) {
(*new_mmap)->is_owner = 1;
old_mmap->is_owner = 0;
apr_pool_cleanup_kill(old_mmap->cntxt, old_mmap, mmap_cleanup);
}
else {
(*new_mmap)->is_owner = 0;
}
apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
apr_pool_cleanup_null);
}
return APR_SUCCESS;
}

APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mmap)
{
apr_status_t rv;
Expand Down
32 changes: 32 additions & 0 deletions mmap/win32/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ static apr_status_t mmap_cleanup(void *themmap)
{
apr_mmap_t *mm = themmap;
apr_status_t rv = 0;

if (!mm->is_owner) {
return APR_SUCCESS;
}

if (mm->mv) {
if (!UnmapViewOfFile(mm->mv))
{
Expand Down Expand Up @@ -155,13 +160,40 @@ APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **new, apr_file_t *file,
(*new)->mm = (char*)((*new)->mv) + offset;
(*new)->size = size;
(*new)->cntxt = cont;
(*new)->is_owner = 1;

/* register the cleanup... */
apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}

APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap,
apr_mmap_t *old_mmap,
apr_pool_t *p,
int transfer_ownership)
{
*new_mmap = (apr_mmap_t *)apr_pmemdup(p, old_mmap, sizeof(apr_mmap_t));
(*new_mmap)->cntxt = p;

/* The old_mmap can transfer ownership only if the old_mmap itself
* is an owner of the mmap'ed segment.
*/
if (old_mmap->is_owner) {
if (transfer_ownership) {
(*new_mmap)->is_owner = 1;
old_mmap->is_owner = 0;
apr_pool_cleanup_kill(old_mmap->cntxt, old_mmap, mmap_cleanup);
}
else {
(*new_mmap)->is_owner = 0;
}
apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
apr_pool_cleanup_null);
}
return APR_SUCCESS;
}

APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mmap)
{
apr_status_t rv;
Expand Down

0 comments on commit 1594bc7

Please sign in to comment.