Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 9393b324 authored by Erwin Jansen's avatar Erwin Jansen
Browse files

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
parent 50bbf0ad
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment