From 02398462000160d2d698975093c994148b01a061 Mon Sep 17 00:00:00 2001 From: Jakub Jermar Date: Thu, 9 Nov 2017 21:25:58 +0100 Subject: [PATCH] First wait for IPC answer and then end the async exchange This is necessary to create a parallel locsrv connection (when handling locsrv requests in parallel) instead of reusing the one which is still possibly active. --- uspace/lib/c/generic/loc.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/uspace/lib/c/generic/loc.c b/uspace/lib/c/generic/loc.c index a7cafe547..58669a0a3 100644 --- a/uspace/lib/c/generic/loc.c +++ b/uspace/lib/c/generic/loc.c @@ -246,18 +246,22 @@ int loc_server_register(const char *name) aid_t req = async_send_2(exch, LOC_SERVER_REGISTER, 0, 0, &answer); sysarg_t retval = async_data_write_start(exch, name, str_size(name)); - loc_exchange_end(exch); - if (retval != EOK) { async_forget(req); + loc_exchange_end(exch); return retval; } - exch = loc_exchange_begin(INTERFACE_LOC_SUPPLIER); async_connect_to_me(exch, 0, 0, 0); + + /* + * First wait for the answer and then end the exchange. The opposite + * order is generally wrong because it may lead to a deadlock under + * certain circumstances. + */ + async_wait_for(req, &retval); loc_exchange_end(exch); - async_wait_for(req, &retval); return retval; } @@ -275,14 +279,19 @@ int loc_service_register(const char *fqsn, service_id_t *sid) aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer); sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn)); - loc_exchange_end(exch); - if (retval != EOK) { async_forget(req); + loc_exchange_end(exch); return retval; } + /* + * First wait for the answer and then end the exchange. The opposite + * order is generally wrong because it may lead to a deadlock under + * certain circumstances. + */ async_wait_for(req, &retval); + loc_exchange_end(exch); if (retval != EOK) { if (sid != NULL) -- 2.11.4.GIT