Commit 9e3c1a6d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Use copy/free paradigm rather than hold/release for message items

Message items are more often than not not rereferenced, and hardly ever
rereferenced more than once. Demand-copying will be faster in most
common circumstances (especially built-in console or logger).
parent 0b93cc71
......@@ -53,8 +53,6 @@ typedef struct
char * psz_module;
char * psz_msg; /**< the message itself */
char * psz_header; /**< Additional header */
gc_object_t vlc_gc_data;
} msg_item_t;
/* Message types */
......@@ -67,15 +65,25 @@ typedef struct
/** debug messages */
#define VLC_MSG_DBG 3
static inline msg_item_t *msg_Hold (msg_item_t *msg)
VLC_MALLOC VLC_USED
static inline msg_item_t *msg_Copy (const msg_item_t *msg)
{
vlc_hold (&msg->vlc_gc_data);
return msg;
msg_item_t *copy = (msg_item_t *)xmalloc (sizeof (*copy));
copy->i_type = msg->i_type;
copy->i_object_id = msg->i_object_id;
copy->psz_object_type = msg->psz_object_type;
copy->psz_module = strdup (msg->psz_module);
copy->psz_msg = strdup (msg->psz_msg);
copy->psz_header = strdup (msg->psz_header);
return copy;
}
static inline void msg_Release (msg_item_t *msg)
static inline void msg_Free (msg_item_t *msg)
{
vlc_release (&msg->vlc_gc_data);
free (msg->psz_module);
free (msg->psz_msg);
free (msg->psz_header);
free (msg);
}
/**
......
......@@ -1782,8 +1782,8 @@ static void MsgCallback(msg_cb_data_t *data, msg_item_t *msg, unsigned i)
vlc_mutex_lock(&p_sys->msg_lock);
if (p_sys->msgs[p_sys->i_msgs])
msg_Release(p_sys->msgs[p_sys->i_msgs]);
p_sys->msgs[p_sys->i_msgs++] = msg_Hold(msg);
msg_Free(p_sys->msgs[p_sys->i_msgs]);
p_sys->msgs[p_sys->i_msgs++] = msg_Copy(msg);
if (p_sys->i_msgs == (sizeof p_sys->msgs / sizeof *p_sys->msgs))
p_sys->i_msgs = 0;
......@@ -1915,7 +1915,7 @@ static void Close(vlc_object_t *p_this)
vlc_mutex_destroy(&p_sys->msg_lock);
for(unsigned i = 0; i < sizeof p_sys->msgs / sizeof *p_sys->msgs; i++)
if (p_sys->msgs[i])
msg_Release(p_sys->msgs[i]);
msg_Free(p_sys->msgs[i]);
free(p_sys);
}
......@@ -48,13 +48,13 @@ class MsgEvent : public QEvent
{
public:
MsgEvent( msg_item_t *msg )
: QEvent( (QEvent::Type)MsgEvent_Type ), msg(msg)
: QEvent( (QEvent::Type)MsgEvent_Type )
{
msg_Hold( msg );
this->msg = msg_Copy( msg );
}
virtual ~MsgEvent()
virtual ~MsgEvent( void )
{
msg_Release( msg );
msg_Free( msg );
}
msg_item_t *msg;
......
......@@ -53,12 +53,11 @@ static void handler( msg_cb_data_t *d, msg_item_t *p_item, unsigned i_drop )
if (p_item->i_type > d->verbosity)
return;
msg_item_t *msg = msg_Copy (p_item);
vlc_spin_lock (&d->lock);
if (d->count < VLC_MSG_QSIZE)
{
d->items[d->count++] = p_item;
msg_Hold (p_item);
}
d->items[d->count++] = msg;
vlc_spin_unlock (&d->lock);
(void)i_drop;
}
......@@ -156,7 +155,7 @@ void libvlc_log_clear( libvlc_log_t *p_log )
vlc_spin_unlock (&p_log->data.lock);
for (unsigned i = 0; i < sizeof (tab) / sizeof (tab[0]); i++)
msg_Release (tab[i]);
msg_Free (tab[i]);
}
libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log )
......
......@@ -248,19 +248,6 @@ void msg_Generic( vlc_object_t *p_this, int i_type, const char *psz_module,
va_end( args );
}
/**
* Destroys a message.
*/
static void msg_Free (gc_object_t *gc)
{
msg_item_t *msg = vlc_priv (gc, msg_item_t);
free (msg->psz_module);
free (msg->psz_msg);
free (msg->psz_header);
free (msg);
}
#undef msg_GenericVa
/**
* Add a message to a queue
......@@ -383,11 +370,9 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
if (p_item == NULL)
return; /* Uho! */
vlc_gc_init (p_item, msg_Free);
p_item->psz_module = p_item->psz_msg = p_item->psz_header = NULL;
i_header_size = 0;
p_obj = p_this;
while( p_obj != NULL )
......@@ -458,7 +443,7 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
sub->func (sub->opaque, p_item, 0);
}
vlc_rwlock_unlock (&bank->lock);
msg_Release (p_item);
msg_Free (p_item);
}
/*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment