[mapserver-commits] r12283 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:13:40 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:13:40 -0700 (Fri, 26 Aug 2011)
New Revision: 12283
Modified:
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/lock.c
trunk/mapserver/mapcache/src/tileset.c
Log:
tweak
thomas.bonfort | 2011-01-24 17:54:29 +0100 (Mon, 24 Jan 2011)
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:13:35 UTC (rev 12282)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:13:40 UTC (rev 12283)
@@ -674,8 +674,6 @@
* \sa geocache_image_format
*/
geocache_buffer *data;
- void *lock; /**< pointer to opaque structure set by a geocache_cache to reference a lock on the tile
- \sa geocache_cache::tile_lock() */
apr_time_t mtime; /**< last modification time */
int expires; /**< time in seconds after which the tile should be rechecked for validity */
@@ -694,6 +692,7 @@
int ntiles; /**< the number of geocache_metatile::tiles contained in this metatile */
geocache_tile *tiles; /**< the list of geocache_tile s contained in this metatile */
geocache_image *imdata;
+ void *lock; /**< pointer to opaque structure set by the locking mechanism */
};
@@ -859,24 +858,24 @@
/**
* lock the tile
*/
-void geocache_tileset_tile_lock(geocache_context *ctx, geocache_tile *tile);
+void geocache_tileset_metatile_lock(geocache_context *ctx, geocache_metatile *tile);
/**
* unlock the tile
*/
-void geocache_tileset_tile_unlock(geocache_context *ctx, geocache_tile *tile);
+void geocache_tileset_metatile_unlock(geocache_context *ctx, geocache_metatile *tile);
/**
* check if there is a lock on the tile (the lock will have been set by another process/thread)
* \returns GEOCACHE_TRUE if the tile is locked by another process/thread
* \returns GEOCACHE_FALSE if there is no lock on the tile
*/
-int geocache_tileset_tile_lock_exists(geocache_context *ctx, geocache_tile *tile);
+int geocache_tileset_metatile_lock_exists(geocache_context *ctx, geocache_metatile *tile);
/**
* wait for the lock set on the tile (the lock will have been set by another process/thread)
*/
-void geocache_tileset_tile_lock_wait(geocache_context *ctx, geocache_tile *tile);
+void geocache_tileset_metatile_lock_wait(geocache_context *ctx, geocache_metatile *tile);
/** @} */
Modified: trunk/mapserver/mapcache/src/lock.c
===================================================================
--- trunk/mapserver/mapcache/src/lock.c 2011-08-26 11:13:35 UTC (rev 12282)
+++ trunk/mapserver/mapcache/src/lock.c 2011-08-26 11:13:40 UTC (rev 12283)
@@ -47,16 +47,16 @@
return ret;
}
-char *geocache_tileset_tile_lock_key(geocache_context *ctx, geocache_tile *tile) {
+char *geocache_tileset_metatile_lock_key(geocache_context *ctx, geocache_metatile *mt) {
char *lockname = apr_psprintf(ctx->pool,
"/%s-%s-%s%s", /*x,y,z,tilesetname*/
- num_encode(ctx->pool,tile->x), num_encode(ctx->pool,tile->y),
- num_encode(ctx->pool,tile->z), tile->tileset->name);
- if(tile->tileset->grid_links->nelts > 1) {
- lockname = apr_pstrcat(ctx->pool,lockname,tile->grid_link->grid->name,NULL);
+ num_encode(ctx->pool,mt->tile.x), num_encode(ctx->pool,mt->tile.y),
+ num_encode(ctx->pool,mt->tile.z), mt->tile.tileset->name);
+ if(mt->tile.tileset->grid_links->nelts > 1) {
+ lockname = apr_pstrcat(ctx->pool,lockname,mt->tile.grid_link->grid->name,NULL);
}
- if(tile->dimensions && !apr_is_empty_table(tile->dimensions)) {
- const apr_array_header_t *elts = apr_table_elts(tile->dimensions);
+ if(mt->tile.dimensions && !apr_is_empty_table(mt->tile.dimensions)) {
+ const apr_array_header_t *elts = apr_table_elts(mt->tile.dimensions);
int i;
for(i=0;i<elts->nelts;i++) {
apr_table_entry_t entry = APR_ARRAY_IDX(elts,i,apr_table_entry_t);
@@ -74,24 +74,21 @@
return lockname;
}
/**
- * \brief lock the given tile so other processes know it is being processed
+ * \brief lock the given metatile so other processes know it is being processed
*
* this function call is protected by a mutex
*
* this function creates a named semaphore and aquires a lock on it
- * \sa geocache_cache::tile_lock()
- * \sa geocache_cache::tile_lock_exists()
- * \private \memberof geocache_cache_disk
*/
-void geocache_tileset_tile_lock(geocache_context *ctx, geocache_tile *tile) {
- char *lockname = geocache_tileset_tile_lock_key(ctx,tile);
+void geocache_tileset_metatile_lock(geocache_context *ctx, geocache_metatile *mt) {
+ char *lockname = geocache_tileset_metatile_lock_key(ctx,mt);
sem_t *lock;
if ((lock = sem_open(lockname, O_CREAT|O_EXCL, 0644, 1)) == SEM_FAILED) {
ctx->set_error(ctx,500, "failed to create posix semaphore %s: %s",lockname, strerror(errno));
return;
}
sem_wait(lock);
- tile->lock = lock;
+ mt->lock = lock;
}
/**
@@ -102,17 +99,17 @@
* \sa geocache_cache::tile_unlock()
* \sa geocache_cache::tile_lock_exists()
*/
-void geocache_tileset_tile_unlock(geocache_context *ctx, geocache_tile *tile) {
- sem_t *lock = (sem_t*) tile->lock;
- const char *lockname = geocache_tileset_tile_lock_key(ctx,tile);
- if (!tile->lock) {
+void geocache_tileset_metatile_unlock(geocache_context *ctx, geocache_metatile *mt) {
+ sem_t *lock = (sem_t*) mt->lock;
+ const char *lockname = geocache_tileset_metatile_lock_key(ctx,mt);
+ if (!mt->lock) {
ctx->set_error(ctx,500,"###### TILE UNLOCK ######### attempting to unlock tile %s not created by this thread", lockname);
return;
}
sem_post(lock);
sem_close(lock);
sem_unlink(lockname);
- tile->lock = NULL;
+ mt->lock = NULL;
}
/**
@@ -123,11 +120,11 @@
* \sa geocache_cache::tile_lock()
* \sa geocache_cache::tile_unlock()
*/
-int geocache_tileset_tile_lock_exists(geocache_context *ctx, geocache_tile *tile) {
+int geocache_tileset_metatile_lock_exists(geocache_context *ctx, geocache_metatile *mt) {
char *lockname;
- if (tile->lock)
+ if (mt->lock)
return GEOCACHE_TRUE;
- lockname = geocache_tileset_tile_lock_key(ctx, tile);
+ lockname = geocache_tileset_metatile_lock_key(ctx, mt);
sem_t *lock = sem_open(lockname, 0, 0644, 1) ;
if (lock == SEM_FAILED) {
if(errno == ENOENT) {
@@ -148,16 +145,16 @@
* this function will not return until the lock on the tile has been removed
* \sa geocache_cache::tile_lock_wait()
*/
-void geocache_tileset_tile_lock_wait(geocache_context *ctx, geocache_tile *tile) {
+void geocache_tileset_metatile_lock_wait(geocache_context *ctx, geocache_metatile *mt) {
char *lockname;
sem_t *lock;
#ifdef DEBUG
- if (tile->lock) {
+ if (mt->lock) {
ctx->set_error(ctx, 500, "### BUG ### waiting for a lock we have created ourself");
return;
}
#endif
- lockname = geocache_tileset_tile_lock_key(ctx, tile);
+ lockname = geocache_tileset_metatile_lock_key(ctx, mt);
lock = sem_open(lockname, 0, 0644, 1) ;
if( lock == SEM_FAILED ) {
if(errno == ENOENT) {
Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:13:35 UTC (rev 12282)
+++ trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:13:40 UTC (rev 12283)
@@ -63,37 +63,6 @@
/*
- * for each of the metatile's tiles, ask the underlying cache to lock it
- */
-void _geocache_tileset_metatile_lock(geocache_context *ctx, geocache_metatile *mt) {
- int i;
- for(i=0; i<mt->ntiles; i++) {
- geocache_tile *tile = &(mt->tiles[i]);
- geocache_tileset_tile_lock(ctx, tile);
- if(GC_HAS_ERROR(ctx)) {
- /* undo successful locks */
- int j;
- for(j=0;j<i;j++) {
- tile = &(mt->tiles[j]);
- geocache_tileset_tile_unlock(ctx,tile);
- }
- return;
- }
- }
-}
-
-/*
- * for each of the metatile's tiles, ask the underlying cache to unlock it
- */
-void _geocache_tileset_metatile_unlock(geocache_context *ctx, geocache_metatile *mt) {
- int i;
- for(i=0; i<mt->ntiles; i++) {
- geocache_tile *tile = &(mt->tiles[i]);
- geocache_tileset_tile_unlock(ctx, tile);
- }
-}
-
-/*
* compute the metatile that should be rendered for the given tile
*/
static geocache_metatile* _geocache_tileset_metatile_get(geocache_context *ctx, geocache_tile *tile) {
@@ -240,12 +209,13 @@
ctx->global_lock_aquire(ctx);
GC_CHECK_ERROR(ctx);
+
+ mt = _geocache_tileset_metatile_get(ctx, tile);
- isLocked = geocache_tileset_tile_lock_exists(ctx, tile);
+ isLocked = geocache_tileset_metatile_lock_exists(ctx, mt);
if(isLocked == GEOCACHE_FALSE) {
- /* no other thread is doing the rendering, we aquire and lock a list of tiles to render */
- mt = _geocache_tileset_metatile_get(ctx, tile);
- _geocache_tileset_metatile_lock(ctx, mt);
+ /* no other thread is doing the rendering, we aquire and lock the metatile */
+ geocache_tileset_metatile_lock(ctx, mt);
}
ctx->global_lock_release(ctx);
if(GC_HAS_ERROR(ctx))
@@ -257,7 +227,7 @@
ctx->log(ctx, GEOCACHE_DEBUG, "cache wait: tileset %s - tile %d %d %d",
tile->tileset->name,tile->x, tile->y,tile->z);
#endif
- geocache_tileset_tile_lock_wait(ctx,tile);
+ geocache_tileset_metatile_lock_wait(ctx,mt);
GC_CHECK_ERROR(ctx);
} else {
/* no other thread is doing the rendering, do it ourselves */
@@ -270,7 +240,7 @@
/* remove the lockfiles */
ctx->global_lock_aquire(ctx);
- _geocache_tileset_metatile_unlock(ctx,mt);
+ geocache_tileset_metatile_unlock(ctx,mt);
ctx->global_lock_release(ctx);
GC_CHECK_ERROR(ctx);
}
More information about the mapserver-commits
mailing list