You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@celix.apache.org by GitBox <gi...@apache.org> on 2021/05/06 14:54:52 UTC
[GitHub] [celix] pnoltes commented on a change in pull request #336: Feature/async update
pnoltes commented on a change in pull request #336:
URL: https://github.com/apache/celix/pull/336#discussion_r627495742
##########
File path: libs/framework/include/celix/dm/ServiceDependency_Impl.h
##########
@@ -403,22 +531,64 @@ void ServiceDependency<T,I>::setupCallbacks() {
int(*cadd)(void*, void *, const celix_properties_t*) {nullptr};
int(*crem)(void*, void *, const celix_properties_t*) {nullptr};
- if (setFp != nullptr) {
- cset = [](void* handle, void *service, const celix_properties_t* props) -> int {
+ if (setFp || setFpUsingSharedPtr) {
+ cset = [](void* handle, void* rawSvc, const celix_properties_t* rawProps) -> int {
+ int rc = 0;
auto dep = (ServiceDependency<T,I>*) handle;
- return dep->invokeCallback(dep->setFp, props, service);
+ if (dep->setFp) {
+ rc = dep->invokeCallback(dep->setFp, rawProps, rawSvc);
+ }
+ if (dep->setFpUsingSharedPtr) {
+ auto svcId = dep->setService.second ? dep->setService.second->getAsLong(celix::SERVICE_ID, -1) : -1;
+ std::weak_ptr<I> currentSvc = dep->setService.first;
+ std::weak_ptr<const celix::Properties> currentProps = dep->setService.second;
+ auto svc = std::shared_ptr<I>{static_cast<I*>(rawSvc), [](I*){/*nop*/}};
+ auto props = rawProps ? celix::Properties::wrap(rawProps) : nullptr;
+ dep->setService = std::make_pair(std::move(svc), std::move(props));
+ dep->setFpUsingSharedPtr(dep->setService.first, dep->setService.second);
+ dep->waitForExpired(currentSvc, svcId, "service pointer");
Review comment:
Yes. If a shared_ptr is not expired we can have a bug (removal is not correctly done) or the svc is still in use on an other thread (also not desirable).
Note that this can also happen with raw pointers, but in the case of shared_ptr a warning can be printed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org