[vlc-commits] modules: remove plug-in loaded flag
Rémi Denis-Courmont
git at videolan.org
Thu Apr 12 19:48:17 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 8 18:25:37 2018 +0300| [7b2b46f7c6921a50d47a633f0d7e54b17343cd91] | committer: Rémi Denis-Courmont
modules: remove plug-in loaded flag
The handle is nul when not loaded. There are no needs for a separate
boolean.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7b2b46f7c6921a50d47a633f0d7e54b17343cd91
---
src/modules/bank.c | 22 ++++++++++------------
src/modules/entry.c | 5 ++---
src/modules/modules.h | 3 +--
3 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/src/modules/bank.c b/src/modules/bank.c
index e7e0b9599c..c4f7546c7c 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -166,7 +166,7 @@ static vlc_plugin_t *module_InitStatic(vlc_plugin_cb entry)
return NULL;
#ifdef HAVE_DYNAMIC_PLUGINS
- atomic_init(&lib->loaded, true);
+ atomic_init(&lib->handle, 1 /* must be non-zero for module_Map() */);
lib->unloadable = false;
#endif
return lib;
@@ -235,8 +235,7 @@ static vlc_plugin_t *module_InitDynamic(vlc_object_t *obj, const char *path,
goto error;
}
- plugin->handle = handle;
- atomic_init(&plugin->loaded, true);
+ atomic_init(&plugin->handle, (uintptr_t)handle);
return plugin;
error:
vlc_dlclose(handle);
@@ -498,7 +497,7 @@ int module_Map(vlc_object_t *obj, vlc_plugin_t *plugin)
{
static vlc_mutex_t lock = VLC_STATIC_MUTEX;
- if (atomic_load_explicit(&plugin->loaded, memory_order_acquire))
+ if (atomic_load_explicit(&plugin->handle, memory_order_acquire))
return 0; /* fast path: already loaded */
/* Try to load the plug-in (without locks, so read-only) */
@@ -523,7 +522,7 @@ int module_Map(vlc_object_t *obj, vlc_plugin_t *plugin)
}
vlc_mutex_lock(&lock);
- if (!atomic_load_explicit(&plugin->loaded, memory_order_relaxed))
+ if (atomic_load_explicit(&plugin->handle, memory_order_relaxed) == 0)
{ /* Lock is held, update the plug-in structure */
if (vlc_plugin_resolve(plugin, entry))
{
@@ -531,8 +530,8 @@ int module_Map(vlc_object_t *obj, vlc_plugin_t *plugin)
return -1;
}
- plugin->handle = handle;
- atomic_store_explicit(&plugin->loaded, true, memory_order_release);
+ atomic_store_explicit(&plugin->handle, (uintptr_t)handle,
+ memory_order_release);
}
else /* Another thread won the race to load the plugin */
vlc_dlclose(handle);
@@ -551,12 +550,11 @@ static void module_Unmap(vlc_plugin_t *plugin)
{
if (!plugin->unloadable)
return;
- if (!atomic_exchange_explicit(&plugin->loaded, false,
- memory_order_acquire))
- return;
- assert(plugin->handle != NULL);
- vlc_dlclose(plugin->handle);
+ void *handle = (void *)atomic_exchange_explicit(&plugin->handle, 0,
+ memory_order_acquire);
+ if (handle != NULL)
+ vlc_dlclose(handle);
}
#else
int module_Map(vlc_object_t *obj, vlc_plugin_t *plugin)
diff --git a/src/modules/entry.c b/src/modules/entry.c
index 5df86f6710..31fa64c2ce 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -105,9 +105,8 @@ vlc_plugin_t *vlc_plugin_create(void)
plugin->conf.booleans = 0;
#ifdef HAVE_DYNAMIC_PLUGINS
plugin->abspath = NULL;
- atomic_init(&plugin->loaded, false);
plugin->unloadable = true;
- plugin->handle = NULL;
+ atomic_init(&plugin->handle, 0);
plugin->abspath = NULL;
plugin->path = NULL;
#endif
@@ -125,7 +124,7 @@ void vlc_plugin_destroy(vlc_plugin_t *plugin)
{
assert(plugin != NULL);
#ifdef HAVE_DYNAMIC_PLUGINS
- assert(!plugin->unloadable || !atomic_load(&plugin->loaded));
+ assert(!plugin->unloadable || atomic_load(&plugin->handle) == 0);
#endif
if (plugin->module != NULL)
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 8f7ae97e97..885789a149 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -47,9 +47,8 @@ typedef struct vlc_plugin_t
} conf;
#ifdef HAVE_DYNAMIC_PLUGINS
- atomic_bool loaded; /**< Whether the plug-in is mapped in memory */
bool unloadable; /**< Whether the plug-in can be unloaded safely */
- void *handle; /**< Run-time linker handle (if loaded) */
+ atomic_uintptr_t handle; /**< Run-time linker handle (or nul) */
char *abspath; /**< Absolute path */
char *path; /**< Relative path (within plug-in directory) */
More information about the vlc-commits
mailing list