Module: wine Branch: master Commit: c889780c2f5ff8850acabc077ef8419a00d53f3f URL: https://source.winehq.org/git/wine.git/?a=commit;h=c889780c2f5ff8850acabc077...
Author: Zebediah Figura z.figura12@gmail.com Date: Wed Mar 28 21:01:57 2018 -0500
ole32: Simplify grabbing the MTA.
Signed-off-by: Zebediah Figura z.figura12@gmail.com Signed-off-by: Huw Davies huw@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ole32/compobj.c | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-)
diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 58b9835..fc8587b 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -717,6 +717,23 @@ static inline BOOL apartment_is_model(const APARTMENT *apt, DWORD model) return (apt->multi_threaded == !(model & COINIT_APARTMENTTHREADED)); }
+/* gets the multi-threaded apartment if it exists. The caller must + * release the reference from the apartment as soon as the apartment pointer + * is no longer required. */ +static APARTMENT *apartment_find_mta(void) +{ + APARTMENT *apt; + + EnterCriticalSection(&csApartment); + + if ((apt = MTA)) + apartment_addref(apt); + + LeaveCriticalSection(&csApartment); + + return apt; +} + static void COM_RevokeRegisteredClassObject(RegisteredClass *curClass) { list_remove(&curClass->entry); @@ -1295,31 +1312,6 @@ static APARTMENT *apartment_findmain(void) return result; }
-/* gets the multi-threaded apartment if it exists. The caller must - * release the reference from the apartment as soon as the apartment pointer - * is no longer required. */ -static APARTMENT *apartment_find_multi_threaded(void) -{ - APARTMENT *result = NULL; - struct list *cursor; - - EnterCriticalSection(&csApartment); - - LIST_FOR_EACH( cursor, &apts ) - { - struct apartment *apt = LIST_ENTRY( cursor, struct apartment, entry ); - if (apt->multi_threaded) - { - result = apt; - apartment_addref(result); - break; - } - } - - LeaveCriticalSection(&csApartment); - return result; -} - /* gets the specified class object by loading the appropriate DLL, if * necessary and calls the DllGetClassObject function for the DLL */ static HRESULT apartment_getclassobject(struct apartment *apt, LPCWSTR dllpath, @@ -3000,7 +2992,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoGetClassObject(
if (!(apt = COM_CurrentApt())) { - if (!(apt = apartment_find_multi_threaded())) + if (!(apt = apartment_find_mta())) { ERR("apartment not initialised\n"); return CO_E_NOTINITIALIZED; @@ -3300,7 +3292,7 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstanceEx(
if (!(apt = COM_CurrentApt())) { - if (!(apt = apartment_find_multi_threaded())) + if (!(apt = apartment_find_mta())) { ERR("apartment not initialised\n"); return CO_E_NOTINITIALIZED; @@ -5007,7 +4999,7 @@ HRESULT WINAPI CoGetContextToken( ULONG_PTR *token ) if (!info->apt) { APARTMENT *apt; - if (!(apt = apartment_find_multi_threaded())) + if (!(apt = apartment_find_mta())) { ERR("apartment not initialised\n"); return CO_E_NOTINITIALIZED;