[RFC] Single instance
Compare changes
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:
configure(dbPath, mlFolderPath)
: set the db path and ml folder pathinitialize(mlCallback)
: initialize the databaseThe 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:
flock()
, so something else is necessary for Windows.configure()
call, which is not obvious from the name.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
VideoLAN code repository instance