diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-18 02:23:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-18 02:23:37 +0000 |
commit | 588504b20f5cc880ad51827b93e571e32446e5db (patch) | |
tree | 7aa1d8e9a5e5ce06e48ff6857ae58f4204e65b56 /ext/win32ole | |
parent | 6a052813d013679a75469762d290e63d2efbc61c (diff) |
win32ole: OLE initialize per threads
* ext/win32ole/win32ole.c (ole_initialize): initialize OLE for each
threads. [Bug #2618] [ruby-core:27634]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/win32ole')
-rw-r--r-- | ext/win32ole/extconf.rb | 8 | ||||
-rw-r--r-- | ext/win32ole/win32ole.c | 45 |
2 files changed, 24 insertions, 29 deletions
diff --git a/ext/win32ole/extconf.rb b/ext/win32ole/extconf.rb index 1a17524d0a..52c3d6bdfb 100644 --- a/ext/win32ole/extconf.rb +++ b/ext/win32ole/extconf.rb @@ -23,6 +23,14 @@ def create_win32ole_makefile unless have_type("IMultiLanguage2", "mlang.h") have_type("IMultiLanguage", "mlang.h") end + spec = nil + checking_for('thread_specific', '%s') do + spec = %w[__declspec(thread) __thread].find {|th| + try_compile("#{th} int foo;", "", :werror => true) + } + spec or 'no' + end + $defs << "-DRB_THREAD_SPECIFIC=#{spec}" if spec create_makefile("win32ole") end end diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index c8a86e18d4..dcf0dd3497 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -214,7 +214,16 @@ VALUE cWIN32OLE_PROPERTY; static VALUE ary_ole_event; static ID id_events; -static BOOL g_ole_initialized = FALSE; +#ifdef RB_THREAD_SPECIFIC +static RB_THREAD_SPECIFIC BOOL g_ole_initialized; +# define g_ole_initialized_init() ((void)0) +# define g_ole_initialized_set(val) (g_ole_initialized = (val)) +#else +static volatile DWORD g_ole_initialized_key = TLS_OUT_OF_INDEXES; +# define g_ole_initialized (BOOL)TlsGetValue(g_ole_initialized_key) +# define g_ole_initialized_init() (g_ole_initialized_key = TlsAlloc()) +# define g_ole_initialized_set(val) TlsSetValue(g_ole_initialized_key, (void*)(val)) +#endif static BOOL g_cp_installed = FALSE; static BOOL g_lcid_installed = FALSE; static HINSTANCE ghhctrl = NULL; @@ -370,9 +379,7 @@ static BOOL CALLBACK installed_lcid_proc(LPTSTR str); static BOOL lcid_installed(LCID lcid); static VALUE fole_s_set_locale(VALUE self, VALUE vlcid); static VALUE fole_s_create_guid(VALUE self); -static void ole_pure_initialize(void); static VALUE fole_s_ole_initialize(VALUE self); -static void ole_pure_uninitialize(void); static VALUE fole_s_ole_uninitialize(VALUE self); static VALUE fole_initialize(int argc, VALUE *argv, VALUE self); static VALUE hash2named_arg(VALUE pair, struct oleparam* pOp); @@ -1204,7 +1211,7 @@ void ole_uninitialize(void) { OleUninitialize(); - g_ole_initialized = FALSE; + g_ole_initialized_set(FALSE); } static void @@ -1217,13 +1224,8 @@ ole_initialize(void) if(FAILED(hr)) { ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize"); } - g_ole_initialized = TRUE; - /* - * In some situation, OleUninitialize does not work fine. ;-< - */ - /* - atexit((void (*)(void))ole_uninitialize); - */ + g_ole_initialized_set(TRUE); + hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter); if(FAILED(hr)) { previous_filter = NULL; @@ -3141,27 +3143,11 @@ fole_s_create_guid(VALUE self) * You must not use thease method. */ -static void -ole_pure_initialize(void) -{ - HRESULT hr; - hr = OleInitialize(NULL); - if(FAILED(hr)) { - ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize"); - } -} - -static void -ole_pure_uninitialize(void) -{ - OleUninitialize(); -} - /* :nodoc */ static VALUE fole_s_ole_initialize(VALUE self) { - ole_pure_initialize(); + ole_initialize(); return Qnil; } @@ -3169,7 +3155,7 @@ fole_s_ole_initialize(VALUE self) static VALUE fole_s_ole_uninitialize(VALUE self) { - ole_pure_uninitialize(); + ole_uninitialize(); return Qnil; } @@ -9080,6 +9066,7 @@ free_enc2cp(void) void Init_win32ole(void) { + g_ole_initialized_init(); ary_ole_event = rb_ary_new(); rb_gc_register_mark_object(ary_ole_event); id_events = rb_intern("events"); |