costin 02/04/10 16:44:56 Modified: jk/native2/common jk_shm.c Added: jk/native2/include jk_shm.h Log: A bit more code in the shm area. Revision Changes Path 1.1 jakarta-tomcat-connectors/jk/native2/include/jk_shm.h Index: jk_shm.h =================================================================== /* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2001 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Jk", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <[EMAIL PROTECTED]>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= */ #ifndef JK_SHM_H #define JK_SHM_H #include "jk_global.h" #include "jk_env.h" #include "jk_logger.h" #include "jk_pool.h" #include "jk_msg.h" #include "jk_service.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ struct jk_env; struct jk_shm; typedef struct jk_shm jk_shm_t; /** Each shared memory slot has at least the following components. */ struct jk_shm_slot { /** Size of the segment */ int size; /** Version of the segment. Whoever writes it must change the version after writing. Various components will check the version and refresh if needed */ int ver; /** Name of the segment. */ char type[64]; char data[1]; }; /** * Shared memory support. This is similar with the scoreboard or jserv's worker shm, but * organized a bit more generic to support use of shm as a channel and to support config * changes. * * The structure is organized as an array of 'slots'. Each slot has a name and data. Slots are long lived - * they are never destroyed. * Each slot has it's own rules for content and synchronization - but typically they are 'owned' * by a process or thread and use various conventions to avoid the need for sync. * * @author Costin Manolache */ struct jk_shm { struct jk_bean *mbean; struct jk_pool *pool; char *fname; /** Initialize the shared memory area. It'll map the shared memory * segment if it exists, or create and init it if not. */ int (*init)(struct jk_env *env, struct jk_shm *shm); /** Get a shm slot. Each slot has different rules for synchronization, based on type. */ struct jk_shm_slot *(*getSlot)(struct jk_env *env, struct jk_shm *shm, char *name, int size); /** Create a slot. This typically involves inter-process synchronization. */ struct jk_shm_slot *(*createSlot)(struct jk_env *env, struct jk_shm *shm, char *name, int size); /** Get an ID that is unique across processes. */ int (*getId)(struct jk_env *env, struct jk_shm *shm); /* Private data */ void *privateData; }; #ifdef __cplusplus } #endif /* __cplusplus */ #endif 1.2 +31 -40 jakarta-tomcat-connectors/jk/native2/common/jk_shm.c Index: jk_shm.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_shm.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- jk_shm.c 8 Apr 2002 19:17:35 -0000 1.1 +++ jk_shm.c 10 Apr 2002 23:44:56 -0000 1.2 @@ -69,6 +69,7 @@ #include "jk_global.h" #include "jk_map.h" #include "jk_pool.h" +#include "jk_shm.h" #ifdef HAS_APR @@ -88,25 +89,6 @@ #include "apr_shm.h" -/* - Shared memory support for jk. - - Will be used for interprocess communication ( as a channel - eventually with a single copy ), and - for configuration/monitoring. - - The model will be very similar with the apache scoreboard and jserv's load-balancing shmem. - - However we try to make it more flexible in order to support run-time configuration and - IPC. - - The shmem will consist of 'slots'. Each slot will be owned by a process. - - The tricky part is avoiding inter-process synchronization - that's done by a complex set of - rules ( similar with the scoreboard and jserv). - - ( XXX The first impl. will just provide the jserv-style support for lb workers ) -*/ - struct jk_shm_buffer { /** Incremented after each modification */ int generation; @@ -125,39 +107,38 @@ }; struct jk_shm_head { - int generation; - - int bufferSize; + int size; int bufferCount; - struct jk_shm_buffer *buffers; + + int objCount; + int lastId; + + struct jk_shm_buffer buffers[1]; }; -typedef struct jk_shm { - char *fname; - apr_shm_t *aprShm; + +typedef struct jk_shm_private { apr_size_t size; + apr_shm_t *aprShm; apr_pool_t *aprPool; - - int objCount; - int lastId; - - /* XXX writelock */ - struct jk_shm_head *image; -} jk_shm_t; - +} jk_shm_private_t; static apr_pool_t *globalShmPool; static int jk_shm_destroy(jk_env_t *env, jk_shm_t *shm) { - return apr_shm_destroy(shm->aprShm); + jk_shm_private_t *shmP=shm->privateData; + + return apr_shm_destroy(shmP->aprShm); } static int jk_shm_detach(jk_env_t *env, jk_shm_t *shm) { - return apr_shm_detach(shm->aprShm); + jk_shm_private_t *shmP=shm->privateData; + + return apr_shm_detach(shmP->aprShm); } static int jk_shm_attach(jk_env_t *env, jk_shm_t *shm) @@ -172,6 +153,7 @@ static int jk_shm_createScoreboard(jk_env_t *env, jk_shm_t *shm) { apr_status_t rv; + jk_shm_private_t *shmP=shm->privateData; /* We don't want to have to recreate the scoreboard after * restarts, so we'll create a global pool and never clean it. @@ -198,7 +180,7 @@ * segment. */ apr_file_remove(shm->fname, globalShmPool ); /* ignore errors */ - rv = apr_shm_create(&shm->aprShm, shm->size, shm->fname, globalShmPool); + rv = apr_shm_create(&shmP->aprShm, shmP->size, shm->fname, globalShmPool); if (rv) { env->l->jkLog(env, env->l, JK_LOG_ERROR, @@ -207,15 +189,21 @@ return rv; } - shm->image = apr_shm_baseaddr_get( shm->aprShm); - if( shm->image==NULL ) { + shmP->image = apr_shm_baseaddr_get( shmP->aprShm); + if( shmP->image==NULL ) { env->l->jkLog(env, env->l, JK_LOG_ERROR, "shm.create(): No memory allocated %s\n", shm->fname); return JK_FALSE; } - memset(shm->image, 0, shm->size); + memset(shmP->image, 0, shmP->size); + + return JK_TRUE; +} + +static int jk2_shm_init(struct jk_env *env, jk_shm_t *shm) { + return JK_TRUE; } @@ -228,6 +216,7 @@ jk_shm_t *_this; _this=(jk_shm_t *)pool->alloc(env, pool, sizeof(jk_shm_t)); + if( _this == NULL ) return JK_FALSE; @@ -236,6 +225,8 @@ /* _this->mbean=result; */ result->object=_this; + _this->init=jk2_shm_init; + /* result->aprPool=(apr_pool_t *)p->_private; */ return JK_TRUE;
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>