From fcdc6337cfd4d408a55f3dcb20696957c99fded5 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Thu, 28 Aug 2008 17:10:04 -0600 Subject: [PATCH] add in ability to make queries on 1.9 absolutely simultaneously--currently broken, however--feel free to help out--currently the master branch is faster --- ext/Makefile | 166 ------------------------------------------------- ext/extconf.rb | 5 ++ ext/mysql.c | 28 ++++++++- 3 files changed, 32 insertions(+), 167 deletions(-) delete mode 100644 ext/Makefile diff --git a/ext/Makefile b/ext/Makefile deleted file mode 100644 index cac97bb..0000000 --- a/ext/Makefile +++ /dev/null @@ -1,166 +0,0 @@ - -SHELL = /bin/sh - -#### Start of system configuration section. #### - -srcdir = . -topdir = /usr/local/include/ruby-1.9.0 -hdrdir = /usr/local/include/ruby-1.9.0 -arch_hdrdir = /usr/local/include/ruby-1.9.0/$(arch) -VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby -prefix = $(DESTDIR)/usr/local -exec_prefix = $(prefix) -bindir = $(exec_prefix)/bin -sbindir = $(exec_prefix)/sbin -libexecdir = $(exec_prefix)/libexec -datarootdir = $(prefix)/share -datadir = $(datarootdir) -sysconfdir = $(prefix)/etc -sharedstatedir = $(prefix)/com -localstatedir = $(prefix)/var -includedir = $(prefix)/include -oldincludedir = $(DESTDIR)/usr/include -docdir = $(datarootdir)/doc/$(PACKAGE) -infodir = $(datarootdir)/info -htmldir = $(docdir) -dvidir = $(docdir) -pdfdir = $(docdir) -psdir = $(docdir) -libdir = $(exec_prefix)/lib -localedir = $(datarootdir)/locale -mandir = $(datarootdir)/man -sitedir = $(prefix)/lib/ruby/site_ruby -vendordir = $(prefix)/lib/ruby/vendor_ruby -rubyhdrdir = $(includedir)/ruby-$(MAJOR).$(MINOR).$(TEENY) -sitehdrdir = $(rubyhdrdir)/site_ruby -vendorhdrdir = $(rubyhdrdir)/vendor_ruby -rubylibdir = $(libdir)/ruby/$(ruby_version) -archdir = $(rubylibdir)/$(arch) -sitelibdir = $(sitedir)/$(ruby_version) -sitearchdir = $(sitelibdir)/$(sitearch) -vendorlibdir = $(vendordir)/$(ruby_version) -vendorarchdir = $(vendorlibdir)/$(sitearch) - -CC = gcc -CXX = g++ -LIBRUBY = $(LIBRUBY_A) -LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a -LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir) -LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -OUTFLAG = -o -COUTFLAG = -o - -RUBY_EXTCONF_H = -CFLAGS = -fPIC -g -O2 $(cflags) -INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir) -I$(srcdir) -DEFS = -D_FILE_OFFSET_BITS=64 -CPPFLAGS = -DHAVE_MYSQL_SSL_SET -DHAVE_RB_STR_SET_LEN -DHAVE_MYSQL_MYSQL_H -I/usr/local/include $(DEFS) $(cppflags) -CXXFLAGS = $(CFLAGS) -g -O2 -ldflags = -L. -rdynamic -Wl,-export-dynamic -dldflags = -archflag = -DLDFLAGS = $(ldflags) $(dldflags) $(archflag) -LDSHARED = $(CC) -shared -LDSHAREDXX = $(CXX) -shared -AR = ar -EXEEXT = - -RUBY_INSTALL_NAME = ruby -RUBY_SO_NAME = ruby -arch = i686-linux -sitearch = i686-linux -ruby_version = 1.9.0 -ruby = /usr/local/bin/ruby -RUBY = $(ruby) -RM = rm -f -MAKEDIRS = mkdir -p -INSTALL = /usr/bin/install -c -INSTALL_PROG = $(INSTALL) -m 0755 -INSTALL_DATA = $(INSTALL) -m 644 -COPY = cp - -#### End of system configuration section. #### - -preload = - -libpath = . $(libdir) /usr/local/lib -LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib -Wl,-R/usr/local/lib -DEFFILE = - -CLEANFILES = mkmf.log -DISTCLEANFILES = - -extout = -extout_prefix = -target_prefix = -LOCAL_LIBS = -LIBS = -lmysqlclient -lpthread -lrt -ldl -lcrypt -lm -lc -SRCS = mysql.c -OBJS = mysql.o -TARGET = mysqlplus -DLLIB = $(TARGET).so -EXTSTATIC = -STATIC_LIB = - -RUBYCOMMONDIR = $(sitedir)$(target_prefix) -RUBYLIBDIR = $(sitelibdir)$(target_prefix) -RUBYARCHDIR = $(sitearchdir)$(target_prefix) -HDRDIR = $(rubyhdrdir)/ruby$(target_prefix) -ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix) - -TARGET_SO = $(DLLIB) -CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map -CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak - -all: $(DLLIB) -static: $(STATIC_LIB) - -clean: - @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) - -distclean: clean - @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log - @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) - -realclean: distclean -install: install-so install-rb - -install-so: $(RUBYARCHDIR) -install-so: $(RUBYARCHDIR)/$(DLLIB) -$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) - $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR) -install-rb: pre-install-rb install-rb-default -install-rb-default: pre-install-rb-default -pre-install-rb: Makefile -pre-install-rb-default: Makefile -$(RUBYARCHDIR): - $(MAKEDIRS) $@ - -site-install: site-install-so site-install-rb -site-install-so: install-so -site-install-rb: install-rb - -.SUFFIXES: .c .m .cc .cxx .cpp .C .o - -.cc.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cxx.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cpp.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.C.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.c.o: - $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< - -$(DLLIB): $(OBJS) - @-$(RM) $(@) - $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) - - - -$(OBJS): ruby.h defines.h diff --git a/ext/extconf.rb b/ext/extconf.rb index bc00612..848cb19 100644 --- a/ext/extconf.rb +++ b/ext/extconf.rb @@ -67,4 +67,9 @@ File.open('error_const.h', 'w') do |f| end end +# check for 1.9 +if have_func('rb_thread_blocking_region') and have_macro('RB_UBF_DFL', 'ruby.h') + $CFLAGS += " -DHAVE_TBR" +end + create_makefile("mysql") diff --git a/ext/mysql.c b/ext/mysql.c index 765cfde..19f91d0 100644 --- a/ext/mysql.c +++ b/ext/mysql.c @@ -683,11 +683,37 @@ static VALUE my_stat(VALUE obj) return rb_tainted_str_new2(s); } +typedef struct +{ + MYSQL *mysql_instance; + MYSQL_RES **store_it_here; + +} mysql_result_to_here_t, + *shared_stuff_p; + +static VALUE store_result_to_location(void *settings_in) +{ + mysql_result_to_here_t *settings = (mysql_result_to_here_t *) settings_in; + *(settings->store_it_here) = mysql_store_result(settings->mysql_instance); // this one runs a good long while for very large queries + return Qnil; +} + /* store_result() */ static VALUE store_result(VALUE obj) { MYSQL* m = GetHandler(obj); - MYSQL_RES* res = mysql_store_result(m); + MYSQL_RES* res = NULL; +#ifndef HAVE_TBR + res = mysql_store_result(m); + //store_result_to_location(m, &res); +#else + mysql_result_to_here_t linker; + linker.mysql_instance = m; + linker.store_it_here = &res; + //store_result_to_location((void *) &linker); + rb_thread_blocking_region(store_result_to_location, (void *) &linker, RB_UBF_DFL, 0); +#endif + if (res == NULL) mysql_raise(m); return mysqlres2obj(res);