apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Kew <n...@webthing.com>
Subject Reducing #ifdef burden on APR applications
Date Sat, 20 Aug 2005 11:29:56 GMT
When writing APR applications, we sometimes need to make heavy
use of APR #ifdefs.

A case in point is mod_dbd, which uses either apr_reslist or a
single persistent connection according to whether APR_HAS_THREADS.
As an APR application, this would be greatly simplified if
apr_reslist fell back to a trivial implementation of a single
resource in the non-threaded case, sparing the application
the burden of dealing with it.

There are a number of APR modules that could do this, to the
benefit of applications.  A trivial case to illustrate is
apr_thread_mutex, where the change is merely:

Index: include/apr_thread_mutex.h
===================================================================
--- include/apr_thread_mutex.h  (revision 233161)
+++ include/apr_thread_mutex.h  (working copy)
@@ -99,6 +99,13 @@
   */
  APR_POOL_DECLARE_ACCESSOR(thread_mutex);

+#else /* APR_HAS_THREADS */
+/* Stubs for unthreaded APR, so applications don't have to use #ifdef */
+#define apr_thread_mutex_create(mutex,flags,pool)
+#define apr_thread_mutex_lock(mutex)
+#define apr_thread_mutex_trylock(mutex)
+#define apr_thread_mutex_unlock(mutex)
+#define apr_thread_mutex_destroy(mutex)
  #endif /* APR_HAS_THREADS */

  /** @} */


Anyone object to this kind of update?

-- 
Nick Kew

Mime
View raw message