mirror of https://github.com/llvm/circt.git
[ESI] Disallow calls on an unconnected `FuncService::Function` (#8779)
because currently, that'll result in segfaults. Co-authored-by: Morten Borup Petersen <mpetersen@microsoft.com>
This commit is contained in:
parent
2696da0895
commit
d41ea14885
|
@ -284,6 +284,7 @@ public:
|
|||
std::mutex callMutex;
|
||||
WriteChannelPort *arg;
|
||||
ReadChannelPort *result;
|
||||
bool connected = false;
|
||||
};
|
||||
|
||||
private:
|
||||
|
|
|
@ -200,16 +200,21 @@ FuncService::Function *FuncService::Function::get(AppID id, BundleType *type,
|
|||
}
|
||||
|
||||
void FuncService::Function::connect() {
|
||||
if (connected)
|
||||
throw std::runtime_error("Function is already connected");
|
||||
if (channels.size() != 2)
|
||||
throw std::runtime_error("FuncService must have exactly two channels");
|
||||
arg = &getRawWrite("arg");
|
||||
arg->connect();
|
||||
result = &getRawRead("result");
|
||||
result->connect();
|
||||
connected = true;
|
||||
}
|
||||
|
||||
std::future<MessageData>
|
||||
FuncService::Function::call(const MessageData &argData) {
|
||||
if (!connected)
|
||||
throw std::runtime_error("Function must be 'connect'ed before calling");
|
||||
std::scoped_lock<std::mutex> lock(callMutex);
|
||||
arg->write(argData);
|
||||
return result->readAsync();
|
||||
|
|
Loading…
Reference in New Issue