Skip to content

Commit

Permalink
Fix thread-safety for C++/CLI.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 934f0b05cc46cc0731f5f9f24c6db019a1e6a605
  • Loading branch information
levlam committed Sep 3, 2018
1 parent dea5dea commit 6f57062
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions td/tl/tl_dotnet_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,36 @@ auto CLRCALL FromUnmanaged(td::td_api::object_ptr<T> &from) -> decltype(FromUnma
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>
inline ResT DoFromUnmanaged(T &from) {
#if TD_WINRT
ResT res;
downcast_call(from, [&](auto &from_downcasted) {
res = FromUnmanaged(from_downcasted);
});
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) {
Expand Down

0 comments on commit 6f57062

Please sign in to comment.