diff options
author | jwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68> | 2002-11-23 21:17:27 +0000 |
---|---|---|
committer | jwoolley <jwoolley@13f79535-47bb-0310-9956-ffa450edef68> | 2002-11-23 21:17:27 +0000 |
commit | 66ccfd970a816a31670486a1afa0338cf2903ae5 (patch) | |
tree | 6d3f7bbc1439b32841d05b809d283c5dccf96fb3 /mmap | |
parent | 6eb654c280774eaf5cb263f2cc8638b4459de906 (diff) | |
download | libapr-66ccfd970a816a31670486a1afa0338cf2903ae5.tar.gz |
Fixed the apr_mmap_dup ownership problem for disjoint pools by getting
rid of the is_owner thing completely. Instead, we place all of the dup'ed
apr_mmap_t's in a ring with each other (essentially the same as refcounting
the mmaped region but without the where-do-you-store-it pitfall).
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64067 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'mmap')
-rw-r--r-- | mmap/unix/mmap.c | 37 | ||||
-rw-r--r-- | mmap/win32/mmap.c | 35 |
2 files changed, 29 insertions, 43 deletions
diff --git a/mmap/unix/mmap.c b/mmap/unix/mmap.c index 4a54b860e..707702662 100644 --- a/mmap/unix/mmap.c +++ b/mmap/unix/mmap.c @@ -83,13 +83,17 @@ static apr_status_t mmap_cleanup(void *themmap) { apr_mmap_t *mm = themmap; - int rv; + apr_mmap_t *next = APR_RING_NEXT(mm,link); + int rv = 0; - if (!mm->is_owner) { - return APR_EINVAL; - } - else if (mm->mm == (void *)-1) { - return APR_ENOENT; + /* we no longer refer to the mmaped region */ + APR_RING_REMOVE(mm,link); + APR_RING_NEXT(mm,link) = NULL; + APR_RING_PREV(mm,link) = NULL; + + if (next != mm) { + /* more references exist, so we're done */ + return APR_SUCCESS; } #ifdef BEOS @@ -163,7 +167,7 @@ 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; + APR_RING_ELEM_INIT(*new, link); /* register the cleanup... */ apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup, @@ -179,21 +183,10 @@ APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap, *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); - apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup, - apr_pool_cleanup_null); - } - else { - (*new_mmap)->is_owner = 0; - } - } + APR_RING_INSERT_AFTER(old_mmap, *new_mmap, link); + + apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup, + apr_pool_cleanup_null); return APR_SUCCESS; } diff --git a/mmap/win32/mmap.c b/mmap/win32/mmap.c index a113ecfcf..4053ab868 100644 --- a/mmap/win32/mmap.c +++ b/mmap/win32/mmap.c @@ -66,13 +66,17 @@ static apr_status_t mmap_cleanup(void *themmap) { apr_mmap_t *mm = themmap; + apr_mmap_t *next = APR_RING_NEXT(mm,link); apr_status_t rv = 0; - if (!mm->is_owner) { - return APR_EINVAL; - } - else if (!mm->mhandle) { - return APR_ENOENT; + /* we no longer refer to the mmaped region */ + APR_RING_REMOVE(mm,link); + APR_RING_NEXT(mm,link) = NULL; + APR_RING_PREV(mm,link) = NULL; + + if (next != mm) { + /* more references exist, so we're done */ + return APR_SUCCESS; } if (mm->mv) { @@ -163,7 +167,7 @@ APR_DECLARE(apr_status_t) apr_mmap_create(apr_mmap_t **new, apr_file_t *file, (*new)->mm = (char*)((*new)->mv) + (*new)->poffset; (*new)->size = size; (*new)->cntxt = cont; - (*new)->is_owner = 1; + APR_RING_ELEM_INIT(*new, link); /* register the cleanup... */ apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup, @@ -179,21 +183,10 @@ APR_DECLARE(apr_status_t) apr_mmap_dup(apr_mmap_t **new_mmap, *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); - apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup, - apr_pool_cleanup_null); - } - else { - (*new_mmap)->is_owner = 0; - } - } + APR_RING_INSERT_AFTER(old_mmap, *new_mmap, link); + + apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup, + apr_pool_cleanup_null); return APR_SUCCESS; } |