Make StopWatchingFileDescriptor deterministic.
The AsyncManager allows for registering and unregistering watchers for sockets. Previously it was possible to receive a callback even though unregister was called from a separate thread. This makes it very difficult to properly manage object lifetime for an object that took a dependency on a callback, as a callback could arrive while the object was destroyed. We now introduce a recursive_mutex to protect the subscriptions. This guarantees: - We will block unsubscription until all relevant callbacks have finished. - We can still stop watching from the callback thread. This guarantees that we will never get a callback after unsubscription. Includes 2 unit tests: 1. Guarantee that we do not deadlock in unsubscription from a callback. 2. Attempt to validate that a callback never happens after unsubscribe. The 2nd test will fail when the recursive mutex is removed. Test: 2 additional unit tests. Change-Id: I2b9cdb0c31f88e67bbaca0667bd8822f69096995
Loading
Please register or sign in to comment