MediaLibrary: Add priority access mechanism
Compare changes
In addition to read-lock and write-lock, add a "priority access" mechanism. The goal is to give priority to UI requests.
Several callers may acquire a "priority access". As soon as at least one caller has priority access, all non-priority callers are blocked on lock_read()
and lock_write()
, until all priority accesses are released. However, they can continue executing their current requests following the traditional RW-lock rules.
Acquiring a priority access is "immediate". It is different from a lock in that it never blocks but makes other clients wait.
When the VLC UI loads a list of items, it generates many read requests to the medialibrary, each one protected by a read-lock, but not globally protected by a single lock/unlock. As a consequence, during indexation, many write requests were executed between these read requests, causing the loading time to explode (several tens of seconds instead of milliseconds).
To avoid interleaving of read requests from the UI and write requests from the indexation, I first wrote a PoC to expose an exclusive lock in the medialib API. The UI took the exclusive lock for executing all its read requests within a single lock. This solved the performance issue.
However, an exclusive lock for solving this problem was not very suitable in theory:
To avoid these drawbacks, this MR implements a "priority access" instead. It is different from a lock in that it never blocks the caller but makes other (non-priority) clients wait. In bulk:
auto _ = ml->acquirePriorityAccess()
)lock_read()
or lock_write()
until all priority accesses are releasedlock_read()
and lock_write()
by others (priority or non-priority) clients due to traditional RW-lock rulesIn practice, indexation requests don't have priority access, so they are all blocked when a UI request, which will take the priority access, is started.
Like with the "exclusive lock" PoC, the list results is retrieved very quickly even when indexing is running.
VideoLAN code repository instance