[vlc-commits] objects: simplify handling of object name
Rémi Denis-Courmont
git at videolan.org
Sun Mar 3 16:52:20 CET 2019
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 3 13:54:50 2019 +0200| [41bf77a26c39a0aa452f147a44a0eeea770338aa] | committer: Rémi Denis-Courmont
objects: simplify handling of object name
This should be removed altogether, when custom input controls are
cleaned up.
This removes the global name lock.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=41bf77a26c39a0aa452f147a44a0eeea770338aa
---
src/misc/objects.c | 38 ++++++++++----------------------------
src/misc/variables.h | 2 +-
2 files changed, 11 insertions(+), 29 deletions(-)
diff --git a/src/misc/objects.c b/src/misc/objects.c
index 3481acbb22..33e03ab76b 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -199,7 +199,7 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,
return NULL;
priv->typename = typename;
- priv->psz_name = NULL;
+ atomic_init(&priv->is_v4l2, false);
priv->var_root = NULL;
vlc_mutex_init (&priv->var_lock);
vlc_cond_init (&priv->var_wait);
@@ -284,38 +284,23 @@ vlc_object_t *(vlc_object_parent)(vlc_object_t *obj)
return vlc_internals(obj)->parent;
}
-static vlc_mutex_t name_lock = VLC_STATIC_MUTEX;
-
#undef vlc_object_set_name
int vlc_object_set_name(vlc_object_t *obj, const char *name)
{
vlc_object_internals_t *priv = vlc_internals(obj);
- char *newname = NULL;
- char *oldname;
-
/* See vlc_object_find_name(). */
- if (unlikely(strcmp(name, "v4l2") == 0))
- newname = strdup(name);
-
- vlc_mutex_lock (&name_lock);
- oldname = priv->psz_name;
- priv->psz_name = newname;
- vlc_mutex_unlock (&name_lock);
+ bool newname = unlikely(strcmp(name, "v4l2") == 0);
- free (oldname);
- return (priv->psz_name || !name) ? VLC_SUCCESS : VLC_ENOMEM;
+ atomic_store_explicit(&priv->is_v4l2, newname, memory_order_release);
+ return VLC_SUCCESS;
}
char *vlc_object_get_name(const vlc_object_t *obj)
{
vlc_object_internals_t *priv = vlc_internals(obj);
- char *name;
-
- vlc_mutex_lock (&name_lock);
- name = priv->psz_name ? strdup (priv->psz_name) : NULL;
- vlc_mutex_unlock (&name_lock);
- return name;
+ return atomic_load_explicit(&priv->is_v4l2, memory_order_acquire)
+ ? strdup("v4l2") : NULL;
}
/**
@@ -345,15 +330,14 @@ static void vlc_object_destroy( vlc_object_t *p_this )
vlc_cond_destroy( &p_priv->var_wait );
vlc_mutex_destroy( &p_priv->var_lock );
- free( p_priv->psz_name );
free( p_priv );
}
-static vlc_object_t *FindName (vlc_object_t *obj, const char *name)
+static vlc_object_t *FindV4L2(vlc_object_t *obj)
{
vlc_object_internals_t *priv = vlc_internals(obj);
- if (priv->psz_name != NULL && !strcmp (priv->psz_name, name))
+ if (atomic_load_explicit(&priv->is_v4l2, memory_order_relaxed))
return vlc_object_hold (obj);
vlc_object_t *found = NULL;
@@ -361,7 +345,7 @@ static vlc_object_t *FindName (vlc_object_t *obj, const char *name)
vlc_mutex_assert(&tree_lock);
vlc_children_foreach(priv, priv)
{
- found = FindName (vlc_externals(priv), name);
+ found = FindV4L2(vlc_externals(priv));
if (found != NULL)
break;
}
@@ -397,11 +381,9 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this, const char *psz_name )
if (strcmp(psz_name, "v4l2"))
return NULL;
- vlc_mutex_lock (&name_lock);
vlc_mutex_lock(&tree_lock);
- p_found = FindName (p_this, psz_name);
+ p_found = FindV4L2(p_this);
vlc_mutex_unlock(&tree_lock);
- vlc_mutex_unlock (&name_lock);
return p_found;
}
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 11f0dfbc7f..14aaa2336f 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -39,7 +39,7 @@ struct vlc_object_internals
alignas (max_align_t) /* ensure vlc_externals() is maximally aligned */
vlc_object_t *parent; /**< Parent object (or NULL) */
const char *typename; /**< Object type human-readable name */
- char *psz_name; /* given name */
+ atomic_bool is_v4l2; /* Temporary backward-compatibility hack */
/* Object variables */
void *var_root;
More information about the vlc-commits
mailing list