kulst commented on PR #627:
URL: https://github.com/apache/celix/pull/627#issuecomment-2111046448

   > > Two weeks have passed and I wanted to share again my progress :)
   > > **BundleContext lifetime** Another way I came up with is to hand out a 
BundleContext to the bundle and having an Arc<(Condvar, Mutex)> flag in the 
BundleContext (not accessible by the BundleContexts API). When the 
BundleContext is dropped, the flag is set and the Condvar is notified. A copy 
of that Arc is stored in the internal part of the activator. When the 
stop/delete function of the bundle is invoked the flag is checked periodically 
if it is set. By using the Condvar we can block between these checks (and also 
log an error similar to the cpp API).
   > 
   > This is indeed close to what C++ is doing and that case a `weak_ptr` is 
used during bundle stop a runtime check and wait is made to ensure there are no 
users of the BundleContext anymore.
   
   Exactly, the C++ solution is where I took inspiration from. But by doing it 
with an Arc<(Condvar, Mutex<bool>)> inside of the BundleContext we can utilize 
lifetimes and could also create the Rust API with more flexibility for the 
user. 
   For example instead of explicitly storing an Arc<BundleContext> or an 
&BundleContext in each data structure that depends on the BundleContext we 
could also store an T : AsRef<BundleContext> in the data structures and let the 
user decide. 


-- 
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.

To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to