apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Reid <dr...@jetnet.co.uk>
Subject [PATCH] pools are sms
Date Sat, 07 Jul 2001 17:00:50 GMT
Folks,

Well, here is the patch that I promised a while back.  It basically adds
wrappers so that pools are implemented as SMS.

Basically we add a new file, apr_sms_pools.c, add the configure switch
--enable-sms to switch this mode on and move some stuff around in
apr_pools.h to make the wrapping possible with as few #ifdef's as
possible.

Attached to this mail are the files involved and I've inlined the diff
for those who prefer that.

Now a few points you should consider...

- this is the first time that sms has been pushed in any signiicant
manner.  It has shown some problems and some strengths very clearly, but
it does demonstrate to me that a lot more work is needed.  Basically we
need a lot more pairs of eyes looking at the code and trying to find the
problems, then fixing them.  I have no illusions that a lot of people on
this forum have a LOT to offer and hopefully they will :)
- this is slow, but works.
- locking isn't fully implemented, but because of the way the threaded
MPM's actually work it'll run them without more locking code, alebit
with increased risk of it all blowing up :)
- this has been built on FreeBSD/prefork, Linux/prefork & threaded and
beos to date.  YMMV :)
- it's not as memory hungry as it was in a previous patch, but that'll
need to be looked at.
- Sander & I have some ideas already about how to improve the speed, but
to be honest wemay be too close to the code and so fresh eyes are good.
- this doesn't stop the build as is and I've just built apache using
both sms and pools code with no problems.

Well, enjoy.  I'm off to Phoenix in the afternoon so will try to get
enough connectivity there to follow any replies as well as looking
before I leave home :)

david

Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.330
diff -u -r1.330 configure.in
--- configure.in        2001/07/07 07:17:32     1.330
+++ configure.in        2001/07/07 16:46:26
@@ -148,6 +148,17 @@
    fi
 ])dnl

+POOLS_TARGET=apr_pools.lo
+AC_ARG_ENABLE(sms, [ --enable-sms Build APR to use sms emulating
pools],
+    echo "*************   WARNING   ***************"
+    echo "You have switched ON using SMS to emulate pools.  This is
highly"
+    echo "experimental and so you may want to think about it!"
+    echo "Presently this option is only advised for people working on
SMS"
+    APR_ADDTO(CFLAGS, -DAPR_POOLS_ARE_SMS)
+    POOLS_TARGET=apr_sms_pools.lo
+)
+AC_SUBST(POOLS_TARGET)
+
 AC_ARG_ENABLE(assert-memory,[ --enable-assert-memory  Turn on asserts
in the APR memory code],
   [APR_ADDTO(NOTEST_CPPFLAGS,-DAPR_ASSERT_MEMORY)
 ])
Index: include/apr_pools.h
===================================================================
RCS file: /home/cvs/apr/include/apr_pools.h,v
retrieving revision 1.50
diff -u -r1.50 apr_pools.h
--- include/apr_pools.h 2001/06/13 16:10:16     1.50
+++ include/apr_pools.h 2001/07/07 16:46:33
@@ -55,6 +55,10 @@
 #ifndef APR_POOLS_H
 #define APR_POOLS_H

+#ifdef APR_POOLS_ARE_SMS
+#include "apr_sms.h"
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -91,11 +95,13 @@
 #define APR_POOL_DEBUG
 */

+#ifndef APR_POOLS_ARE_SMS
 /** The fundamental pool type */
 typedef struct apr_pool_t apr_pool_t;

 /** A function that is called when allocation fails. */
 typedef int (*apr_abortfunc_t)(int retcode);
+#endif /* !APR_POOLS_ARE_SMS */

 /**
  * @defgroup PoolDebug Pool Debugging functions.
@@ -214,6 +220,7 @@
 APR_DECLARE(apr_status_t) apr_pool_create(apr_pool_t **newcont,
                                           apr_pool_t *cont);

+#if !defined(APR_POOLS_ARE_SMS) || defined(DOXYGEN)
 /**
  * Set the function to be called when an allocation failure occurs.
  * @tip If the program wants APR to exit on a memory allocation error,
@@ -273,17 +280,6 @@
                                            apr_pool_t *cont);

 /**
- * Make a sub pool from the current pool
- * @param p The pool to use as a parent pool
- * @param apr_abort A function to use if the pool cannot allocate more
memory.
- * @return The new sub-pool
- * @remark The @a apr_abort function provides a way to quit the program
if the
- *      machine is out of memory.  By default, APR will return on
error.
- */
-APR_DECLARE(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p,
-                                            int (*apr_abort)(int
retcode));
-
-/**
  * Clear all memory in the pool and run all the cleanups. This also
clears all
  * subpools.
  * @param p The pool to clear
@@ -301,20 +297,6 @@
 APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);

 /**
- * Report the number of bytes currently in the pool
- * @param p The pool to inspect
- * @param recurse Recurse/include the subpools' sizes
- * @return The number of bytes
- */
-APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);

-
-/**
- * Report the number of bytes currently in the list of free blocks
- * @return The number of bytes
- */
-APR_DECLARE(apr_size_t) apr_pool_free_blocks_num_bytes(void);
-
-/**
  * Allocate a block of memory from a pool
  * @param c The pool to allocate from
  * @param reqsize The amount of memory to allocate
@@ -330,7 +312,36 @@
  */
 APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);

+#endif /* !APR_POOLS_ARE_SMS || DOXYGEN */
+
+/**
+ * Make a sub pool from the current pool
+ * @param p The pool to use as a parent pool
+ * @param apr_abort A function to use if the pool cannot allocate more
memory.
+ * @return The new sub-pool
+ * @remark The @a apr_abort function provides a way to quit the program
if the
+ *      machine is out of memory.  By default, APR will return on
error.
+ */
+APR_DECLARE(apr_pool_t *) apr_pool_sub_make(apr_pool_t *p,
+                                            int (*apr_abort)(int
retcode));
+
+#if defined(APR_POOL_DEBUG) || defined(DOXYGEN)
+/**
+ * Report the number of bytes currently in the pool
+ * @param p The pool to inspect
+ * @param recurse Recurse/include the subpools' sizes
+ * @return The number of bytes
+ */
+APR_DECLARE(apr_size_t) apr_pool_num_bytes(apr_pool_t *p, int recurse);

+
 /**
+ * Report the number of bytes currently in the list of free blocks
+ * @return The number of bytes
+ */
+APR_DECLARE(apr_size_t) apr_pool_free_blocks_num_bytes(void);
+#endif
+
+/**
  * Register a function to be called when a pool is cleared or destroyed

  * @param p The pool register the cleanup with
  * @param data The data to pass to the cleanup function.
@@ -343,6 +354,7 @@
                                        apr_status_t
(*plain_cleanup)(void *),
                                        apr_status_t
(*child_cleanup)(void *));

+#if !defined(APR_POOLS_ARE_SMS) || defined(DOXYGEN)
 /**
  * Remove a previously registered cleanup function
  * @param p The pool remove the cleanup from
@@ -364,6 +376,14 @@
 APR_DECLARE(apr_status_t) apr_pool_cleanup_run(apr_pool_t *p, void
*data,
                                           apr_status_t (*cleanup)(void
*));

+/**
+ * An empty cleanup function
+ * @param data The data to cleanup
+ */
+APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
+
+#endif /* !APR_POOLS_ARE_SMS || DOXYGEN */
+
 /* Preparing for exec() --- close files, etc., but *don't* flush I/O
  * buffers, *don't* wait for subprocesses, and *don't* free any memory.

  */
@@ -373,12 +393,6 @@
  */
 APR_DECLARE(void) apr_pool_cleanup_for_exec(void);

-/**
- * An empty cleanup function
- * @param data The data to cleanup
- */
-APR_DECLARE_NONSTD(apr_status_t) apr_pool_cleanup_null(void *data);
-
 /*
  * Pool accessor functions.
  *
@@ -418,6 +432,37 @@
 # endif /* apr_pool_join */
 # define apr_pool_join(a,b)
 #endif /* APR_POOL_DEBUG */
+
+
+#ifdef APR_POOLS_ARE_SMS
+/* Add a number of defines where the sms equivalent is 1 to 1 */
+#define apr_pool_get_abort(p)                apr_sms_get_abort(p)
+#define apr_pool_set_abort(fn, p)            apr_sms_set_abort(fn, p)
+
+#define apr_pool_get_parent(p)               apr_sms_get_parent(p)
+
+#define apr_pool_userdata_set(d, k, c, p) \
+        apr_sms_userdata_set(d, k, c, p)
+#define apr_pool_userdata_get(d, k, p) \
+        apr_sms_userdata_get(d, k, p)
+
+#define apr_pool_cleanup_kill(p, d, c) \
+        apr_sms_cleanup_unregister(p, APR_ALL_CLEANUPS, d, c)
+#define apr_pool_cleanup_run(p, d, c) \
+        apr_sms_cleanup_run(p, APR_GENERAL_CLEANUP, d, c)
+
+/* we won't even bother to register these as they'll be ignored when
+ * we call the register fucntion
+ */
+#define apr_pool_cleanup_null                NULL
+
+/* The parameters match exactly for these, so just define them directly
*/
+#define apr_palloc       apr_sms_malloc
+#define apr_pcalloc      apr_sms_calloc
+#define apr_pool_clear   apr_sms_reset
+#define apr_pool_destroy apr_sms_destroy
+
+#endif /* APR_POOLS_ARE_SMS */

 #ifdef __cplusplus
 }
Index: include/apr_sms.h
===================================================================
RCS file: /home/cvs/apr/include/apr_sms.h,v
retrieving revision 1.35
diff -u -r1.35 apr_sms.h
--- include/apr_sms.h   2001/07/07 13:03:45     1.35
+++ include/apr_sms.h   2001/07/07 16:46:33
@@ -65,14 +65,18 @@

 #include "apr.h"
 #include "apr_errno.h"
+#ifndef APR_POOLS_ARE_SMS
 #include "apr_pools.h"
-#include "apr_lock.h"
-#include "apr_portable.h"
+#endif

 #ifdef __cplusplus
 extern "C" {
 #endif

+#ifdef APR_POOLS_ARE_SMS
+typedef struct apr_sms_t           apr_pool_t;
+typedef int (*apr_abortfunc_t)(int retcode);
+#endif

 /**********************************************************************

  ** Defines
Index: memory/unix/Makefile.in
===================================================================
RCS file: /home/cvs/apr/memory/unix/Makefile.in,v
retrieving revision 1.6
diff -u -r1.6 Makefile.in
--- memory/unix/Makefile.in     2001/07/07 07:17:32     1.6
+++ memory/unix/Makefile.in     2001/07/07 16:46:39
@@ -4,7 +4,7 @@
           apr_sms_tracking.lo \
           apr_sms_blocks.lo \
           apr_sms_trivial.lo \
-          apr_pools.lo
+          @POOLS_TARGET@

 # bring in rules.mk for standard functionality
 @INCLUDE_RULES@
Index: memory/unix/apr_sms.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
retrieving revision 1.46
diff -u -r1.46 apr_sms.c
--- memory/unix/apr_sms.c       2001/07/07 13:26:28     1.46
+++ memory/unix/apr_sms.c       2001/07/07 16:46:39
@@ -295,8 +295,12 @@
     sms->threads = 1;
 #endif /* APR_HAS_THREADS */

+#ifndef APR_POOLS_ARE_SMS
     /* XXX - This should eventually be removed */
     apr_pool_create(&sms->pool, pms ? pms->pool : NULL);
+#else
+    sms->pool = sms;
+#endif

     return APR_SUCCESS;
 }
@@ -610,8 +614,10 @@
     if (sms->sms_lock)
         apr_lock_destroy(sms->sms_lock);

+#ifndef APR_POOLS_ARE_SMS
     /* XXX - This should eventually be removed */
     apr_pool_destroy(sms->pool);
+#endif

     /* 1 - If we have a self destruct, use it */
     if (sms->destroy_fn)
@@ -905,7 +911,7 @@
 }
 #endif /* APR_HAS_THREADS */

-APR_DECLARE(const char*) apr_sms_identity(apr_sms_t *sms)
+APR_DECLARE(const char*) apr_sms_get_identity(apr_sms_t *sms)
 {
     return sms->identity;
 }
Index: memory/unix/sms_private.h
===================================================================
RCS file: /home/cvs/apr/memory/unix/sms_private.h,v
retrieving revision 1.6
diff -u -r1.6 sms_private.h
--- memory/unix/sms_private.h   2001/07/07 13:03:45     1.6
+++ memory/unix/sms_private.h   2001/07/07 16:46:39
@@ -96,6 +96,10 @@
     apr_status_t (*apr_abort)(int retcode);
     struct apr_hash_t *prog_data;

+#ifdef APR_POOLS_ARE_SMS
+    struct process_chain *subprocesses;
+#endif
+
 #if APR_HAS_THREADS
     apr_status_t (*thread_register_fn)   (apr_sms_t *sms,
                                           apr_os_thread_t thread);


Mime
View raw message