[Kernel] Initialize COM on all new XThreads.

This commit is contained in:
gibbed 2019-04-19 04:02:32 -05:00
parent 4030cff3ec
commit 18d8a59cfa
2 changed files with 19 additions and 0 deletions

View File

@ -124,6 +124,7 @@ int Main() {
// Setup COM on the main thread. // Setup COM on the main thread.
// NOTE: this may fail if COM has already been initialized - that's OK. // NOTE: this may fail if COM has already been initialized - that's OK.
#pragma warning(suppress : 6031)
CoInitializeEx(nullptr, COINIT_MULTITHREADED); CoInitializeEx(nullptr, COINIT_MULTITHREADED);
// Initialize logging. Needs parsed FLAGS. // Initialize logging. Needs parsed FLAGS.

View File

@ -13,6 +13,10 @@
#include <cstring> #include <cstring>
#ifdef XE_PLATFORM_WIN32
#include <objbase.h>
#endif
#include "xenia/base/byte_stream.h" #include "xenia/base/byte_stream.h"
#include "xenia/base/clock.h" #include "xenia/base/clock.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
@ -374,6 +378,20 @@ X_STATUS XThread::Create() {
// Set name immediately, if we have one. // Set name immediately, if we have one.
thread_->set_name(thread_name_); thread_->set_name(thread_name_);
#ifdef XE_PLATFORM_WIN32
// Setup COM on this thread.
//
// https://devblogs.microsoft.com/oldnewthing/?p=4613
//
// "If any thread in the process calls CoInitialize[Ex] with the
// COINIT_MULTITHREADED flag, then that not only initializes the current
// thread as a member of the multi-threaded apartment, but it also says,
// "Any thread which has never called CoInitialize[Ex] is also part of the
// multi-threaded apartment."
#pragma warning(suppress : 6031)
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
#endif
// Profiler needs to know about the thread. // Profiler needs to know about the thread.
xe::Profiler::ThreadEnter(thread_name_.c_str()); xe::Profiler::ThreadEnter(thread_name_.c_str());