Skip to content

[RFC] Single instance

Romain Vimont requested to merge rom1v/medialibrary:single_instance into master

In VLC, loading the medialibrary module (Open()) is done during VLC start, unless --no-media-library is passed. The fact that the module is correctly opened determines if the medialib UI should be enabled.

However, the medialib initialization is lazy (Init()/initialize() is called the first time the medialib is needed, i.e. later).

To enforce a single medialib instance, we want to know immediately (on medialibrary module loading) if the single instance file lock can be acquired, to be able to enable/disable the medialib UI as needed. However, the file lock path depends on parameters passed to initialize() (ml.pid in the mlFolderPath), which is called later.

Therefore, split initialize() in two parts:

  1. configure(dbPath, mlFolderPath): set the db path and ml folder path
  2. initialize(mlCallback): initialize the database

The existing initialize(dbPath, mlFolderPath, mlCallback) is kept for convenience to do both configure(dbPath, mlFolderPath)+initialize(mlCallback) (and make the tests happy).

Then acquire the file lock on configure() (and return a bool to let the caller know if the database can be used).

Remarks:

  • the feature uses flock(), so something else is necessary for Windows.
  • the file lock is acquired during the configure() call, which is not obvious from the name.
  • the lock is ml.pid in the mlFolderPath directory, maybe its named should be derived from dbPath instead?

On VLC, this branch disables the medialib if the lock is already acquired): https://code.videolan.org/rom1v/vlc/-/commits/ml_single_instance

Merge request reports