diff options
| author | Frank Warmerdam <warmerdam@pobox.com> | 2009-03-09 13:32:02 +0000 |
|---|---|---|
| committer | Frank Warmerdam <warmerdam@pobox.com> | 2009-03-09 13:32:02 +0000 |
| commit | d3c86d308fbf9100462618619f623d01bb450bbd (patch) | |
| tree | 559e8dfe7c0b10579f912d4e2d37a0fc0bd5cc17 /src | |
| parent | 79ab268f30b5705810b06c9997f20528160e48d3 (diff) | |
| download | PROJ-d3c86d308fbf9100462618619f623d01bb450bbd.tar.gz PROJ-d3c86d308fbf9100462618619f623d01bb450bbd.zip | |
added initial init file caching
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@1542 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/pj_init.c | 27 | ||||
| -rw-r--r-- | src/pj_initcache.c | 181 | ||||
| -rw-r--r-- | src/pj_mutex.c | 53 | ||||
| -rw-r--r-- | src/projects.h | 9 |
5 files changed, 271 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9a4095cf..205d1ed2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,7 +59,7 @@ libproj_la_SOURCES = \ nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \ pj_apply_gridshift.c pj_datums.c pj_datum_set.c pj_transform.c \ geocent.c geocent.h pj_utils.c pj_gridinfo.c pj_gridlist.c \ - jniproj.c + jniproj.c pj_mutex.c pj_initcache.c install-exec-local: diff --git a/src/pj_init.c b/src/pj_init.c index 5f09c569..6b70d62b 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -106,8 +106,27 @@ static paralist * get_init(paralist **start, paralist *next, char *name) { char fname[MAX_PATH_FILENAME+ID_TAG_MAX+3], *opt; FILE *fid; + paralist *init_items = NULL; + const paralist *orig_next = next; (void)strncpy(fname, name, MAX_PATH_FILENAME + ID_TAG_MAX + 1); + + /* + ** Search for file/key pair in cache + */ + + init_items = pj_search_initcache( name ); + if( init_items != NULL ) + { + next->next = init_items; + while( next->next != NULL ) + next = next->next; + return next; + } + + /* + ** Otherwise we try to open the file and search for it. + */ if (opt = strrchr(fname, ':')) *opt++ = '\0'; else { pj_errno = -3; return(0); } @@ -118,6 +137,14 @@ get_init(paralist **start, paralist *next, char *name) { (void)fclose(fid); if (errno == 25) errno = 0; /* unknown problem with some sys errno<-25 */ + + /* + ** If we seem to have gotten a result, insert it into the + ** init file cache. + */ + if( next != NULL && next != orig_next ) + pj_insert_initcache( name, orig_next->next ); + return next; } diff --git a/src/pj_initcache.c b/src/pj_initcache.c new file mode 100644 index 00000000..5dd46fad --- /dev/null +++ b/src/pj_initcache.c @@ -0,0 +1,181 @@ +/****************************************************************************** + * $Id: pj_transform.c 1504 2009-01-06 02:11:57Z warmerdam $ + * + * Project: PROJ.4 + * Purpose: init file definition cache. + * Author: Frank Warmerdam, warmerdam@pobox.com + * + ****************************************************************************** + * Copyright (c) 2009, Frank Warmerdam + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *****************************************************************************/ + +#include <projects.h> +#include <string.h> + +PJ_CVSID("$Id: pj_transform.c 1504 2009-01-06 02:11:57Z warmerdam $"); + +static int cache_count = 0; +static int cache_alloc = 0; +static char **cache_key = NULL; +static paralist **cache_paralist = NULL; + +/************************************************************************/ +/* pj_clone_paralist() */ +/* */ +/* Allocate a copy of a parameter list. */ +/************************************************************************/ + +paralist *pj_clone_paralist( const paralist *list) +{ + paralist *list_copy = NULL, *next_copy = NULL; + + for( ; list != NULL; list = list->next ) + { + paralist *newitem = (paralist *) + pj_malloc(sizeof(paralist) + strlen(list->param)); + + newitem->used = 0; + newitem->next = 0; + strcpy( newitem->param, list->param ); + + if( list_copy == NULL ) + list_copy = newitem; + else + next_copy->next = newitem; + + next_copy = newitem; + } + + return list_copy; +} + +/************************************************************************/ +/* pj_clear_initcache() */ +/* */ +/* Clear out all memory held in the init file cache. */ +/************************************************************************/ + +void pj_clear_initcache() +{ + if( cache_alloc > 0 ) + { + int i; + + pj_acquire_lock(); + + for( i = 0; i < cache_count; i++ ) + { + paralist *n, *t = cache_paralist[i]; + + pj_dalloc( cache_key[i] ); + + /* free parameter list elements */ + for (; t != NULL; t = n) { + n = t->next; + pj_dalloc(t); + } + } + + pj_dalloc( cache_key ); + pj_dalloc( cache_paralist ); + cache_count = 0; + cache_alloc= 0; + cache_key = NULL; + cache_paralist = NULL; + + pj_release_lock(); + } +} + +/************************************************************************/ +/* pj_search_initcache() */ +/* */ +/* Search for a matching definition in the init cache. */ +/************************************************************************/ + +paralist *pj_search_initcache( const char *filekey ) + +{ + int i; + paralist *result = NULL; + + pj_acquire_lock(); + + for( i = 0; result == NULL && i < cache_count; i++) + { + if( strcmp(filekey,cache_key[i]) == 0 ) + { + result = pj_clone_paralist( cache_paralist[i] ); + } + } + + pj_release_lock(); + + return result; +} + +/************************************************************************/ +/* pj_insert_initcache() */ +/* */ +/* Insert a paralist definition in the init file cache. */ +/************************************************************************/ + +void pj_insert_initcache( const char *filekey, const paralist *list ) + +{ + pj_acquire_lock(); + + /* + ** Grow list if required. + */ + if( cache_count == cache_alloc ) + { + char **cache_key_new; + paralist **cache_paralist_new; + + cache_alloc = cache_alloc * 2 + 15; + + cache_key_new = (char **) pj_malloc(sizeof(char*) * cache_alloc); + memcpy( cache_key, cache_key_new, sizeof(char*) * cache_count); + pj_dalloc( cache_key ); + cache_key = cache_key_new; + + cache_paralist_new = (paralist **) + pj_malloc(sizeof(paralist*) * cache_alloc); + memcpy( cache_paralist_new, cache_paralist, + sizeof(paralist*) * cache_count ); + pj_dalloc( cache_paralist ); + cache_paralist = cache_paralist_new; + } + + /* + ** Duplicate the filekey and paralist, and insert in cache. + */ + cache_key[cache_count] = (char *) pj_malloc(strlen(filekey)+1); + strcpy( cache_key[cache_count], filekey ); + + cache_paralist[cache_count] = pj_clone_paralist( list ); + + cache_count++; + + pj_release_lock(); +} + diff --git a/src/pj_mutex.c b/src/pj_mutex.c new file mode 100644 index 00000000..f988e1c3 --- /dev/null +++ b/src/pj_mutex.c @@ -0,0 +1,53 @@ +/****************************************************************************** + * $Id: pj_transform.c 1504 2009-01-06 02:11:57Z warmerdam $ + * + * Project: PROJ.4 + * Purpose: Mutex (thread lock) functions. + * Author: Frank Warmerdam, warmerdam@pobox.com + * + ****************************************************************************** + * Copyright (c) 2009, Frank Warmerdam + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + *****************************************************************************/ + +#include <projects.h> + +PJ_CVSID("$Id: pj_transform.c 1504 2009-01-06 02:11:57Z warmerdam $"); + +/************************************************************************/ +/* pj_acquire_lock() */ +/* */ +/* Acquire the PROJ.4 lock. */ +/************************************************************************/ + +void pj_acquire_lock() +{ +} + +/************************************************************************/ +/* pj_release_lock() */ +/* */ +/* Release the PROJ.4 lock. */ +/************************************************************************/ + +void pj_release_lock() +{ +} + diff --git a/src/projects.h b/src/projects.h index 6ed75648..60693e53 100644 --- a/src/projects.h +++ b/src/projects.h @@ -342,6 +342,12 @@ int pj_ell_set(paralist *, double *, double *); int pj_datum_set(paralist *, PJ *); int pj_prime_meridian_set(paralist *, PJ *); int pj_angular_units_set(paralist *, PJ *); + +paralist *pj_clone_paralist( const paralist* ); +void pj_clear_initcache(void); +paralist*pj_search_initcache( const char *filekey ); +void pj_insert_initcache( const char *filekey, const paralist *list); + double *pj_enfn(double); double pj_mlfn(double, double, double, double *); double pj_inv_mlfn(double, double, double *); @@ -398,6 +404,9 @@ PJ_GRIDINFO *pj_gridinfo_init( const char * ); int pj_gridinfo_load( PJ_GRIDINFO * ); void pj_gridinfo_free( PJ_GRIDINFO * ); +void pj_acquire_lock(void); +void pj_release_lock(void); + void *proj_mdist_ini(double); double proj_mdist(double, double, double, const void *); double proj_inv_mdist(double, const void *); |
