Fix thread-safety for C++/CLI.

GitOrigin-RevId: 934f0b05cc46cc0731f5f9f24c6db019a1e6a605
This commit is contained in:
levlam 2018-09-03 14:19:14 +03:00
parent dea5dea49a
commit 6f570624df

View File

@ -100,13 +100,36 @@ auto CLRCALL FromUnmanaged(td::td_api::object_ptr<T> &from) -> decltype(FromUnma
return FromUnmanaged(*from.get()); return FromUnmanaged(*from.get());
} }
#if TD_CLI
template <class ResT>
ref class CallFromUnmanagedRes {
public:
[System::ThreadStaticAttribute]
static property ResT res;
};
template <class ResT>
struct CallFromUnmanaged {
template <class T>
void operator()(T &val) const {
CallFromUnmanagedRes<ResT>::res = FromUnmanaged(val);
}
};
#endif
template <class ResT, class T> template <class ResT, class T>
inline ResT DoFromUnmanaged(T &from) { inline ResT DoFromUnmanaged(T &from) {
#if TD_WINRT
ResT res; ResT res;
downcast_call(from, [&](auto &from_downcasted) { downcast_call(from, [&](auto &from_downcasted) {
res = FromUnmanaged(from_downcasted); res = FromUnmanaged(from_downcasted);
}); });
return res; return res;
#elif TD_CLI
CallFromUnmanaged<ResT> res;
downcast_call(from, res);
return CallFromUnmanagedRes<ResT>::res;
#endif
} }
inline BaseObject^ FromUnmanaged(td::td_api::Function &from) { inline BaseObject^ FromUnmanaged(td::td_api::Function &from) {