From c6c2f7782e2270ee4684d2405376a186aa806fcd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 3 Dec 2010 17:27:53 -0800 Subject: add optional thread-safety on a per-object basis Thread-safety is useful sometimes and needless overhead otherwise. Default to whatever TDB upstream defaults to. --- ext/tdb/tdb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/tdb/tdb.c b/ext/tdb/tdb.c index a68c360..373da17 100644 --- a/ext/tdb/tdb.c +++ b/ext/tdb/tdb.c @@ -158,7 +158,7 @@ static VALUE nogvl_open(void *ptr) return (VALUE)tdb; } -static void set_args(struct open_args *o, VALUE opts) +static void set_args(VALUE self, struct open_args *o, VALUE opts) { VALUE tmp; @@ -203,6 +203,10 @@ static void set_args(struct open_args *o, VALUE opts) o->hash_fn = (tdb_hash_func)NUM2ULONG(num); } + + tmp = rb_hash_aref(opts, ID2SYM(rb_intern("threadsafe"))); + if (RTEST(tmp)) + rb_funcall(self, rb_intern("threadsafe!"), 0); } /* @@ -242,7 +246,7 @@ static VALUE init(int argc, VALUE *argv, VALUE self) if (tdb) rb_raise(rb_eRuntimeError, "TDB already initialized"); rb_scan_args(argc, argv, "11", &path, &opts); - set_args(&o, opts); + set_args(self, &o, opts); if (NIL_P(path)) o.tdb_flags |= TDB_INTERNAL; -- cgit v1.2.3-24-ge0c7