[#28561] Ruby::DL vs Ruby::FFI — Aston <blackapache512-ticket@...>

Ruby.DL and FFI libraries are great for programmers like me who are not internet programmers, but are more interested in scientific and number processing etc.

11 messages 2010/03/08

[#28686] trunk (26947) build fail with msys/mingw/vista — Jon <jon.forums@...>

I get the following build failure when msysgit's "c:\git\cmd" dir is on PATH.

8 messages 2010/03/16

[#28687] [Bug #2973] rb_bug - Segmentation fault - error.c:213 — rudolf gavlas <redmine@...>

Bug #2973: rb_bug - Segmentation fault - error.c:213

10 messages 2010/03/16

[#28735] [Bug #2982] Ruby tries to link with both openssl and readline — Lucas Nussbaum <redmine@...>

Bug #2982: Ruby tries to link with both openssl and readline

16 messages 2010/03/18

[#28736] [Bug #2983] Ruby (GPLv2 only) tries to link to with readline (now GPLv3) — Lucas Nussbaum <redmine@...>

Bug #2983: Ruby (GPLv2 only) tries to link to with readline (now GPLv3)

10 messages 2010/03/18

[#28907] [Bug #3000] Open SSL Segfaults — Christian Höltje <redmine@...>

Bug #3000: Open SSL Segfaults

19 messages 2010/03/23

[#28924] [Bug #3005] Ruby core dump - [BUG] rb_sys_fail() - errno == 0 — Sebastian YEPES <redmine@...>

Bug #3005: Ruby core dump - [BUG] rb_sys_fail() - errno == 0

10 messages 2010/03/24

[#28954] [Feature #3010] slow require gems in ruby 1.9.1 — Miao Jiang <redmine@...>

Feature #3010: slow require gems in ruby 1.9.1

15 messages 2010/03/24

[#29179] [Bug #3071] Convert rubygems and rdoc to use psych — Aaron Patterson <redmine@...>

Bug #3071: Convert rubygems and rdoc to use psych

10 messages 2010/03/31

[ruby-core:28952] Re: st.c: pool allocator for tables and entries

From: Eric Wong <normalperson@...>
Date: 2010-03-24 19:31:30 UTC
List: ruby-core #28952
Aaron Patterson <aaron@tenderlovemaking.com> wrote:
> On Wed, Mar 24, 2010 at 07:43:56PM +0900, NARUSE, Yui wrote:
> > (2010/03/22 17:05), Eric Wong wrote:
> > >This assumes st.c is only called inside GVL, and GVL == GIL which is
> > >true these days in 1.9.1 and trunk.
> > 
> > st.c is used not only from GC, but by other extensions.
> > 
> > I don't know whether st.h is public API or not.
> > But if a library uses st_table in multi thread way,
> > it will break when st_table become thread unsafe.
> 
> FWIW, Nokogiri uses st.h.

st.h seems public, at least there are several extensions that use it,
too (json, rcov, ruby-prof) but very few of them release GVL, so they
should all be safe.

Combining thread-safety good malloc performance is a lot of work, I
would just defer to the malloc implementation (like tcmalloc) if
thread-safety is a concern.

I not sure if this patch series is suitable for ruby itself, which
is why I'm putting them here first for discussion (and not Redmine).

diff --git a/st.c b/st.c
index 54ebee9..c9a5bba 100644
--- a/st.c
+++ b/st.c
@@ -7,6 +7,7 @@
 #include "st.h"
 #else
 #include "ruby/ruby.h"
+#include "vm_core.h"
 #endif
 
 #include <stdio.h>
@@ -38,6 +39,22 @@ struct st_table_entry {
      *
      */
 
+/*
+ * assume USE_VALUE_CACHE means we care about thread-safety
+ */
+#if USE_VALUE_CACHE
+/* thread-safety, defer to slower malloc() implementation */
+#define DEFINE_ALLOC_POOL(name,type,size) \
+static inline type *alloc_##name(void) \
+{ \
+    return ruby_xmalloc(sizeof(type)); \
+} \
+static inline void release_##name(void *ptr) \
+{ \
+    ruby_xfree(ptr); \
+}
+#else
+/* not thread-safe, but faster if st.h users don't release GVL */
 #if __GNUC__ >= 3
 #define UNLIKELY(x) (__builtin_expect((x), 0))
 #else /* __GNUC__ >= 3 */
@@ -83,6 +100,7 @@ static void release_##name(void *ptr) \
     tmp->as.next = name##_head ? name##_head : NULL; \
     name##_head = tmp; \
 }
+#endif
 
 DEFINE_ALLOC_POOL(entry, struct st_table_entry, 0x2000);
 DEFINE_ALLOC_POOL(table, struct st_table, 0x2000);
-- 
Eric Wong

In This Thread