Skip to content

Commit

Permalink
Remove make functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaanstra committed Mar 13, 2024
1 parent 9486d45 commit 2901891
Showing 1 changed file with 169 additions and 79 deletions.
248 changes: 169 additions & 79 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2007,27 +2007,32 @@ private static IObjectReference %
auto objrefname = w.write_temp("%", bind<write_objref_type_name>(staticsType));
w.write(R"(
private static volatile ObjectReference<%> __%;
private static ObjectReference<%> Make__%()
private static ObjectReference<%> %
{
global::System.Threading.Interlocked.CompareExchange(ref __%, ActivationFactory.Get<%>("%.%", %.IID), null);
return __%;
get
{
var factory = __%;
if (factory != null && factory.IsInCurrentContext)
{
return factory;
}
else
{
return __% = ActivationFactory.Get<%>("%.%", %.IID);
}
}
}
private static ObjectReference<%> % => __% ?? Make__%();
)",
vftblType,
objrefname,
vftblType,
objrefname,
objrefname,
objrefname,
vftblType,
classType.TypeNamespace(),
classType.TypeName(),
bind<write_type_name>(staticsType, typedef_name_type::StaticAbiClass, true),
objrefname,
vftblType,
objrefname,
objrefname,
objrefname);
bind<write_type_name>(staticsType, typedef_name_type::StaticAbiClass, true));
}
else
{
Expand Down Expand Up @@ -3828,18 +3833,29 @@ evt.Name());
{
w.write(R"(
private volatile static global::System.Runtime.CompilerServices.ConditionalWeakTable<object, EventSource<%>> _%_;
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<object, EventSource<%>> Make%Table()
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<object, EventSource<%>> _%
{
%
global::System.Threading.Interlocked.CompareExchange(ref _%_, new(), null);
return _%_;
get
{
var table = _%_;
if (table != null)
{
return table;
}
else
{
%
global::System.Threading.Interlocked.CompareExchange(ref _%_, new(), null);
return _%_;
}
}
}
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<object, EventSource<%>> _% => _%_ ?? Make%Table();
)",
bind<write_type_name>(get_type_semantics(evt.EventType()), typedef_name_type::Projected, false),
evt.Name(),
bind<write_type_name>(get_type_semantics(evt.EventType()), typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
bind([&](writer& w)
{
call(get_type_semantics(evt.EventType()),
Expand All @@ -3857,10 +3873,6 @@ private static global::System.Runtime.CompilerServices.ConditionalWeakTable<obje
[&](auto const&) {});
}),
evt.Name(),
evt.Name(),
bind<write_type_name>(get_type_semantics(evt.EventType()), typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
evt.Name());
}

Expand Down Expand Up @@ -6540,12 +6552,22 @@ prop.Name());

w.write(R"(
private volatile static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_tokenTables;
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> Make%Table()
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_TokenTables
{
global::System.Threading.Interlocked.CompareExchange(ref _%_tokenTables, new(), null);
return _%_tokenTables;
get
{
var tokenTables = _%_tokenTables;
if (tokenTables != null)
{
return tokenTables;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _%_tokenTables, new(), null);
return _%_tokenTables;
}
}
}
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_TokenTables => _%_tokenTables ?? Make%Table();
)",
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
Expand All @@ -6555,10 +6577,6 @@ private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, g
evt.Name(),
evt.Name(),
evt.Name(),
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
evt.Name());

w.write(
Expand Down Expand Up @@ -6636,26 +6654,31 @@ return __ex.HResult;

w.write(R"(
private volatile static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_tokenTables;
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> Make%TokenTable()
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_TokenTables
{
global::System.Threading.Interlocked.CompareExchange(ref _%_tokenTables, new(), null);
return _%_tokenTables;
}
private static global::System.Runtime.CompilerServices.ConditionalWeakTable<%, global::WinRT.EventRegistrationTokenTable<%>> _%_TokenTables => _%_tokenTables ?? Make%TokenTable();
)",
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
evt.Name(),
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
evt.Name());
get
{
var tokenTables = _%_tokenTables;
if (tokenTables != null)
{
return tokenTables;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _%_tokenTables, new(), null);
return _%_tokenTables;
}
}
})",
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
type_name,
bind<write_type_name>(semantics, typedef_name_type::Projected, false),
evt.Name(),
evt.Name(),
evt.Name(),
evt.Name());

w.write(R"(
public static global::WinRT.EventRegistrationToken Do_Abi_%(IntPtr thisPtr, % handler)
Expand Down Expand Up @@ -7357,20 +7380,39 @@ IObjectReference IWinRTObject.NativeObject => _inner;
bool IWinRTObject.HasUnwrappableNativeObject => true;
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> _queryInterfaceCache;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> MakeQueryInterfaceCache()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference>(), null);
return _queryInterfaceCache;
get
{
var cache = _queryInterfaceCache;
if (cache != null)
{
return cache;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new(), null);
return _queryInterfaceCache;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache();
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> _additionalTypeData;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> MakeAdditionalTypeData()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object>(), null);
return _additionalTypeData;
get
{
var typeData = _additionalTypeData;
if (typeData != null)
{
return typeData;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new(), null);
return _additionalTypeData;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData();
%
}
)",
Expand Down Expand Up @@ -7398,13 +7440,22 @@ global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, ob

w.write(R"(
private volatile IObjectReference __%;
private IObjectReference Make__%()
private IObjectReference %
{
%
global::System.Threading.Interlocked.CompareExchange(ref __%, ((IWinRTObject)this).NativeObject.As<IUnknownVftbl>(%.IID), null);
return __%;
get
{
var objRef = __%;
if (objRef != null)
{
return objRef;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref __%, ((IWinRTObject)this).NativeObject.As<IUnknownVftbl>(%.IID), null);
return __%;
}
}
}
private IObjectReference % => __% ?? Make__%();
)",
objrefname,
objrefname,
Expand All @@ -7419,10 +7470,8 @@ private IObjectReference % => __% ?? Make__%();
}
},
objrefname,
bind<write_type_name>(ifaceTypeSemantics, typedef_name_type::StaticAbiClass, false),
objrefname,
objrefname,
objrefname,
bind<write_type_name>(ifaceTypeSemantics, typedef_name_type::StaticAbiClass, false),
objrefname);

for_typedef(w, ifaceTypeSemantics, [&](auto type)
Expand Down Expand Up @@ -8576,19 +8625,40 @@ IObjectReference IWinRTObject.NativeObject => _inner;)");
{
w.write(R"(
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> _queryInterfaceCache;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> MakeQueryInterfaceCache()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference>(), null);
return _queryInterfaceCache;
get
{
var cache = _queryInterfaceCache;
if (cache != null)
{
return cache;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new(), null);
return _queryInterfaceCache;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache();
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> _additionalTypeData;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> MakeAdditionalTypeData()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object>(), null);
return _additionalTypeData;
get
{
var typeData = _additionalTypeData;
if (typeData != null)
{
return typeData;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new(), null);
return _additionalTypeData;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData();)");
)");
}
}),
bind([&](writer& w)
Expand Down Expand Up @@ -8849,19 +8919,39 @@ _nativeDelegate = nativeDelegate;
IObjectReference IWinRTObject.NativeObject => _nativeDelegate;
bool IWinRTObject.HasUnwrappableNativeObject => true;
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> _queryInterfaceCache;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> MakeQueryInterfaceCache()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference>(), null);
return _queryInterfaceCache;
get
{
var cache = _queryInterfaceCache;
if (cache != null)
{
return cache;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _queryInterfaceCache, new(), null);
return _queryInterfaceCache;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, IObjectReference> IWinRTObject.QueryInterfaceCache => _queryInterfaceCache ?? MakeQueryInterfaceCache();
private volatile global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> _additionalTypeData;
private global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> MakeAdditionalTypeData()
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object>(), null);
return _additionalTypeData;
get
{
var typeData = _additionalTypeData;
if (typeData != null)
{
return typeData;
}
else
{
global::System.Threading.Interlocked.CompareExchange(ref _additionalTypeData, new(), null);
return _additionalTypeData;
}
}
}
global::System.Collections.Concurrent.ConcurrentDictionary<RuntimeTypeHandle, object> IWinRTObject.AdditionalTypeData => _additionalTypeData ?? MakeAdditionalTypeData();
#endif
public unsafe % Invoke(%)
Expand Down

0 comments on commit 2901891

Please sign in to comment.