mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
miniobject: hide qdata array layout
This commit is contained in:
parent
d317b36919
commit
2cb9eba560
2 changed files with 31 additions and 24 deletions
|
@ -68,6 +68,18 @@ static GstAllocTrace *_gst_mini_object_trace;
|
||||||
G_LOCK_DEFINE_STATIC (qdata_mutex);
|
G_LOCK_DEFINE_STATIC (qdata_mutex);
|
||||||
static GQuark weak_ref_quark;
|
static GQuark weak_ref_quark;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GQuark quark;
|
||||||
|
GstMiniObjectWeakNotify notify;
|
||||||
|
gpointer data;
|
||||||
|
} GstQData;
|
||||||
|
|
||||||
|
#define QDATA(o,i) ((GstQData *)(o)->qdata)[(i)]
|
||||||
|
#define QDATA_QUARK(o,i) (QDATA(o,i).quark)
|
||||||
|
#define QDATA_NOTIFY(o,i) (QDATA(o,i).notify)
|
||||||
|
#define QDATA_DATA(o,i) (QDATA(o,i).data)
|
||||||
|
|
||||||
void
|
void
|
||||||
_priv_gst_mini_object_initialize (void)
|
_priv_gst_mini_object_initialize (void)
|
||||||
{
|
{
|
||||||
|
@ -220,7 +232,7 @@ qdata_notify (GstMiniObject * obj)
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
for (i = 0; i < obj->n_qdata; i++)
|
for (i = 0; i < obj->n_qdata; i++)
|
||||||
obj->qdata[i].notify (obj->qdata[i].data, obj);
|
QDATA_NOTIFY (obj, i) (QDATA_DATA (obj, i), obj);
|
||||||
g_free (obj->qdata);
|
g_free (obj->qdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,10 +422,10 @@ gst_mini_object_weak_ref (GstMiniObject * object,
|
||||||
G_LOCK (qdata_mutex);
|
G_LOCK (qdata_mutex);
|
||||||
i = object->n_qdata++;
|
i = object->n_qdata++;
|
||||||
object->qdata =
|
object->qdata =
|
||||||
g_realloc (object->qdata, sizeof (object->qdata[0]) * object->n_qdata);
|
g_realloc (object->qdata, sizeof (GstQData) * object->n_qdata);
|
||||||
object->qdata[i].quark = weak_ref_quark;
|
QDATA_QUARK (object, i) = weak_ref_quark;
|
||||||
object->qdata[i].notify = notify;
|
QDATA_NOTIFY (object, i) = notify;
|
||||||
object->qdata[i].data = data;
|
QDATA_DATA (object, i) = data;
|
||||||
G_UNLOCK (qdata_mutex);
|
G_UNLOCK (qdata_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,15 +451,15 @@ gst_mini_object_weak_unref (GstMiniObject * object,
|
||||||
|
|
||||||
G_LOCK (qdata_mutex);
|
G_LOCK (qdata_mutex);
|
||||||
for (i = 0; i < object->n_qdata; i++) {
|
for (i = 0; i < object->n_qdata; i++) {
|
||||||
if (object->qdata[i].quark == weak_ref_quark &&
|
if (QDATA_QUARK (object, i) == weak_ref_quark &&
|
||||||
object->qdata[i].notify == notify && object->qdata[i].data == data) {
|
QDATA_NOTIFY (object, i) == notify && QDATA_DATA (object, i) == data) {
|
||||||
found_one = TRUE;
|
found_one = TRUE;
|
||||||
if (--object->n_qdata == 0) {
|
if (--object->n_qdata == 0) {
|
||||||
/* we don't shrink but free when everything is gone */
|
/* we don't shrink but free when everything is gone */
|
||||||
g_free (object->qdata);
|
g_free (object->qdata);
|
||||||
object->qdata = NULL;
|
object->qdata = NULL;
|
||||||
} else if (i != object->n_qdata)
|
} else if (i != object->n_qdata)
|
||||||
object->qdata[i] = object->qdata[object->n_qdata];
|
QDATA (object, i) = QDATA (object, object->n_qdata);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,9 +503,9 @@ gst_mini_object_set_qdata (GstMiniObject * object, GQuark quark,
|
||||||
|
|
||||||
G_LOCK (qdata_mutex);
|
G_LOCK (qdata_mutex);
|
||||||
for (i = 0; i < object->n_qdata; i++) {
|
for (i = 0; i < object->n_qdata; i++) {
|
||||||
if (object->qdata[i].quark == quark) {
|
if (QDATA_QUARK (object, i) == quark) {
|
||||||
old_data = object->qdata[i].data;
|
old_data = QDATA_DATA (object, i);
|
||||||
old_notify = (GDestroyNotify) object->qdata[i].notify;
|
old_notify = (GDestroyNotify) QDATA_NOTIFY (object, i);
|
||||||
|
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
/* remove item */
|
/* remove item */
|
||||||
|
@ -502,7 +514,7 @@ gst_mini_object_set_qdata (GstMiniObject * object, GQuark quark,
|
||||||
g_free (object->qdata);
|
g_free (object->qdata);
|
||||||
object->qdata = NULL;
|
object->qdata = NULL;
|
||||||
} else if (i != object->n_qdata)
|
} else if (i != object->n_qdata)
|
||||||
object->qdata[i] = object->qdata[object->n_qdata];
|
QDATA (object, i) = QDATA (object, object->n_qdata);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -511,11 +523,11 @@ gst_mini_object_set_qdata (GstMiniObject * object, GQuark quark,
|
||||||
/* add item */
|
/* add item */
|
||||||
i = object->n_qdata++;
|
i = object->n_qdata++;
|
||||||
object->qdata =
|
object->qdata =
|
||||||
g_realloc (object->qdata, sizeof (object->qdata[0]) * object->n_qdata);
|
g_realloc (object->qdata, sizeof (GstQData) * object->n_qdata);
|
||||||
}
|
}
|
||||||
object->qdata[i].quark = quark;
|
QDATA_QUARK (object, i) = quark;
|
||||||
object->qdata[i].data = data;
|
QDATA_DATA (object, i) = data;
|
||||||
object->qdata[i].notify = (GstMiniObjectWeakNotify) destroy;
|
QDATA_NOTIFY (object, i) = (GstMiniObjectWeakNotify) destroy;
|
||||||
G_UNLOCK (qdata_mutex);
|
G_UNLOCK (qdata_mutex);
|
||||||
|
|
||||||
if (old_notify)
|
if (old_notify)
|
||||||
|
@ -543,8 +555,8 @@ gst_mini_object_get_qdata (GstMiniObject * object, GQuark quark)
|
||||||
|
|
||||||
G_LOCK (qdata_mutex);
|
G_LOCK (qdata_mutex);
|
||||||
for (i = 0; i < object->n_qdata; i++) {
|
for (i = 0; i < object->n_qdata; i++) {
|
||||||
if (object->qdata[i].quark == quark) {
|
if (QDATA_QUARK (object, i) == quark) {
|
||||||
result = object->qdata[i].data;
|
result = QDATA_DATA (object, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,12 +178,7 @@ struct _GstMiniObject {
|
||||||
/* < private > */
|
/* < private > */
|
||||||
/* Used to keep track of weak ref notifies and qdata */
|
/* Used to keep track of weak ref notifies and qdata */
|
||||||
guint n_qdata;
|
guint n_qdata;
|
||||||
struct
|
gpointer qdata;
|
||||||
{
|
|
||||||
GQuark quark;
|
|
||||||
GstMiniObjectWeakNotify notify;
|
|
||||||
gpointer data;
|
|
||||||
} *qdata;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void gst_mini_object_init (GstMiniObject *mini_object, GType type);
|
void gst_mini_object_init (GstMiniObject *mini_object, GType type);
|
||||||
|
|
Loading…
Reference in a new issue