You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by je...@apache.org on 2001/08/13 23:49:09 UTC

cvs commit: apr/test Makefile.in testshmem.c

jerenkrantz    01/08/13 14:49:09

  Modified:    .        CHANGES acconfig.h configure.in
               include  apr.h.in
               shmem/unix Makefile.in shmem.c
               test     Makefile.in testshmem.c
  Log:
  Move the necessary shared memory code from MM into APR and remove our
  dependency upon MM.  (This commit does not delete the MM files - they
  are still there for the time being.)
  
  MM has a bunch of features that we do not need (locking, three different
  APIs, etc, etc, etc.)
  
  Also clean up the migrated code while I'm at it to be cleaner.
  
  This code works on Solaris with shmget.  I'll be testing it again with
  Linux in a few.  This really needs to get hammered to make sure that I
  didn't miss anything.
  
  This gets us moving in the right direction.
  
  Revision  Changes    Path
  1.137     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- CHANGES	2001/08/13 13:22:30	1.136
  +++ CHANGES	2001/08/13 21:49:08	1.137
  @@ -1,4 +1,8 @@
   Changes with APR b1  
  +
  +  *) Move the necessary shared memory code from MM into APR and remove
  +     our dependency upon MM.  [Justin Erenkrantz]
  +
     *) Get apr_lock_file and apr_unlock_file working on Windows 9x.
        [Mladen Turk, Bill Stoddard]
   
  
  
  
  1.50      +1 -0      apr/acconfig.h
  
  Index: acconfig.h
  ===================================================================
  RCS file: /home/cvs/apr/acconfig.h,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- acconfig.h	2001/07/31 02:10:10	1.49
  +++ acconfig.h	2001/08/13 21:49:08	1.50
  @@ -14,6 +14,7 @@
   #undef HAVE_POLLIN
   #undef HAVE_isascii
   #undef HAVE_SO_ACCEPTFILTER
  +#undef HAVE_MAP_ANON
   
   /* Cross process serialization techniques */
   #undef USE_FLOCK_SERIALIZE
  
  
  
  1.356     +86 -78    apr/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /home/cvs/apr/configure.in,v
  retrieving revision 1.355
  retrieving revision 1.356
  diff -u -r1.355 -r1.356
  --- configure.in	2001/08/13 20:04:28	1.355
  +++ configure.in	2001/08/13 21:49:08	1.356
  @@ -200,13 +200,11 @@
   	APR_ADDTO(CFLAGS,-Kthread)
   	;;
   esac
  -LOCAL_MM_LIB="../shmem/unix/mm/libmm.la"
   config_subdirs="none"
  +INSTALL_SUBDIRS="none"
   case $host in
      i386-ibm-aix* | *-ibm-aix[1-2].* | *-ibm-aix3.* | *-ibm-aix4.1 | *-ibm-aix4.1.* | *-ibm-aix4.2 | *-ibm-aix4.2.*)
          OSDIR="aix"
  -       config_subdirs="shmem/unix/mm"
  -       USE_MM=yes
          eolstr="\\n"
          ;;
      *-os2*)
  @@ -214,7 +212,6 @@
          APR_ADDTO(CFLAGS,-Zmt)
          OSDIR="os2"
          enable_threads="system_threads"
  -       LOCAL_MM_LIB=""
          eolstr="\\r\\n"
          file_as_socket="0"
          ;;
  @@ -234,23 +231,19 @@
                file_as_socket="0"
                ;;
          esac
  -       LOCAL_MM_LIB=""
          ;;
      *os390)
          OSDIR="os390"
  -       config_subdirs="shmem/unix/mm"
  -       USE_MM=yes
          eolstr="\\n"
          ;;
      *)
          OSDIR="unix"
  -       config_subdirs="shmem/unix/mm"
  -       USE_MM=yes
          eolstr="\\n"
          ;;
   esac
   
   AC_SUBST(eolstr)
  +AC_SUBST(INSTALL_SUBDIRS)
   
   dnl For some platforms we need a version string which allows easy numeric
   dnl comparisons.
  @@ -390,73 +383,100 @@
   dnl #----------------------------- Checking for Shared Memory Support 
   echo $ac_n "${nl}Checking for Shared Memory Support...${nl}"
   
  -# run the MM config script regardless of whether we are going to use
  -# it or not.  When we have a much better idea of who is using MM, we can
  -# run this on a more conditional basis.
  -mm_dir=shmem/unix/mm
  -
  -dnl #----------------------------- Prepare mm directory for VPATH support
  -if test "$USE_MM" = "yes"; then
  -  if test -n "$USE_VPATH"; then
  -    test -d $mm_dir || $MKDIR $mm_dir
  -
  -    for i in shtool config.guess config.sub fbtool ltconfig \
  -             ltmain.sh mm_vers.c; do
  -      test -r $mm_dir/$i || ln -s $abs_srcdir/$mm_dir/$i $mm_dir/$i
  -    done
  -  fi
  -  APR_SUBDIR_CONFIG($config_subdirs)
  -fi
  +AC_HAVE_HEADERS(sys/mman.h)
  +APR_CHECK_DEFINE(MAP_ANON, sys/mman.h)
  +AC_HAVE_FUNCS(mmap munmap shm_open shm_unlink)
  +APR_CHECK_FILE(/dev/zero)
  +AC_HAVE_HEADERS(sys/ipc.h sys/shm.h sys/file.h)
  +AC_HAVE_FUNCS(shmget shmat shmdt shmctl)
  +AC_HAVE_HEADERS(kernel/OS.h)
  +AC_HAVE_FUNCS(create_area)
  +
  +dnl Now we determine which one is our preference.
  +APR_BEGIN_DECISION([shared memory allocation method])
  +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap,
  +             APR_DECIDE(USE_SHMEM_MMAP_TMP, 
  +             [Classical mmap() on temporary file]))
  +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap func:shm_open dnl
  +             func:shm_unlink,
  +             APR_DECIDE(USE_SHMEM_MMAP_SHM, 
  +             [mmap() via POSIX.1 shm_open() on temporary file]))
  +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap file:/dev/zero,
  +             APR_DECIDE(USE_SHMEM_MMAP_ZERO, 
  +             [SVR4-style mmap() on /dev/zero]))
  +APR_IFALLYES(header:sys/ipc.h header:sys/shm.h header:sys/file.h dnl
  +             func:shmget func:shmat func:shmdt func:shmctl,
  +             APR_DECIDE(USE_SHMEM_SHMGET, [SysV IPC shmget()]))
  +APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
  +             APR_DECIDE(USE_SHMEM_MMAP_ANON, 
  +             [4.4BSD-style mmap() via MAP_ANON]))
  +APR_IFALLYES(header:kernel/OS.h func:create_area,
  +             APR_DECIDE(USE_SHMEM_BEOS, [BeOS areas]))
  +APR_END_DECISION
  +AC_DEFINE_UNQUOTED($ac_decision)
   
  -INSTALL_SUBDIRS=$config_subdirs
  -AC_SUBST(INSTALL_SUBDIRS)
  +usemmaptmp="0"
  +usemmapshm="0"
  +usemmapzero="0"
  +useshmget="0"
  +usemmapanon="0"
  +usebeosarea="0"
  +mem_based="0"
  +file_based="1"
   
  -AC_MSG_CHECKING(for Shared memory support)
  -AC_ARG_ENABLE(shmem,
  -  [  --enable-shmem          Enable shared memory support in APR. ],
  -  [ ],
  -  ac_cv_enable_shmem="mm" )
  +case $ac_decision in
  +    USE_SHMEM_MMAP_TMP )
  +        usemmaptmp="1"
  +        file_based="1"
  +        ;;
  +    USE_SHMEM_MMAP_SHM )
  +        usemmapshm="1"
  +        mem_based="1"
  +        ;;
  +    USE_SHMEM_MMAP_ZERO )
  +        usemmapzero="1"
  +        mem_based="1"
  +        ;;
  +    USE_SHMEM_SHMGET )
  +        useshmget="1"
  +        mem_based="1"
  +        ;;
  +    USE_SHMEM_MMAP_ANON )
  +        usemmapanon="1"
  +        mem_based="1"
  +        ;;
  +    USE_SHMEM_BEOS )
  +        usebeosarea="1"
  +        mem_based="1"
  +        ;;
  +esac
   
  -sharedmem="0"
  -anonymous_shm="0"
  -filebased_shm="0"
  -keybased_shm="0"
  -if test "$ac_cv_enable_shmem" = "mm"; then
  -  sharedmem="1"
  -  anonymous_shm="1"
  -  AC_MSG_RESULT(anonymous)
  -  if test "$USE_MM" = "yes"; then
  -    LIBTOOL_LIBS="$abs_builddir/shmem/unix/mm/libmm.la"
  -  fi
  -elif test "$ac_cv_enable_shmem" = "file"; then
  -  sharedmem="1"
  -  filebased_shm="1"
  -  AC_MSG_RESULT(file based)
  -elif test "$ac_cv_enable_shmem" = "key"; then
  -  sharedmem="1"
  -  keybased_shm="1"
  -  AC_MSG_RESULT(key based)
  +dnl Do we have any shared memory support?
  +if test "$usemmaptmp$usemmapshm$usemmapzero$useshmget$usemmapanon$usebeosarea" = "000000"; then
  +  sharedmem="0"
   else
  -  AC_MSG_RESULT(no)
  +  sharedmem="1"
   fi
  +
  +AC_SUBST(usemmaptmp)
  +AC_SUBST(usemmapshm)
  +AC_SUBST(usemmapzero)
  +AC_SUBST(useshmget)
  +AC_SUBST(usemmapanon)
  +AC_SUBST(usebeosarea)
   AC_SUBST(sharedmem)
  +AC_SUBST(file_based)
  +AC_SUBST(mem_based)
  +
  +dnl We only support anonymous shared memory in Unix currently.
  +anonymous_shm="1"
  +filebased_shm="0"
  +keybased_shm="0"
  +
   AC_SUBST(anonymous_shm)
   AC_SUBST(filebased_shm)
   AC_SUBST(keybased_shm)
   
  -APR_CHECK_DEFINE(MM_SHMT_MMFILE, $srcdir/shmem/unix/mm/mm_conf.h) 
  -
  -if test "$ac_cv_define_MM_SHMT_MMFILE" = "yes"; then
  -    file_based="1"
  -    mem_based="0"
  -else
  -    file_based="0"
  -    mem_based="1"
  -fi
  -
  -AC_SUBST(mem_based)
  -AC_SUBST(file_based)
  -
   if test ".$SYS_SW" = ".AIX"; then
       APR_ADDTO(CPPFLAGS,-U__STR__)
       case "$SYS_KV" in
  @@ -1306,7 +1326,6 @@
   AC_SUBST(DEFAULT_OSDIR)
   AC_SUBST(EXEEXT)
   AC_SUBST(LIBTOOL_LIBS)
  -AC_SUBST(LOCAL_MM_LIB)
   
   echo "${nl}Construct Makefiles and header files."
   MAKEFILE1="Makefile strings/Makefile passwd/Makefile tables/Makefile build/Makefile"
  @@ -1376,9 +1395,6 @@
   changequote({,})
   
   if test -n "$USE_VPATH"; then
  -  if test -n "$USE_MM"; then
  -    MAKEFILE3="$MAKEFILE3 $mm_dir/Makefile"
  -  fi
     for makefile in $MAKEFILE1 $MAKEFILE2 $MAKEFILE3; do
       dir=`echo $makefile|sed 's%[^/][^/]*$%%'`
       (cat <<EOF
  @@ -1394,14 +1410,6 @@
   		> tmp
       cp tmp $makefile
     done
  -  if test -n "$USE_MM"; then
  -    cat $mm_dir/Makefile | \
  -       sed \
  -       -e 's#\($(CFLAGS)\)#\1 -I$(srcdir) -I.#' \
  -       -e '/mm_global\.c/d' \
  -       > tmp
  -    cp tmp $mm_dir/Makefile
  -  fi
     rm -f tmp
   fi
   
  
  
  
  1.90      +6 -0      apr/include/apr.h.in
  
  Index: apr.h.in
  ===================================================================
  RCS file: /home/cvs/apr/include/apr.h.in,v
  retrieving revision 1.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- apr.h.in	2001/08/12 05:50:46	1.89
  +++ apr.h.in	2001/08/13 21:49:08	1.90
  @@ -62,6 +62,12 @@
   #define APR_HAVE_SYS_WAIT_H      @sys_waith@
   #define APR_HAVE_UNISTD_H        @unistdh@
   
  +#define APR_USE_SHMEM_MMAP_TMP   @usemmaptmp@
  +#define APR_USE_SHMEM_MMAP_SHM   @usemmapshm@
  +#define APR_USE_SHMEM_MMAP_ZERO  @usemmapzero@
  +#define APR_USE_SHMEM_SHMGET     @useshmget@
  +#define APR_USE_SHMEM_BEOS       @usebeosarea@
  +
   #define APR_USE_FLOCK_SERIALIZE           @flockser@ 
   #define APR_USE_SYSVSEM_SERIALIZE         @sysvser@
   #define APR_USE_FCNTL_SERIALIZE           @fcntlser@
  
  
  
  1.17      +2 -12     apr/shmem/unix/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/shmem/unix/Makefile.in,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Makefile.in	2001/01/10 23:50:32	1.16
  +++ Makefile.in	2001/08/13 21:49:08	1.17
  @@ -1,20 +1,10 @@
   
  -TARGETS = shmem.lo build-mm
  +TARGETS = shmem.lo
   
   # bring in rules.mk for standard functionality
   @INCLUDE_RULES@
   
   INCDIR=../../include
  -INCDIR1=mm
  -INCLUDES=-I$(INCDIR) -I$(INCDIR1)
  -
  -x-local-clean:
  -	(cd mm && $(MAKE) clean)
  -
  -x-local-distclean:
  -	(cd mm && $(MAKE) distclean)
  -
  -build-mm:
  -	(cd mm && $(MAKE) libmm.la)
  +INCLUDES=-I$(INCDIR)
   
   # DO NOT REMOVE
  
  
  
  1.24      +184 -38   apr/shmem/unix/shmem.c
  
  Index: shmem.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/unix/shmem.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- shmem.c	2001/08/10 21:04:48	1.23
  +++ shmem.c	2001/08/13 21:49:08	1.24
  @@ -52,61 +52,199 @@
    * <http://www.apache.org/>.
    */
   
  -#include "mm.h"
   #include "apr_general.h"
   #include "apr_shmem.h"
  +#include "apr_lock.h"
  +#include "apr_portable.h"
   #include "apr_errno.h"
   
  +/*
  + * This is the Unix implementation of shared memory.
  + *
  + * Currently, this code supports the following shared memory techniques:
  + *
  + * - mmap on a temporary file
  + * - mmap/shm_open on a temporary file (POSIX.1)
  + * - mmap with MAP_ANON (4.4BSD)
  + * - mmap /dev/zero (SVR4)
  + * - shmget (SysV)
  + * - create_area (BeOS)
  + */
  +
  +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
  +#include <sys/mman.h>
  +#elif APR_USE_SHMEM_SHMGET
  +#include <sys/ipc.h>
  +#include <sys/shm.h>
  +#include <sys/file.h>
  +#elif APR_USE_SHMEM_BEOS
  +#include <kernel/OS.h>
  +#endif
  +
   struct shmem_t {
  -    MM *mm;
  +    void *mem;
  +    void *curmem;
  +    apr_size_t length;
  +    apr_lock_t *lock;
  +    char *filename;
  +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
  +    apr_file_t *file; 
  +#elif APR_USE_SHMEM_MMAP_ANON
  +    /* Nothing else. */
  +#elif APR_USE_SHMEM_SHMGET
  +    apr_os_file_t file;
  +#elif APR_USE_SHMEM_BEOS
  +    area_id areaid; 
  +#endif
   };
   
  -APR_DECLARE(apr_status_t) apr_shm_init(struct shmem_t **m, apr_size_t reqsize, const char *file, apr_pool_t *cont)
  +APR_DECLARE(apr_status_t) apr_shm_init(apr_shmem_t **m, apr_size_t reqsize, 
  +                                       const char *filename, apr_pool_t *pool)
   {
  -    MM *newmm = mm_create(reqsize + sizeof(**m), file, MM_ALLOCATE_ENOUGH);
  -    if (newmm == NULL) {
  -        return errno;
  -    }
  -    (*m) = mm_malloc(newmm, sizeof(struct shmem_t));
  -    /* important to check this; we may be locking a lock file for the first
  -     * time, which won't work if the file is on NFS
  -     */
  -    if (!*m) {
  -        return errno;
  +    apr_shmem_t *new_m;
  +    int tmpfd;
  +    void *mem;
  +
  +#if APR_USE_SHMEM_SHMGET
  +    struct shmid_ds shmbuf;
  +#else
  +    apr_status_t stat;
  +#endif
  +
  +    new_m = apr_palloc(pool, sizeof(apr_shmem_t));
  +    if (!new_m)
  +        return APR_ENOMEM;
  +
  +/* These implementations are very similar except for opening the file. */
  +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
  +    /* FIXME: Ignore error for now. *
  +     *stat = apr_file_remove(filename, pool);*/
  +    
  +#if APR_USE_SHMEM_MMAP_TMP
  +    /* FIXME: Is APR_OS_DEFAULT sufficient? */
  +    stat = apr_file_open(new_m->file, filename, 
  +                         APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT,
  +                         pool);
  +    if (stat != APR_SUCCESS)
  +        return APR_EGENERAL;
  +
  +    tmpfd = apr_os_file_get(&tmpfd, new_m->file);
  +    stat = apr_file_trunc(new_m->file, reqsize);
  +    if (stat != APR_SUCCESS)
  +        return APR_EGENERAL;
  +
  +#elif APR_USE_SHMEM_MMAP_SHM
  +    /* FIXME: Is APR_OS_DEFAULT sufficient? */
  +    tmpfd = shm_open(filename, O_RDWR | O_CREAT, APR_OS_DEFAULT);
  +    if (tmpfd == -1)
  +        return errno + APR_OS_START_SYSERR;
  +
  +    apr_os_file_put(new_m->file, &tmpfd, pool); 
  +    stat = apr_file_trunc(new_m->file, reqsize);
  +    if (stat != APR_SUCCESS)
  +    {
  +        shm_unlink(filename);
  +        return APR_EGENERAL;
       }
  -    (*m)->mm = newmm;
  +#elif APR_USE_SHMEM_MMAP_ZERO
  +    stat = apr_file_open(new_m->file, "/dev/zero", APR_READ | APR_WRITE, 
  +                         APR_OS_DEFAULT);
  +    if (stat != APR_SUCCESS)
  +        return APR_EGENERAL;
  +    tmpfd = apr_os_file_get(&tmpfd, new_m->file);
  +#endif
  +
  +    mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_SHARED, tmpfd, 0);
  +
  +#elif APR_USE_SHMEM_MMAP_ANON
  +    mem = mmap(NULL, reqsize, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
  +#elif APR_USE_SHMEM_SHMGET
  +    tmpfd = shmget(IPC_PRIVATE, reqsize, (SHM_R|SHM_W|IPC_CREAT));
  +    if (tmpfd == -1)
  +        return errno + APR_OS_START_SYSERR;
  +
  +    new_m->file = tmpfd;
  +
  +    mem = shmat(new_m->file, NULL, 0);
  +
  +    /* FIXME: Handle errors. */
  +    if (shmctl(new_m->file, IPC_STAT, &shmbuf) == -1)
  +        return errno + APR_OS_START_SYSERR;
  +
  +    apr_current_userid(&shmbuf.shm_perm.uid, &shmbuf.shm_perm.gid, pool);
  +
  +    if (shmctl(new_m->file, IPC_SET, &shmbuf) == -1)
  +        return errno + APR_OS_START_SYSERR;
  +
  +#elif APR_USE_SHMEM_BEOS
  +    new_m->area_id = create_area("mm", (void*)&mem, B_ANY_ADDRESS, reqsize, 
  +                                 B_LAZY_LOCK, B_READ_AREA|B_WRITE_AREA);
  +    /* FIXME: error code? */
  +    if (new_m->area_id < 0)
  +        return APR_EGENERAL;
  +
  +#endif
  +
  +    new_m->mem = mem;
  +    new_m->curmem = mem;
  +    new_m->length = reqsize;
  +
  +    apr_lock_create(&new_m->lock, APR_MUTEX, APR_CROSS_PROCESS, NULL, pool);
  +    if (!new_m->lock)
  +        return APR_EGENERAL;
  +
  +    *m = new_m; 
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_destroy(struct shmem_t *m)
  +APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shmem_t *m)
   {
  -    mm_destroy(m->mm);
  +#if APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM || APR_USE_SHMEM_MMAP_ZERO
  +    munmap(m->mem);
  +    apr_file_close(m->file);
  +#elif APR_USE_SHMEM_MMAP_ANON
  +    munmap(m->mem);
  +#elif APR_USE_SHMEM_SHMGET
  +    shmdt(m->mem);
  +#elif APR_USE_SHMEM_BEOS
  +    delete_area(new_m->area_id);
  +#endif
  +
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(void *) apr_shm_malloc(struct shmem_t *c, apr_size_t reqsize)
  +APR_DECLARE(void *) apr_shm_malloc(apr_shmem_t *m, apr_size_t reqsize)
   {
  -    if (c->mm == NULL) {
  -        return NULL;
  +    void *new;
  +    new = NULL;
  +
  +    apr_lock_acquire(m->lock);
  +    /* Do we have enough space? */
  +    if ((m->curmem - m->mem + reqsize) <= m->length)
  +    {
  +        new = m->curmem;
  +        m->curmem += reqsize;
       }
  -    return mm_malloc(c->mm, reqsize);
  +    apr_lock_release(m->lock);
  +    return new;
   }
   
  -APR_DECLARE(void *) apr_shm_calloc(struct shmem_t *shared, apr_size_t size) 
  +APR_DECLARE(void *) apr_shm_calloc(apr_shmem_t *m, apr_size_t reqsize) 
   {
  -    if (shared == NULL) {
  -        return NULL;
  -    }
  -    return mm_calloc(shared->mm, 1, size);
  +    void *new = apr_shm_malloc(m, reqsize);
  +    memset(new, '\0', reqsize);
  +    return new;
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_free(struct shmem_t *shared, void *entity)
  +APR_DECLARE(apr_status_t) apr_shm_free(apr_shmem_t *shared, void *entity)
   {
  -    mm_free(shared->mm, entity);
  +    /* Without a memory management scheme within our shared memory, it
  +     * is impossible to implement free. */
       return APR_SUCCESS;
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, apr_shm_name_t **name)
  +APR_DECLARE(apr_status_t) apr_shm_name_get(apr_shmem_t *c, 
  +                                           apr_shm_name_t **name)
   {
   #if APR_USES_ANONYMOUS_SHM
       *name = NULL;
  @@ -121,7 +259,8 @@
   #endif
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, apr_shm_name_t *name)
  +APR_DECLARE(apr_status_t) apr_shm_name_set(apr_shmem_t *c, 
  +                                           apr_shm_name_t *name)
   {
   #if APR_USES_ANONYMOUS_SHM
       return APR_ANONYMOUS;
  @@ -135,12 +274,12 @@
   #endif
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_open(struct shmem_t *c)
  +APR_DECLARE(apr_status_t) apr_shm_open(apr_shmem_t *c)
   {
   #if APR_USES_ANONYMOUS_SHM
   
  -/* When using MM, we don't need to open shared memory segments in child
  - * segments, so just return immediately.
  +/* we don't need to open shared memory segments in child segments, so 
  + * just return immediately.
    */
       return APR_SUCCESS;
   /* Currently, we are not supporting name based shared memory on Unix
  @@ -153,11 +292,18 @@
   #endif
   }
   
  -APR_DECLARE(apr_status_t) apr_shm_avail(struct shmem_t *c, apr_size_t *size)
  +APR_DECLARE(apr_status_t) apr_shm_avail(apr_shmem_t *m, apr_size_t *size)
   {
  -    *size = mm_available(c);
  -    if (*size == 0) {
  -        return APR_ENOSHMAVAIL;
  -    }
  -    return APR_SUCCESS;
  +    apr_status_t stat;
  +
  +    stat = APR_ENOSHMAVAIL;
  +
  +    apr_lock_acquire(m->lock);
  +
  +    *size = m->length - (m->curmem - m->mem);
  +    if (*size)
  +        stat = APR_SUCCESS;
  +
  +    apr_lock_release(m->lock);
  +    return stat;
   }
  
  
  
  1.65      +1 -2      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- Makefile.in	2001/08/02 21:07:04	1.64
  +++ Makefile.in	2001/08/13 21:49:08	1.65
  @@ -35,8 +35,7 @@
   # bring in rules.mk for standard functionality
   @INCLUDE_RULES@
   
  -LOCAL_LIBS=../libapr.la @LOCAL_MM_LIB@
  -##../shmem/unix/mm/libmm.la
  +LOCAL_LIBS=../libapr.la
   
   CLEAN_TARGETS = testfile.tmp testdso@EXEEXT@ mod_test.so
   
  
  
  
  1.20      +37 -72    apr/test/testshmem.c
  
  Index: testshmem.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testshmem.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- testshmem.c	2001/05/01 02:03:20	1.19
  +++ testshmem.c	2001/08/13 21:49:08	1.20
  @@ -85,7 +85,7 @@
           apr_sleep(0);
           test = boxes[boxnum].msgavail;
       }    
  -    fprintf(stdout, "\nreceived a message in box %d, message was: %s\n", 
  +    fprintf(stdout, "received a message in box %d, message was: %s\n", 
               boxnum, boxes[boxnum].msg); 
   }
   
  @@ -145,7 +145,7 @@
       printf("Smallest allocation will be %" APR_SIZE_T_FMT " bytes\n", 
              psize[0]);
       printf("Largest allocation will be  %" APR_SIZE_T_FMT " bytes\n", 
  -           psize[CYCLES -1]);
  +           psize[CYCLES - 1]);
       printf("I will be doing it in %d steps\n", CYCLES);
       
       printf("\tAllocating via apr_shm_malloc...............");
  @@ -167,45 +167,35 @@
       }
       printf("OK\n");
   
  -    printf("\tAllocating via apr_shm_calloc...............");
  -    for (cntr = CYCLES-1;cntr > -1;cntr--){
  -        ptrs[cntr] = apr_shm_malloc(shm, psize[cntr]);
  -        if (ptrs[cntr] == NULL){
  -            printf("Failed at %" APR_SIZE_T_FMT" bytes\n", 
  -                   psize[cntr]);
  -            exit (-1);
  -        }
  -    }
  -    printf("OK\n\tFreeing.....................................");
  -    for (cntr = 0;cntr < CYCLES;cntr++){
  -        if (apr_shm_free(shm, ptrs[cntr]) != APR_SUCCESS){
  -            printf("Failed at step %d, %" APR_SIZE_T_FMT 
  -                   " bytes\n", cntr, psize[cntr]);
  -            exit (-1);
  -        }
  -    }
  -    printf("OK\n");
  -
  -    printf("Checking we have all we should have remaining.......");
  +    printf("\tDetermining how much space is remaining.....");
       rv = apr_shm_avail(shm, &cksize);
       if (rv == APR_ENOTIMPL){
  -        printf("Not Impl.\n");
  +        printf("Not Impl.");
       } else {
           if (rv != APR_SUCCESS){
               printf("Failed!\n");
               exit (-1);
  -        }
  -        if (cksize == (TESTSIZE - size)){
  -            printf ("OK\n");
  -        } else {
  -            printf ("Failed.\nShould have had %" APR_SIZE_T_FMT 
  -                    " bytes, instead there are %"
  -                    APR_SIZE_T_FMT " bytes :(\n",
  -                    TESTSIZE - size, cksize);
  -            exit(-1);
           }
  +        printf("%" APR_SIZE_T_FMT, cksize);
  +    }
  +    printf("\n\t%d cycles of malloc and calloc passed.", CYCLES);
  +
  +    printf("\n\nClearing shmem segment..............................");
  +    rv = apr_shm_destroy(shm);
  +    if (rv != APR_SUCCESS)
  +    {
  +        printf("Failed\n");
  +        exit(-1);
  +    }
  +    printf("OK\n");
  +
  +    printf("Recreating shared memory block (%" APR_SIZE_T_FMT " bytes)......", 
  +           TESTSIZE); 
  +    if (apr_shm_init(&shm, TESTSIZE, NULL, context) != APR_SUCCESS) { 
  +        fprintf(stderr, "Error allocating shared memory block\n");
  +        exit(-1);
       }
  -    printf("%d cycles of malloc and calloc passed.\n\n", CYCLES);
  +    fprintf(stdout, "OK\n");
   
       printf("Block test.\n");
       printf("\tI am about to allocate %" APR_SIZE_T_FMT 
  @@ -223,49 +213,24 @@
       }
       printf ("OK\n");
       
  -    printf ("\tAbout to allocate %d blocks of %d bytes....", CYCLES, SIZE);
  -    for (cntr = 0;cntr < CYCLES;cntr++){
  -        if ((ptrs[cntr] = apr_shm_malloc(shm, SIZE)) == NULL){
  -            printf("Failed.\n");
  -            printf("Couldn't allocate block %d\n", cntr + 1);
  -            exit (-1);
  -        }
  -    }
  -    printf("Complete.\n");
  -
  -    printf ("\tAbout to free %d blocks of %d bytes........", CYCLES, SIZE);
  -    for (cntr = 0;cntr < CYCLES;cntr++){
  -        if ((rv = apr_shm_free(shm, ptrs[cntr])) != APR_SUCCESS){
  -            printf("Failed\n");
  -            printf("Counldn't free block %d\n", cntr + 1);
  -            exit (-1);
  -        }
  +    printf("Clearing shmem segment..............................");
  +    rv = apr_shm_destroy(shm);
  +    if (rv != APR_SUCCESS)
  +    {
  +        printf("Failed\n");
  +        exit(-1);
       }
  -    printf("Complete.\n");
  +    printf("OK\n");
   
  -    printf("Checking we have all we should have remaining.......");
  -    rv = apr_shm_avail(shm, &cksize);
  -    if (rv == APR_ENOTIMPL){
  -        printf("Not Impl.\n");
  -    } else {
  -        if (rv != APR_SUCCESS){
  -            printf("Failed!\n");
  -            exit (-1);
  -        }
  -        if (cksize == (TESTSIZE - size)){
  -            printf ("OK\n");
  -        } else {
  -            printf ("Failed.\nShould have had %"
  -                    APR_SIZE_T_FMT " bytes, instead there are %"
  -                    APR_SIZE_T_FMT " bytes :(\n",
  -                    TESTSIZE - size, cksize);
  -            exit(-1);
  -        }
  +    printf("Recreating shared memory block (%" APR_SIZE_T_FMT " bytes)......", 
  +           TESTSIZE); 
  +    if (apr_shm_init(&shm, TESTSIZE, NULL, context) != APR_SUCCESS) { 
  +        fprintf(stderr, "Error allocating shared memory block\n");
  +        exit(-1);
       }
  +    fprintf(stdout, "OK\n");
   
  -    printf("Block test complete.\n\n");
  -             
  -    printf("Creating a child process\n");
  +    printf("Shared Process Test (child/parent)\n");
       pid = fork();
       if (pid == 0) {
           apr_sleep(1);
  
  
  

Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ryan Bloom <rb...@covalent.net>.

That's easy.

cd httpd-2.0/srclib/apr/shmem/unix/mm
cvs rm -f *
cvs commit


Done!

Don't try to remove the ,v's from the Attic, those files are required for APR
to be able to build from tags.

Ryan

On Monday 13 August 2001 15:10, Justin Erenkrantz wrote:
> On Mon, Aug 13, 2001 at 03:00:31PM -0700, Ryan Bloom wrote:
> > YEAH!!!!!!!!
> >
> > No, let's just remove MM!!!!
>
> You can figure out the best way to remove MM from CVS.  =)
>
> Compiling on Linux now.  I'm guessing there is going to be some thinkos
> in this code, but hey, let's find 'em now before we tag again.
> -- justin

-- 

______________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Mon, Aug 13, 2001 at 03:24:13PM -0700, Ian Holsman wrote:
> you might want to use the code you are using to test the shared memory
> routines to the APR/test 
> that way other people can test it on all the other unixes.

When I committed my changes, I also updated the testshmem.c as well 
to respect the fact that apr_shm_free may be a no-op.

That said, Linux is segfaulting right now.  Trying to figure out why.
-- justin


Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ian Holsman <ia...@cnet.com>.
please ignore the previous email.

On 13 Aug 2001 15:24:13 -0700, Ian Holsman wrote:
> On 13 Aug 2001 15:10:46 -0700, Justin Erenkrantz wrote:
> > On Mon, Aug 13, 2001 at 03:00:31PM -0700, Ryan Bloom wrote:
> > > 
> > > YEAH!!!!!!!!
> > > 
> > > No, let's just remove MM!!!!
> > 
> > You can figure out the best way to remove MM from CVS.  =)
> > 
> > Compiling on Linux now.  I'm guessing there is going to be some thinkos
> > in this code, but hey, let's find 'em now before we tag again.  
> 
> you might want to use the code you are using to test the shared memory
> routines to the APR/test 
> that way other people can test it on all the other unixes.
> 
> 
> > -- justin
> -- 
> Ian Holsman          IanH@cnet.com
> Performance Measurement & Analysis
> CNET Networks   -   (415) 364-8608
-- 
Ian Holsman          IanH@cnet.com
Performance Measurement & Analysis
CNET Networks   -   (415) 364-8608


Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ian Holsman <ia...@cnet.com>.
On 13 Aug 2001 15:10:46 -0700, Justin Erenkrantz wrote:
> On Mon, Aug 13, 2001 at 03:00:31PM -0700, Ryan Bloom wrote:
> > 
> > YEAH!!!!!!!!
> > 
> > No, let's just remove MM!!!!
> 
> You can figure out the best way to remove MM from CVS.  =)
> 
> Compiling on Linux now.  I'm guessing there is going to be some thinkos
> in this code, but hey, let's find 'em now before we tag again.  

you might want to use the code you are using to test the shared memory
routines to the APR/test 
that way other people can test it on all the other unixes.


> -- justin
-- 
Ian Holsman          IanH@cnet.com
Performance Measurement & Analysis
CNET Networks   -   (415) 364-8608


Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Justin Erenkrantz <je...@ebuilt.com>.
On Mon, Aug 13, 2001 at 03:00:31PM -0700, Ryan Bloom wrote:
> 
> YEAH!!!!!!!!
> 
> No, let's just remove MM!!!!

You can figure out the best way to remove MM from CVS.  =)

Compiling on Linux now.  I'm guessing there is going to be some thinkos
in this code, but hey, let's find 'em now before we tag again.  
-- justin


Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ryan Bloom <rb...@covalent.net>.
On Monday 13 August 2001 15:00, Ryan Bloom wrote:
> YEAH!!!!!!!!
>
> No, let's just remove MM!!!!

s/No/Now/

Ryan

>
> Ryan
>
> On Monday 13 August 2001 14:49, jerenkrantz@apache.org wrote:
> > jerenkrantz    01/08/13 14:49:09
> >
> >   Modified:    .        CHANGES acconfig.h configure.in
> >                include  apr.h.in
> >                shmem/unix Makefile.in shmem.c
> >                test     Makefile.in testshmem.c
> >   Log:
> >   Move the necessary shared memory code from MM into APR and remove our
> >   dependency upon MM.  (This commit does not delete the MM files - they
> >   are still there for the time being.)
>
> ______________________________________________________________
> Ryan Bloom                        	rbb@apache.org
> Covalent Technologies			rbb@covalent.net
> --------------------------------------------------------------

-- 

______________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ryan Bloom <rb...@covalent.net>.
On Monday 13 August 2001 15:00, Ryan Bloom wrote:
> YEAH!!!!!!!!
>
> No, let's just remove MM!!!!

s/No/Now/

Ryan

>
> Ryan
>
> On Monday 13 August 2001 14:49, jerenkrantz@apache.org wrote:
> > jerenkrantz    01/08/13 14:49:09
> >
> >   Modified:    .        CHANGES acconfig.h configure.in
> >                include  apr.h.in
> >                shmem/unix Makefile.in shmem.c
> >                test     Makefile.in testshmem.c
> >   Log:
> >   Move the necessary shared memory code from MM into APR and remove our
> >   dependency upon MM.  (This commit does not delete the MM files - they
> >   are still there for the time being.)
>
> ______________________________________________________________
> Ryan Bloom                        	rbb@apache.org
> Covalent Technologies			rbb@covalent.net
> --------------------------------------------------------------

-- 

______________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ryan Bloom <rb...@covalent.net>.
YEAH!!!!!!!!

No, let's just remove MM!!!!

Ryan


On Monday 13 August 2001 14:49, jerenkrantz@apache.org wrote:
> jerenkrantz    01/08/13 14:49:09
>
>   Modified:    .        CHANGES acconfig.h configure.in
>                include  apr.h.in
>                shmem/unix Makefile.in shmem.c
>                test     Makefile.in testshmem.c
>   Log:
>   Move the necessary shared memory code from MM into APR and remove our
>   dependency upon MM.  (This commit does not delete the MM files - they
>   are still there for the time being.)

______________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------

Re: cvs commit: apr/test Makefile.in testshmem.c

Posted by Ryan Bloom <rb...@covalent.net>.
YEAH!!!!!!!!

No, let's just remove MM!!!!

Ryan


On Monday 13 August 2001 14:49, jerenkrantz@apache.org wrote:
> jerenkrantz    01/08/13 14:49:09
>
>   Modified:    .        CHANGES acconfig.h configure.in
>                include  apr.h.in
>                shmem/unix Makefile.in shmem.c
>                test     Makefile.in testshmem.c
>   Log:
>   Move the necessary shared memory code from MM into APR and remove our
>   dependency upon MM.  (This commit does not delete the MM files - they
>   are still there for the time being.)

______________________________________________________________
Ryan Bloom                        	rbb@apache.org
Covalent Technologies			rbb@covalent.net
--------------------------------------------------------------