Mir

Code review comment for lp:~afrantzis/mir/fix-1441759-screencast

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> I'm a bit confused here. Under what situation will weak_tid.lock() return a valid pointer
> Under what situation will weak_tid.lock() return a valid pointer but *weak_tid.lock() != this_thread::get_id()?

This can happen when a buffer is not available to the client when calling stream.swap_buffers(), but becomes available soon after stream.swap_buffers() returns (e.g. because a compositor has released a buffer) but before we leave the advance_buffer function (so weak_ptr is still valid). The completion callback will then be called in another thread (the compositor thread), while weak_ptr is still valid.

> It looks like this could be made simpler by just passing ownership of lock to advance_buffer.

The idea is to avoid holding the lock while running the completion function, which (among other things) performs IPC operations. If lock ownership was passed to advance_buffer (and not conditionally unlocked in the completion function), we would be holding the lock if the completion function executed synchronously.

« Back to merge proposal