about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-12-10 01:55:16 +0000
committerEric Wong <mwrap-perl@80x24.org>2022-12-10 02:09:26 +0000
commitdd7f0f6218561d132f9d7450d9b27bdce7096460 (patch)
treeb4b25e5e40f02365268c982be4aeca71ee5be80c
parentfc7c66c1ebe28920f4232b6ac1234089cd090380 (diff)
downloadmwrap-dd7f0f6218561d132f9d7450d9b27bdce7096460.tar.gz
It'll be used for the C HTTP server.
-rw-r--r--Mwrap.xs20
-rw-r--r--mwrap_core.h23
2 files changed, 24 insertions, 19 deletions
diff --git a/Mwrap.xs b/Mwrap.xs
index 0c00914..9f105c6 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -130,26 +130,8 @@ CLEANUP:
 
 void
 mwrap_reset()
-PREINIT:
-        struct cds_lfht *t;
-        struct cds_lfht_iter iter;
-        struct src_loc *l;
 CODE:
-        uatomic_set(&total_bytes_inc, 0);
-        uatomic_set(&total_bytes_dec, 0);
-
-        rcu_read_lock();
-        t = CMM_LOAD_SHARED(totals);
-        if (t)
-                cds_lfht_for_each_entry(t, &iter, l, hnode) {
-                        uatomic_set(&l->total, 0);
-                        uatomic_set(&l->allocations, 0);
-                        uatomic_set(&l->frees, 0);
-                        uatomic_set(&l->freed_bytes, 0);
-                        uatomic_set(&l->age_total, 0);
-                        uatomic_set(&l->max_lifespan, 0);
-                }
-        rcu_read_unlock();
+        mwrap_reset();
 
 Devel::Mwrap::SrcLoc
 mwrap_get(loc)
diff --git a/mwrap_core.h b/mwrap_core.h
index f2d5a09..730699a 100644
--- a/mwrap_core.h
+++ b/mwrap_core.h
@@ -835,6 +835,29 @@ out:
         --locating;
 }
 
+static void mwrap_reset(void)
+{
+        struct cds_lfht *t;
+        struct cds_lfht_iter iter;
+        struct src_loc *l;
+
+        uatomic_set(&total_bytes_inc, 0);
+        uatomic_set(&total_bytes_dec, 0);
+
+        rcu_read_lock();
+        t = CMM_LOAD_SHARED(totals);
+        if (t)
+                cds_lfht_for_each_entry(t, &iter, l, hnode) {
+                        uatomic_set(&l->total, 0);
+                        uatomic_set(&l->allocations, 0);
+                        uatomic_set(&l->frees, 0);
+                        uatomic_set(&l->freed_bytes, 0);
+                        uatomic_set(&l->age_total, 0);
+                        uatomic_set(&l->max_lifespan, 0);
+                }
+        rcu_read_unlock();
+}
+
 __attribute__((constructor)) static void mwrap_ctor(void)
 {
         sigset_t set, old;