about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2018-07-16 19:47:38 +0000
committerEric Wong <e@80x24.org>2018-07-16 21:14:13 +0000
commit3c0e9cdd0ac240dbddeacc1f8ab261f9c1b23d25 (patch)
tree1b5ff95c892a1087146f52e99a12a7cc09d9b113
parentb7173a191ad477219b713cb5e3d2815ca8ab290f (diff)
downloadmwrap-3c0e9cdd0ac240dbddeacc1f8ab261f9c1b23d25.tar.gz
There's nothing a user can do about allocations which happen
in our constructor (aside from not using mwrap), so do not
track them.
-rw-r--r--ext/mwrap/mwrap.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ext/mwrap/mwrap.c b/ext/mwrap/mwrap.c
index 0a1f9b5..627bb63 100644
--- a/ext/mwrap/mwrap.c
+++ b/ext/mwrap/mwrap.c
@@ -61,6 +61,7 @@ static int resolving_malloc;
         } \
 } while (0)
 
+static __thread size_t locating;
 static size_t generation;
 static size_t page_size;
 static struct cds_lfht *totals;
@@ -91,6 +92,7 @@ lfht_new(void)
 __attribute__((constructor)) static void resolve_malloc(void)
 {
         int err;
+        ++locating;
 
 #ifdef __FreeBSD__
         /*
@@ -133,6 +135,7 @@ __attribute__((constructor)) static void resolve_malloc(void)
         if (err)
                 fprintf(stderr, "pthread_atfork failed: %s\n", strerror(err));
         page_size = sysconf(_SC_PAGESIZE);
+        --locating;
 }
 
 static void
@@ -162,8 +165,6 @@ my_mempcpy(void *dest, const void *src, size_t n)
 #define RETURN_ADDRESS(nr) \
   (uintptr_t)(__builtin_extract_return_addr(__builtin_return_address(nr)))
 
-static __thread size_t locating;
-
 #define INT2STR_MAX (sizeof(int) == 4 ? 10 : 19)
 static char *int2str(int num, char *dst, size_t * size)
 {
@@ -1013,7 +1014,10 @@ static VALUE src_loc_name(VALUE self)
  */
 void Init_mwrap(void)
 {
-        VALUE mod = rb_define_module("Mwrap");
+        VALUE mod;
+
+        ++locating;
+        mod = rb_define_module("Mwrap");
         id_uminus = rb_intern("-@");
 
         cSrcLoc = rb_define_class_under(mod, "SourceLocation", rb_cObject);
@@ -1029,6 +1033,7 @@ void Init_mwrap(void)
         rb_define_method(cSrcLoc, "mean_lifespan", src_loc_mean_lifespan, 0);
         rb_define_method(cSrcLoc, "max_lifespan", src_loc_max_lifespan, 0);
         rb_define_method(cSrcLoc, "name", src_loc_name, 0);
+        --locating;
 }
 
 /* rb_cloexec_open isn't usable by non-Ruby processes */