From 3ddd85b5918dc51165b4352e813b4577cd3ee62c Mon Sep 17 00:00:00 2001 From: mahlon Date: Thu, 1 May 2025 00:54:21 +0000 Subject: [PATCH] Cleanup thread-safe work, bump version. FossilOrigin-Name: 2d0770a550c41261b3bc7e54aaeb02809ca991e92f25c71f5864cda9d873fc27 --- History.md | 8 ++++++++ ext/mdbx_ext/database.c | 14 ++++---------- ext/mdbx_ext/mdbx_ext.h | 2 +- lib/mdbx.rb | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/History.md b/History.md index af7ff52..672e07e 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,13 @@ # Release History for MDBX +--- +## v0.4.0 [2025-04-30] Mahlon E. Smith + +Enhancements: + +- Opening a long running transaction is now thread safe. + + --- ## v0.3.8 [2025-02-20] Mahlon E. Smith diff --git a/ext/mdbx_ext/database.c b/ext/mdbx_ext/database.c index 63a8707..e3dc64f 100644 --- a/ext/mdbx_ext/database.c +++ b/ext/mdbx_ext/database.c @@ -465,27 +465,21 @@ rmdbx_in_transaction_p( VALUE self ) } +/* Inline struct for transaction arguments, passed as a void pointer. */ struct txn_open_args_s { rmdbx_db_t *db; int rwflag; }; -/* Opens a transaction outside of th GVL. */ +/* Opens a transaction outside of the GVL. */ void * rmdbx_open_txn_without_gvl( void *ptr ) { - // struct query_call *qcall = (struct query_call *)ptr; struct txn_open_args_s *txn_open_args = (struct txn_open_args_s *)ptr; rmdbx_db_t *db = txn_open_args->db; - - int rc = mdbx_txn_begin( - db->env, - NULL, - txn_open_args->rwflag, - &db->txn - ); + int rc = mdbx_txn_begin( db->env, NULL, txn_open_args->rwflag, &db->txn ); return (void *)rc; } @@ -508,7 +502,7 @@ rmdbx_open_txn( rmdbx_db_t *db, int rwflag ) void *result_ptr = rb_thread_call_without_gvl( rmdbx_open_txn_without_gvl, (void *)&txn_open_args, - NULL, NULL + RUBY_UBF_IO, NULL ); int rc = (int)result_ptr; diff --git a/ext/mdbx_ext/mdbx_ext.h b/ext/mdbx_ext/mdbx_ext.h index 99376f7..43a5d45 100644 --- a/ext/mdbx_ext/mdbx_ext.h +++ b/ext/mdbx_ext/mdbx_ext.h @@ -1,9 +1,9 @@ #include +#include #include "extconf.h" #include "mdbx.h" -#include "ruby/thread.h" #ifndef RBMDBX_EXT #define RBMDBX_EXT diff --git a/lib/mdbx.rb b/lib/mdbx.rb index 04d0df5..bd0b1b4 100644 --- a/lib/mdbx.rb +++ b/lib/mdbx.rb @@ -13,7 +13,7 @@ module MDBX extend Loggability # The version of this gem. - VERSION = '0.3.8' + VERSION = '0.4.0' log_as :mdbx