Skip to content

Commit

Permalink
Enable GVL unlocking per default and rename it
Browse files Browse the repository at this point in the history
Option --disable-gvl-unlock is more understandable.

Benchmarks didn't show a measurable difference between unlocking enabled/disabled, so keeping it enabled is safer.
Should there still be any blocking function calls, GVL unlocking allows to run ruby threads in parallel.
  • Loading branch information
larskanis committed Sep 20, 2021
1 parent 7fe6dac commit 6b4cd3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
ENV['PATH'] = "#{pgdir}/bin" + File::PATH_SEPARATOR + ENV['PATH']
end

if enable_config("nogvl")
$defs.push( "-DENABLE_NOGVL" )
if enable_config("gvl-unlock", true)
$defs.push( "-DENABLE_GVL_UNLOCK" )
$stderr.puts "Calling libpq with GVL unlocked"
else
$stderr.puts "Calling libpq with GVL locked"
end

if enable_config("windows-cross")
Expand Down
4 changes: 2 additions & 2 deletions ext/gvl_wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm){return NULL;}
#endif

#ifdef ENABLE_NOGVL
#ifdef ENABLE_GVL_UNLOCK
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_SKELETON );
#endif
FOR_EACH_BLOCKING_FUNCTION( DEFINE_GVL_STUB );
#ifdef ENABLE_NOGVL
#ifdef ENABLE_GVL_UNLOCK
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVL_WRAPPER_STRUCT );
FOR_EACH_CALLBACK_FUNCTION( DEFINE_GVLCB_SKELETON );
#endif
Expand Down
4 changes: 2 additions & 2 deletions ext/gvl_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
return NULL; \
}

#ifdef ENABLE_NOGVL
#ifdef ENABLE_GVL_UNLOCK
#define DEFINE_GVL_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
Expand Down Expand Up @@ -78,7 +78,7 @@
return NULL; \
}

#ifdef ENABLE_NOGVL
#ifdef ENABLE_GVL_UNLOCK
#define DEFINE_GVLCB_STUB(name, when_non_void, rettype, lastparamtype, lastparamname) \
rettype gvl_##name(FOR_EACH_PARAM_OF_##name(DEFINE_PARAM_LIST3) lastparamtype lastparamname){ \
struct gvl_wrapper_##name##_params params = { \
Expand Down

0 comments on commit 6b4cd3f

Please sign in to comment.