tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native/common jk_shm.c jk_shm.h
Date Sun, 06 Feb 2005 10:35:55 GMT
mturk       2005/02/06 02:35:55

  Modified:    jk/native/common jk_shm.c jk_shm.h
  Log:
  Change shm API to use predefined shm struct since this one is
  always seerver global singleton.
  
  Revision  Changes    Path
  1.3       +37 -26    jakarta-tomcat-connectors/jk/native/common/jk_shm.c
  
  Index: jk_shm.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_shm.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jk_shm.c	6 Feb 2005 10:00:41 -0000	1.2
  +++ jk_shm.c	6 Feb 2005 10:35:55 -0000	1.3
  @@ -31,20 +31,27 @@
   static jk_shm_t *jk_global_shm = NULL;
   
   /* Use plain memory */
  -jk_shm_t *jk_shm_open(const char *fname, int workers, int dynamic, jk_pool_t *p)
  +int jk_shm_open(const char *fname, int workers, int dynamic, jk_shm_t *shm)
   {
  -    jk_shm_t *shm;
       jk_shm_h_rec_t *hdr;
   
  -    if (jk_global_shm)
  -        return jk_global_shm;
  -    shm = jk_pool_alloc(p, sizeof(jk_shm_t));
  +    if (jk_global_shm) {
  +        shm->attached = jk_global_shm->attached;
  +        shm->size = jk_global_shm->size;
  +        shm->base = jk_global_shm->base;
  +        shm->filename = jk_global_shm->filename;
  +        return 0;
  +    }
  +    if (workers < 1 || workers > JK_SHM_MAX_WORKERS)
  +        workers = JK_SHM_MAX_WORKERS;
  +    if (dynamic < 1 || dynamic > JK_SHM_MAX_WORKERS)
  +        dynamic = JK_SHM_MAX_WORKERS;
   
       shm->size = sizeof(jk_shm_h_rec_t) + (workers + dynamic) * sizeof(jk_shm_w_rec_t);
   
       shm->base = calloc(1, shm->size);
       if (!shm->base)
  -        return NULL;
  +        return -1;
       shm->filename = fname;
       shm->fd = -1;
       shm->attached = 0;
  @@ -56,17 +63,17 @@
       hdr->dynamic = dynamic;
   
       jk_global_shm = shm;
  -    return shm;
  +    return 0;
   }
   
  -jk_shm_t *jk_shm_attach(const char *fname, int workers, int dynamic, jk_pool_t *p)
  +int jk_shm_attach(const char *fname, int workers, int dynamic, jk_shm_t *shm)
   {
  -    jk_shm_t *shm = jk_shm_open(fname, workers, dynamic, p);
  -
  -    if (shm) {
  +    if (!jk_shm_open(fname, workers, dynamic, shm)) {
           shm->attached = 1;
  +        return 0;
       }
  -    return shm;
  +    else
  +        return -1;
   }
   
   void jk_shm_close(jk_shm_t *shm)
  @@ -97,10 +104,9 @@
   #define MAP_FILE    (0)
   #endif
   
  -static jk_shm_t *do_shm_open(const char *fname, int workers, int dynamic,
  -                             jk_pool_t *p, int attached)
  +static int do_shm_open(const char *fname, int workers, int dynamic,
  +                       jk_shm_t *shm, int attached)
   {
  -    jk_shm_t *shm;
       int fd;
       int flags = O_RDWR;
   
  @@ -108,8 +114,13 @@
           flags |= (O_CREAT|O_TRUNC);
       fd = open(fname, flags, 0666);
       if (fd == -1)
  -        return NULL;
  -    shm = jk_pool_alloc(p, sizeof(jk_shm_t));
  +        return -1;
  +
  +    if (workers < 1 || workers > JK_SHM_MAX_WORKERS)
  +        workers = JK_SHM_MAX_WORKERS;
  +    if (dynamic < 1 || dynamic > JK_SHM_MAX_WORKERS)
  +        dynamic = JK_SHM_MAX_WORKERS;
  +
       shm->size = sizeof(jk_shm_h_rec_t) + (workers + dynamic) * sizeof(jk_shm_w_rec_t);
   
       if (!attached) {
  @@ -118,13 +129,13 @@
               size = shm->size;
               if (ftruncate(fd, shm->size)) {
                   close(fd);
  -                return NULL;
  +                return -1;
               }
           }
       }
       if (lseek(fd, 0, SEEK_SET) != 0) {
           close(fd);
  -        return NULL;
  +        return -1;
       }
   
       shm->base = mmap(NULL, shm->size,
  @@ -136,7 +147,7 @@
       }
       if (!shm->base) {
           close(fd);
  -        return NULL;
  +        return -1;
       }
       shm->filename = fname;
       shm->fd = fd;
  @@ -157,17 +168,17 @@
           /* TODO: check header magic */
       }
   
  -    return shm;
  +    return 0;
   }
   
  -jk_shm_t *jk_shm_open(const char *fname, int workers, int dynamic, jk_pool_t *p)
  +int jk_shm_open(const char *fname, int workers, int dynamic, jk_shm_t *shm)
   {
  -    return do_shm_open(fname, workers, dynamic, p, 0);
  +    return do_shm_open(fname, workers, dynamic, shm, 0);
   }
   
  -jk_shm_t *jk_shm_attach(const char *fname, int workers, int dynamic, jk_pool_t *p)
  +int jk_shm_attach(const char *fname, int workers, int dynamic, jk_shm_t *shm)
   {
  -    return do_shm_open(fname, workers, dynamic, p, 1);
  +    return do_shm_open(fname, workers, dynamic, shm, 1);
   }
   
   void jk_shm_close(jk_shm_t *shm)
  
  
  
  1.2       +7 -3      jakarta-tomcat-connectors/jk/native/common/jk_shm.h
  
  Index: jk_shm.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_shm.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- jk_shm.h	5 Feb 2005 19:40:19 -0000	1.1
  +++ jk_shm.h	6 Feb 2005 10:35:55 -0000	1.2
  @@ -42,6 +42,10 @@
   #define JK_SHM_DYNAMIC  16
   #define JK_SHM_MAGIC    '!', 'J', 'K', 'S', 'H', 'M', JK_SHM_MAJOR, JK_SHM_MINOR
   
  +/* Really huge numbers, but 1024 workers should be enough */
  +#define JK_SHM_MAX_WORKERS  768
  +#define JK_SHM_MAX_DYNAMIC  256
  +
   /** jk shm structure */
   struct jk_shm
   {
  @@ -128,7 +132,7 @@
   
   /* Open the shared memory creating file if needed
    */
  -jk_shm_t *jk_shm_open(const char *fname, int workers, int dynamic, jk_pool_t *p);
  +int jk_shm_open(const char *fname, int workers, int dynamic, jk_shm_t *shm);
   
   /* Close the shared memory
    */
  @@ -137,7 +141,7 @@
   /* Attach the shared memory in child process.
    * File has to be opened in parent.
    */
  -jk_shm_t *jk_shm_attach(const char *fname, int workers, int dynamic, jk_pool_t *p);
  +int jk_shm_attach(const char *fname, int workers, int dynamic, jk_shm_t *shm);
   
   
   /* Return shm header record
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message