httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r729921 - in /httpd/httpd/trunk/modules/mem: mod_plainmem.c mod_sharedmem.c sharedmem_util.c sharedmem_util.h slotmem.h
Date Mon, 29 Dec 2008 15:55:58 GMT
Author: jim
Date: Mon Dec 29 07:55:58 2008
New Revision: 729921

URL: http://svn.apache.org/viewvc?rev=729921&view=rev
Log:
implement mutex control from shared memory... plain memory not
done yet... wonder if we should even do/include it?

Also looking at cleaning up the struct... do we really need
the sharedslotdesc element??

Modified:
    httpd/httpd/trunk/modules/mem/mod_plainmem.c
    httpd/httpd/trunk/modules/mem/mod_sharedmem.c
    httpd/httpd/trunk/modules/mem/sharedmem_util.c
    httpd/httpd/trunk/modules/mem/sharedmem_util.h
    httpd/httpd/trunk/modules/mem/slotmem.h

Modified: httpd/httpd/trunk/modules/mem/mod_plainmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_plainmem.c?rev=729921&r1=729920&r2=729921&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_plainmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_plainmem.c Mon Dec 29 07:55:58 2008
@@ -18,13 +18,6 @@
  * This one uses plain memory.
  */
 
-#include "apr.h"
-#include "apr_pools.h"
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_log.h"
-
 #include  "slotmem.h"
 
 struct ap_slotmem {

Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=729921&r1=729920&r2=729921&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Mon Dec 29 07:55:58 2008
@@ -18,20 +18,69 @@
  * This one uses shared memory.
  */
 
-#include "apr.h"
-#include "apr_pools.h"
-#include "apr_shm.h"
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_log.h"
-
 #include  "slotmem.h"
 #include "sharedmem_util.h"
 
-/* make sure the shared memory is cleaned */
-static int initialize_cleanup(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec
*s)
+/* 
+ * Create the shared mem mutex and
+ * make sure the shared memory is cleaned
+ */
+static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 {
+    const char *temp_dir;
+    char *template;
+    apr_status_t rv;
+    void *data;
+    apr_file_t *fmutex;
+    const char *userdata_key = "sharedmem_post_config";
+
+    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
+    if (!data) {
+        apr_pool_userdata_set((const void *)1, userdata_key,
+                               apr_pool_cleanup_null, s->process->pool);
+        return OK;
+    }
+
+    rv = apr_temp_dir_get(&temp_dir, p);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "sharedmem: search for temporary directory failed");
+        return rv;
+    }
+    apr_filepath_merge(&template, temp_dir, "sharedmem.lck.XXXXXX",
+                       APR_FILEPATH_NATIVE, p);
+    rv = apr_file_mktemp(&fmutex, template, 0, p);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "sharedmem: creation of mutex file in directory %s failed",
+                     temp_dir);
+        return rv;
+    }
+
+    rv = apr_file_name_get(&mutex_fname, fmutex);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "sharedmem: unable to get mutex fname");
+        return rv;
+    }
+
+    rv = apr_global_mutex_create(&sharedmem_mutex,
+                                 mutex_fname, APR_LOCK_DEFAULT, p);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "sharedmem: creation of mutex failed");
+        return rv;
+    }
+
+#ifdef AP_NEED_SET_MUTEX_PERMS
+    rv = ap_unixd_set_global_mutex_perms(sharedmem_mutex);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "sharedmem: failed to set mutex permissions");
+        return rv;
+    }
+#endif
+
     sharedmem_initialize_cleanup(p);
     return OK;
 }
@@ -52,12 +101,27 @@
     return OK;
 }
 
+static void child_init(apr_pool_t *p, server_rec *s)
+{
+    apr_status_t rv;
+
+    rv = apr_global_mutex_child_init(&sharedmem_mutex,
+                                     mutex_fname, p);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+                     "Failed to initialise global mutex %s in child process %"
+                     APR_PID_T_FMT ".",
+                     mutex_fname, getpid());
+    }
+}
+
 static void ap_sharedmem_register_hook(apr_pool_t *p)
 {
     const slotmem_storage_method *storage = sharedmem_getstorage();
     ap_register_provider(p, SLOTMEM_STORAGE, "shared", "0", storage);
-    ap_hook_post_config(initialize_cleanup, NULL, NULL, APR_HOOK_LAST);
+    ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_LAST);
     ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_child_init(child_init, NULL, NULL, APR_HOOK_MIDDLE);
 }
 
 module AP_MODULE_DECLARE_DATA sharedmem_module = {

Modified: httpd/httpd/trunk/modules/mem/sharedmem_util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/sharedmem_util.c?rev=729921&r1=729920&r2=729921&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/sharedmem_util.c (original)
+++ httpd/httpd/trunk/modules/mem/sharedmem_util.c Mon Dec 29 07:55:58 2008
@@ -18,16 +18,6 @@
  * This one uses shared memory.
  */
 
-#include "apr.h"
-#include "apr_file_io.h"
-#include "apr_strings.h"
-#include "apr_pools.h"
-#include "apr_shm.h"
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_log.h"
-
 #include "slotmem.h"
 #include "sharedmem_util.h"
 
@@ -44,6 +34,7 @@
     apr_size_t size;
     int num;
     apr_pool_t *globalpool;
+    apr_global_mutex_t *sharedmem_mutex;
     struct ap_slotmem *next;
 };
 
@@ -247,6 +238,7 @@
     res->size = item_size;
     res->num = item_num;
     res->globalpool = globalpool;
+    res->sharedmem_mutex = sharedmem_mutex;
     res->next = NULL;
     if (globallistmem == NULL) {
 	globallistmem = res;
@@ -317,6 +309,7 @@
     res->size = desc.item_size;
     res->num = desc.item_num;
     res->globalpool = globalpool;
+    res->sharedmem_mutex = sharedmem_mutex;
     res->next = NULL;
     if (globallistmem == NULL) {
 	globallistmem = res;
@@ -330,19 +323,19 @@
     *item_num = desc.item_num;
     return APR_SUCCESS;
 }
-static apr_status_t ap_slotmem_mem(ap_slotmem_t *score, int id, void **mem)
+static apr_status_t ap_slotmem_mem(ap_slotmem_t *slot, int id, void **mem)
 {
 
     void *ptr;
 
-    if (!score) {
+    if (!slot) {
 	return APR_ENOSHMAVAIL;
     }
-    if (id < 0 || id > score->num) {
+    if (id < 0 || id > slot->num) {
 	return APR_ENOSHMAVAIL;
     }
 
-    ptr = score->base + score->size * id;
+    ptr = slot->base + slot->size * id;
     if (!ptr) {
 	return APR_ENOSHMAVAIL;
     }
@@ -350,11 +343,23 @@
     return APR_SUCCESS;
 }
 
+static apr_status_t ap_slotmem_lock(ap_slotmem_t *slot)
+{
+    return (apr_global_mutex_lock(slot->sharedmem_mutex));    
+}
+
+static apr_status_t ap_slotmem_unlock(ap_slotmem_t *slot)
+{
+    return (apr_global_mutex_unlock(slot->sharedmem_mutex));
+}
+
 static const slotmem_storage_method storage = {
     &ap_slotmem_do,
     &ap_slotmem_create,
     &ap_slotmem_attach,
-    &ap_slotmem_mem
+    &ap_slotmem_mem,
+    &ap_slotmem_lock,
+    &ap_slotmem_unlock
 };
 
 /* make the storage usuable from outside */

Modified: httpd/httpd/trunk/modules/mem/sharedmem_util.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/sharedmem_util.h?rev=729921&r1=729920&r2=729921&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/sharedmem_util.h (original)
+++ httpd/httpd/trunk/modules/mem/sharedmem_util.h Mon Dec 29 07:55:58 2008
@@ -20,3 +20,5 @@
 const slotmem_storage_method *sharedmem_getstorage(void);
 void sharedmem_initglobalpool(apr_pool_t *p);
 void sharedmem_initialize_cleanup(apr_pool_t *p);
+apr_global_mutex_t *sharedmem_mutex;
+const char *mutex_fname;

Modified: httpd/httpd/trunk/modules/mem/slotmem.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/slotmem.h?rev=729921&r1=729920&r2=729921&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/slotmem.h (original)
+++ httpd/httpd/trunk/modules/mem/slotmem.h Mon Dec 29 07:55:58 2008
@@ -28,15 +28,25 @@
  * @{
  */
 
+#include "httpd.h"
+#include "http_config.h"
+#include "http_log.h"
+#include "ap_provider.h"
+
 #include "apr.h"
 #include "apr_strings.h"
 #include "apr_pools.h"
 #include "apr_shm.h"
+#include "apr_global_mutex.h"
+#include "apr_file_io.h"
 
-#include "httpd.h"
-#include "http_config.h"
-#include "http_log.h"
-#include "ap_provider.h"
+#ifdef AP_NEED_SET_MUTEX_PERMS
+#include "unixd.h"
+#endif
+
+#if APR_HAVE_UNISTD_H
+#include <unistd.h>         /* for getpid() */
+#endif
 
 #define SLOTMEM_STORAGE "slotmem"
 
@@ -92,7 +102,21 @@
  * @param mem address to store the pointer to the slot
  * @return APR_SUCCESS if all went well
  */
-AP_DECLARE(apr_status_t) (* ap_slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem); 
+AP_DECLARE(apr_status_t) (* ap_slotmem_mem)(ap_slotmem_t *s, int item_id, void**mem);
+/**
+ * lock the memory segment
+ * NOTE: All slots share the same mutex
+ * @param s ap_slotmem_t to use
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) (* ap_slotmem_lock)(ap_slotmem_t *s);
+/**
+ * unlock the memory segment
+ * NOTE: All slots share the same mutex
+ * @param s ap_slotmem_t to use.
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) (* ap_slotmem_unlock)(ap_slotmem_t *s);
 };
 
 typedef struct slotmem_storage_method slotmem_storage_method;



Mime
View raw message