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 ...@@ -53,8 +53,6 @@ typedef struct
char * psz_module; char * psz_module;
char * psz_msg; /**< the message itself */ char * psz_msg; /**< the message itself */
char * psz_header; /**< Additional header */ char * psz_header; /**< Additional header */
gc_object_t vlc_gc_data;
} msg_item_t; } msg_item_t;
/* Message types */ /* Message types */
...@@ -67,15 +65,25 @@ typedef struct ...@@ -67,15 +65,25 @@ typedef struct
/** debug messages */ /** debug messages */
#define VLC_MSG_DBG 3 #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); msg_item_t *copy = (msg_item_t *)xmalloc (sizeof (*copy));
return msg; 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) ...@@ -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); vlc_mutex_lock(&p_sys->msg_lock);
if (p_sys->msgs[p_sys->i_msgs]) if (p_sys->msgs[p_sys->i_msgs])
msg_Release(p_sys->msgs[p_sys->i_msgs]); msg_Free(p_sys->msgs[p_sys->i_msgs]);
p_sys->msgs[p_sys->i_msgs++] = msg_Hold(msg); p_sys->msgs[p_sys->i_msgs++] = msg_Copy(msg);
if (p_sys->i_msgs == (sizeof p_sys->msgs / sizeof *p_sys->msgs)) if (p_sys->i_msgs == (sizeof p_sys->msgs / sizeof *p_sys->msgs))
p_sys->i_msgs = 0; p_sys->i_msgs = 0;
...@@ -1915,7 +1915,7 @@ static void Close(vlc_object_t *p_this) ...@@ -1915,7 +1915,7 @@ static void Close(vlc_object_t *p_this)
vlc_mutex_destroy(&p_sys->msg_lock); vlc_mutex_destroy(&p_sys->msg_lock);
for(unsigned i = 0; i < sizeof p_sys->msgs / sizeof *p_sys->msgs; i++) for(unsigned i = 0; i < sizeof p_sys->msgs / sizeof *p_sys->msgs; i++)
if (p_sys->msgs[i]) if (p_sys->msgs[i])
msg_Release(p_sys->msgs[i]); msg_Free(p_sys->msgs[i]);
free(p_sys); free(p_sys);
} }
...@@ -48,13 +48,13 @@ class MsgEvent : public QEvent ...@@ -48,13 +48,13 @@ class MsgEvent : public QEvent
{ {
public: public:
MsgEvent( msg_item_t *msg ) 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; msg_item_t *msg;
......
...@@ -53,12 +53,11 @@ static void handler( msg_cb_data_t *d, msg_item_t *p_item, unsigned i_drop ) ...@@ -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) if (p_item->i_type > d->verbosity)
return; return;
msg_item_t *msg = msg_Copy (p_item);
vlc_spin_lock (&d->lock); vlc_spin_lock (&d->lock);
if (d->count < VLC_MSG_QSIZE) if (d->count < VLC_MSG_QSIZE)
{ d->items[d->count++] = msg;
d->items[d->count++] = p_item;
msg_Hold (p_item);
}
vlc_spin_unlock (&d->lock); vlc_spin_unlock (&d->lock);
(void)i_drop; (void)i_drop;
} }
...@@ -156,7 +155,7 @@ void libvlc_log_clear( libvlc_log_t *p_log ) ...@@ -156,7 +155,7 @@ void libvlc_log_clear( libvlc_log_t *p_log )
vlc_spin_unlock (&p_log->data.lock); vlc_spin_unlock (&p_log->data.lock);
for (unsigned i = 0; i < sizeof (tab) / sizeof (tab[0]); i++) 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 ) 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, ...@@ -248,19 +248,6 @@ void msg_Generic( vlc_object_t *p_this, int i_type, const char *psz_module,
va_end( args ); 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 #undef msg_GenericVa
/** /**
* Add a message to a queue * Add a message to a queue
...@@ -383,11 +370,9 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, ...@@ -383,11 +370,9 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
if (p_item == NULL) if (p_item == NULL)
return; /* Uho! */ return; /* Uho! */
vlc_gc_init (p_item, msg_Free);
p_item->psz_module = p_item->psz_msg = p_item->psz_header = NULL; p_item->psz_module = p_item->psz_msg = p_item->psz_header = NULL;
i_header_size = 0; i_header_size = 0;
p_obj = p_this; p_obj = p_this;
while( p_obj != NULL ) while( p_obj != NULL )
...@@ -458,7 +443,7 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type, ...@@ -458,7 +443,7 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
sub->func (sub->opaque, p_item, 0); sub->func (sub->opaque, p_item, 0);
} }
vlc_rwlock_unlock (&bank->lock); 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