"private IntPtr _port;\n" \
"private bool _online = false;\n" \
"private string _appId;\n" \
+ "private Object _lock = new Object();\n" \
"private List<CallbackBase> _delegateList = new List<CallbackBase>();\n" \
"private Interop.LibRPCPort.Proxy.ConnectedEventCallback _connectedEventCallback;\n" \
"private Interop.LibRPCPort.Proxy.DisconnectedEventCallback _disconnectedEventCallback;\n" \
"\n" \
"private void OnReceivedEvent(string endPoint, string port_name, IntPtr data)\n" \
"{\n" \
- " if (Interop.LibRPCPort.Parcel.CreateFromPort(out IntPtr parcel_received, _port) != 0)\n" \
- " return;\n" \
+ " IntPtr parcel_received;\n" \
+ " lock (_lock)\n" \
+ " {\n" \
+ " if (Interop.LibRPCPort.Parcel.CreateFromPort(out parcel_received, _port) != 0)\n" \
+ " return;\n" \
+ " }\n" \
"\n" \
" Interop.LibRPCPort.Parcel.ReadInt32(parcel_received, out int cmd);\n" \
" if (cmd != (int)MethodId.Callback)\n" \
const char* mid =
"// Send\n" \
- "Interop.LibRPCPort.Parcel.Send(p, _port);\n" \
- "Interop.LibRPCPort.Parcel.Destroy(p);\n";
+ "Interop.LibRPCPort.Parcel.Send(p, _port);\n";
stream << AddIndent(TAB_SIZE * 4, pre);
<< "Interop.LibRPCPort.Parcel.WriteInt32(p, (int)MethodId."
<< decl.GetID() << ");" << NLine(1);
std::string m;
+ std::string l;
for (auto& i : decl.GetParameters().GetParams()) {
auto& pt = i->GetParameterType();
if (pt.GetDirection() == ParameterType::Direction::OUT)
continue;
m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p");
if (IsDelegateType(pt.GetBaseType().ToString()))
- m += "_delegateList.Add(" + i->GetID() + ");\n";
+ l += "_delegateList.Add(" + i->GetID() + ");\n";
}
-
stream << AddIndent(TAB_SIZE * 4, m) << NLine(1);
- stream << AddIndent(TAB_SIZE * 4, mid) << NLine(1);
+
+ if (decl.GetMethodType() == Declaration::MethodType::SYNC)
+ stream << Tab(4) << "IntPtr parcel_received;" << NLine(1);
+ stream << Tab(4) << "lock (_lock)" << NLine(1);
+ GenBrace(stream, TAB_SIZE * 4, [&]() {
+ if (!l.empty())
+ stream << AddIndent(TAB_SIZE * 5, l) << NLine(1);
+ stream << AddIndent(TAB_SIZE * 5, mid) << NLine(1);
+ if (decl.GetMethodType() == Declaration::MethodType::SYNC) {
+ stream << Tab(5) << "// Receive" << NLine(1);
+ stream << Tab(5)
+ << "ConsumeCommand(out parcel_received, _port);" << NLine(1);
+ }
+ });
+ stream << NLine(1);
// Deserialize
- if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
+ if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
+ stream << Tab(4) << "Interop.LibRPCPort.Parcel.Destroy(p);"
+ << NLine(1);
return;
+ }
const char* receive_block =
- "// Receive\n" \
- "ConsumeCommand(out IntPtr parcel_received, _port);\n" \
"if (parcel_received == IntPtr.Zero)\n" \
"{\n" \
" throw new InvalidOperationException(\"Can't receive data\");\n" \
"ret", "parcel_received"));
}
+ stream << Tab(4) << "Interop.LibRPCPort.Parcel.Destroy(p);"
+ << NLine(1);
stream << Tab(4) << "Interop.LibRPCPort.Parcel.Destroy(parcel_received);"
<< NLine(1);