@@ -193,7 +193,7 @@ static void rb_mysql_client_mark(void * wrapper) {
193
193
mysql_client_wrapper * w = wrapper ;
194
194
if (w ) {
195
195
rb_gc_mark (w -> encoding );
196
- rb_gc_mark (w -> active_thread );
196
+ rb_gc_mark (w -> active_fiber );
197
197
}
198
198
}
199
199
@@ -297,7 +297,7 @@ static void *nogvl_close(void *ptr) {
297
297
mysql_close (wrapper -> client );
298
298
wrapper -> closed = 1 ;
299
299
wrapper -> reconnect_enabled = 0 ;
300
- wrapper -> active_thread = Qnil ;
300
+ wrapper -> active_fiber = Qnil ;
301
301
}
302
302
303
303
return NULL ;
@@ -342,7 +342,7 @@ static VALUE allocate(VALUE klass) {
342
342
mysql_client_wrapper * wrapper ;
343
343
obj = Data_Make_Struct (klass , mysql_client_wrapper , rb_mysql_client_mark , rb_mysql_client_free , wrapper );
344
344
wrapper -> encoding = Qnil ;
345
- wrapper -> active_thread = Qnil ;
345
+ wrapper -> active_fiber = Qnil ;
346
346
wrapper -> automatic_close = 1 ;
347
347
wrapper -> server_version = 0 ;
348
348
wrapper -> reconnect_enabled = 0 ;
@@ -543,7 +543,7 @@ static VALUE do_send_query(VALUE args) {
543
543
mysql_client_wrapper * wrapper = query_args -> wrapper ;
544
544
if ((VALUE )rb_thread_call_without_gvl (nogvl_send_query , query_args , RUBY_UBF_IO , 0 ) == Qfalse ) {
545
545
/* an error occurred, we're not active anymore */
546
- wrapper -> active_thread = Qnil ;
546
+ wrapper -> active_fiber = Qnil ;
547
547
rb_raise_mysql2_error (wrapper );
548
548
}
549
549
return Qnil ;
@@ -573,7 +573,7 @@ static void *nogvl_do_result(void *ptr, char use_result) {
573
573
574
574
/* once our result is stored off, this connection is
575
575
ready for another command to be issued */
576
- wrapper -> active_thread = Qnil ;
576
+ wrapper -> active_fiber = Qnil ;
577
577
578
578
return result ;
579
579
}
@@ -599,13 +599,13 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
599
599
GET_CLIENT (self );
600
600
601
601
/* if we're not waiting on a result, do nothing */
602
- if (NIL_P (wrapper -> active_thread ))
602
+ if (NIL_P (wrapper -> active_fiber ))
603
603
return Qnil ;
604
604
605
605
REQUIRE_CONNECTED (wrapper );
606
606
if ((VALUE )rb_thread_call_without_gvl (nogvl_read_query_result , wrapper -> client , RUBY_UBF_IO , 0 ) == Qfalse ) {
607
607
/* an error occurred, mark this connection inactive */
608
- wrapper -> active_thread = Qnil ;
608
+ wrapper -> active_fiber = Qnil ;
609
609
rb_raise_mysql2_error (wrapper );
610
610
}
611
611
@@ -618,7 +618,7 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
618
618
619
619
if (result == NULL ) {
620
620
if (mysql_errno (wrapper -> client ) != 0 ) {
621
- wrapper -> active_thread = Qnil ;
621
+ wrapper -> active_fiber = Qnil ;
622
622
rb_raise_mysql2_error (wrapper );
623
623
}
624
624
/* no data and no error, so query was not a SELECT */
@@ -645,7 +645,7 @@ struct async_query_args {
645
645
static VALUE disconnect_and_raise (VALUE self , VALUE error ) {
646
646
GET_CLIENT (self );
647
647
648
- wrapper -> active_thread = Qnil ;
648
+ wrapper -> active_fiber = Qnil ;
649
649
650
650
/* Invalidate the MySQL socket to prevent further communication.
651
651
* The GC will come along later and call mysql_close to free it.
@@ -710,7 +710,7 @@ static VALUE disconnect_and_mark_inactive(VALUE self) {
710
710
GET_CLIENT (self );
711
711
712
712
/* Check if execution terminated while result was still being read. */
713
- if (!NIL_P (wrapper -> active_thread )) {
713
+ if (!NIL_P (wrapper -> active_fiber )) {
714
714
if (CONNECTED (wrapper )) {
715
715
/* Invalidate the MySQL socket to prevent further communication. */
716
716
#ifndef _WIN32
@@ -725,24 +725,24 @@ static VALUE disconnect_and_mark_inactive(VALUE self) {
725
725
}
726
726
/* Skip mysql client check performed before command execution. */
727
727
wrapper -> client -> status = MYSQL_STATUS_READY ;
728
- wrapper -> active_thread = Qnil ;
728
+ wrapper -> active_fiber = Qnil ;
729
729
}
730
730
731
731
return Qnil ;
732
732
}
733
733
734
- void rb_mysql_client_set_active_thread (VALUE self ) {
735
- VALUE thread_current = rb_thread_current ();
734
+ static void rb_mysql_client_set_active_fiber (VALUE self ) {
735
+ VALUE fiber_current = rb_fiber_current ();
736
736
GET_CLIENT (self );
737
737
738
738
// see if this connection is still waiting on a result from a previous query
739
- if (NIL_P (wrapper -> active_thread )) {
739
+ if (NIL_P (wrapper -> active_fiber )) {
740
740
// mark this connection active
741
- wrapper -> active_thread = thread_current ;
742
- } else if (wrapper -> active_thread == thread_current ) {
741
+ wrapper -> active_fiber = fiber_current ;
742
+ } else if (wrapper -> active_fiber == fiber_current ) {
743
743
rb_raise (cMysql2Error , "This connection is still waiting for a result, try again once you have the result" );
744
744
} else {
745
- VALUE inspect = rb_inspect (wrapper -> active_thread );
745
+ VALUE inspect = rb_inspect (wrapper -> active_fiber );
746
746
const char * thr = StringValueCStr (inspect );
747
747
748
748
rb_raise (cMysql2Error , "This connection is in use by: %s" , thr );
@@ -806,7 +806,7 @@ static VALUE rb_mysql_query(VALUE self, VALUE sql, VALUE current) {
806
806
args .sql_len = RSTRING_LEN (args .sql );
807
807
args .wrapper = wrapper ;
808
808
809
- rb_mysql_client_set_active_thread (self );
809
+ rb_mysql_client_set_active_fiber (self );
810
810
811
811
#ifndef _WIN32
812
812
rb_rescue2 (do_send_query , (VALUE )& args , disconnect_and_raise , self , rb_eException , (VALUE )0 );
0 commit comments