Skip to content

Commit

Permalink
Remove thread_blocking_region and thread.h checks
Browse files Browse the repository at this point in the history
On 2.3+ upwards we don't need to check for
header presence as those headers are always
available. We can also unify and simplify
GVL lock/unlock to one set of functions.
  • Loading branch information
julik committed Mar 11, 2019
1 parent 12cc382 commit 39b2a3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
5 changes: 0 additions & 5 deletions ext/patron/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
$CFLAGS << ' -pedantic -Wall'
end

$defs.push("-DUSE_TBR")
$defs.push("-DHAVE_THREAD_H") if have_header('ruby/thread.h')
$defs.push("-DHAVE_TBR") if have_func('rb_thread_blocking_region', 'ruby.h')
$defs.push("-DHAVE_TCWOGVL") if have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')

create_makefile 'patron/session_ext'
31 changes: 5 additions & 26 deletions ext/patron/session_ext.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <ruby.h>
#if defined(USE_TBR) && defined(HAVE_THREAD_H)
#include <ruby/thread.h>
#endif
#include <sys/stat.h>
#include <curl/curl.h>
#include "membuffer.h"
Expand Down Expand Up @@ -103,15 +101,7 @@ static int session_progress_handler(void* clientp, size_t dltotal, size_t dlnow,
// `call_user_rb_progress_blk`. TODO: use the retval of that proc
// to permit premature abort
if(RTEST(state->user_progress_blk)) {
// Even though it is not documented, rb_thread_call_with_gvl is available even when
// rb_thread_call_without_gvl is not. See https://bugs.ruby-lang.org/issues/5543#note-4
// > rb_thread_call_with_gvl() is globally-visible (but not in headers)
// > for 1.9.3: https://bugs.ruby-lang.org/issues/4328
#if (defined(HAVE_TBR) || defined(HAVE_TCWOGVL)) && defined(USE_TBR)
rb_thread_call_with_gvl((void *(*)(void *)) call_user_rb_progress_blk, (void*)state);
#else
call_user_rb_progress_blk((void*)state);
#endif
rb_thread_call_with_gvl((void *(*)(void *)) call_user_rb_progress_blk, (void*)state);
}

// Set the interrupt if the download byte limit has been reached
Expand Down Expand Up @@ -809,21 +799,10 @@ static VALUE perform_request(VALUE self) {
curl_easy_setopt(curl, CURLOPT_WRITEDATA, body_buffer);
}

#if (defined(HAVE_TBR) || defined(HAVE_TCWOGVL)) && defined(USE_TBR)
#if defined(HAVE_TCWOGVL)
ret = (CURLcode) rb_thread_call_without_gvl(
(void *(*)(void *)) curl_easy_perform, curl,
session_ubf_abort, (void*)state
);
#else
ret = (CURLcode) rb_thread_blocking_region(
(rb_blocking_function_t*) curl_easy_perform, curl,
session_ubf_abort, (void*)state
);
#endif
#else
ret = curl_easy_perform(curl);
#endif
ret = (CURLcode) rb_thread_call_without_gvl(
(void *(*)(void *)) curl_easy_perform, curl,
session_ubf_abort, (void*)state
);

if (CURLE_OK == ret) {
VALUE header_str = membuffer_to_rb_str(header_buffer);
Expand Down

0 comments on commit 39b2a3c

Please sign in to comment.