[vlc-commits] stats: remove the lock
Rémi Denis-Courmont
git at videolan.org
Mon Dec 11 21:02:27 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Dec 11 21:01:32 2017 +0200| [cc70e92424100e6f8c60f9342ec8e9b2d375dd1b] | committer: Rémi Denis-Courmont
stats: remove the lock
The containing input item lock already must be held while reading or
writing statistics, so this is redundant.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cc70e92424100e6f8c60f9342ec8e9b2d375dd1b
---
include/vlc_input_item.h | 2 --
lib/media.c | 2 --
modules/control/oldrc.c | 2 --
modules/gui/macosx/VLCPlaylistInfo.m | 4 ----
modules/gui/ncurses.c | 2 --
modules/gui/qt/components/info_panels.cpp | 4 ----
modules/lua/libs/input.c | 2 --
src/input/input.c | 10 +++++++---
src/input/input_interface.h | 4 ----
src/input/item.c | 6 +-----
src/input/stats.c | 14 --------------
src/text/strings.c | 4 ----
12 files changed, 8 insertions(+), 48 deletions(-)
diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index f22c3d9330..e83aba27fa 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -389,8 +389,6 @@ VLC_API void libvlc_MetadataCancel( libvlc_int_t *, void * );
******************/
struct input_stats_t
{
- vlc_mutex_t lock;
-
/* Input */
int64_t i_read_packets;
int64_t i_read_bytes;
diff --git a/lib/media.c b/lib/media.c
index 54875d6a0e..36f2b6eea6 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -712,7 +712,6 @@ int libvlc_media_get_stats( libvlc_media_t *p_md,
return false;
}
- vlc_mutex_lock( &p_itm_stats->lock );
p_stats->i_read_bytes = p_itm_stats->i_read_bytes;
p_stats->f_input_bitrate = p_itm_stats->f_input_bitrate;
@@ -733,7 +732,6 @@ int libvlc_media_get_stats( libvlc_media_t *p_md,
p_stats->i_sent_packets = p_itm_stats->i_sent_packets;
p_stats->i_sent_bytes = p_itm_stats->i_sent_bytes;
p_stats->f_send_bitrate = p_itm_stats->f_send_bitrate;
- vlc_mutex_unlock( &p_itm_stats->lock );
vlc_mutex_unlock( &item->lock );
return true;
}
diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c
index 66402293a5..acb3a70ffa 100644
--- a/modules/control/oldrc.c
+++ b/modules/control/oldrc.c
@@ -1715,7 +1715,6 @@ static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
if( !p_item ) return VLC_EGENERIC;
vlc_mutex_lock( &p_item->lock );
- vlc_mutex_lock( &p_item->p_stats->lock );
msg_rc( "+----[ begin of statistical info ]" );
/* Input */
@@ -1761,7 +1760,6 @@ static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
(float)(p_item->p_stats->f_send_bitrate*8)*1000 );
msg_rc("|");
msg_rc( "+----[ end of statistical info ]" );
- vlc_mutex_unlock( &p_item->p_stats->lock );
vlc_mutex_unlock( &p_item->lock );
return VLC_SUCCESS;
diff --git a/modules/gui/macosx/VLCPlaylistInfo.m b/modules/gui/macosx/VLCPlaylistInfo.m
index 2ff290952b..f11a091bb1 100644
--- a/modules/gui/macosx/VLCPlaylistInfo.m
+++ b/modules/gui/macosx/VLCPlaylistInfo.m
@@ -276,8 +276,6 @@ FREENULL( psz_##foo );
if (![self.window isVisible])
return;
- vlc_mutex_lock(&p_item->p_stats->lock);
-
/* input */
[_readBytesTextField setStringValue: [NSString stringWithFormat:
@"%8.0f KiB", (float)(p_item->p_stats->i_read_bytes)/1024]];
@@ -304,8 +302,6 @@ FREENULL( psz_##foo );
[_audioDecodedTextField setIntValue: p_item->p_stats->i_decoded_audio];
[_playedAudioBuffersTextField setIntValue: p_item->p_stats->i_played_abuffers];
[_lostAudioBuffersTextField setIntValue: p_item->p_stats->i_lost_abuffers];
-
- vlc_mutex_unlock(&p_item->p_stats->lock);
}
- (void)updateStreamsList
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index 6ed98558ec..21fabac77b 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -796,7 +796,6 @@ static int DrawStats(intf_thread_t *intf, input_thread_t *p_input)
vlc_mutex_lock(&item->lock);
p_stats = item->p_stats;
- vlc_mutex_lock(&p_stats->lock);
for (int i = 0; i < item->i_es ; i++) {
i_audio += (item->es[i]->i_cat == AUDIO_ES);
@@ -851,7 +850,6 @@ static int DrawStats(intf_thread_t *intf, input_thread_t *p_input)
p_stats->f_send_bitrate*8000);
if (sys->color) color_set(C_DEFAULT, NULL);
- vlc_mutex_unlock(&p_stats->lock);
vlc_mutex_unlock(&item->lock);
return l;
diff --git a/modules/gui/qt/components/info_panels.cpp b/modules/gui/qt/components/info_panels.cpp
index 5376be235c..626aa737db 100644
--- a/modules/gui/qt/components/info_panels.cpp
+++ b/modules/gui/qt/components/info_panels.cpp
@@ -651,8 +651,6 @@ void InputStatsPanel::update( input_item_t *p_item )
if( p_item->p_stats == NULL )
return;
- vlc_mutex_lock( &p_item->p_stats->lock );
-
#define UPDATE_INT( widget, calc... ) \
{ widget->setText( 1, QString::number( (qulonglong)calc ) ); }
@@ -685,8 +683,6 @@ void InputStatsPanel::update( input_item_t *p_item )
#undef UPDATE_INT
#undef UPDATE_FLOAT
-
- vlc_mutex_unlock(& p_item->p_stats->lock );
}
void InputStatsPanel::clear()
diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
index 7490cd5d26..fb09539bea 100644
--- a/modules/lua/libs/input.c
+++ b/modules/lua/libs/input.c
@@ -198,7 +198,6 @@ static int vlclua_input_item_stats( lua_State *L )
input_stats_t *p_stats = p_item->p_stats;
if( p_stats != NULL )
{
- vlc_mutex_lock( &p_item->p_stats->lock );
#define STATS_INT( n ) lua_pushinteger( L, p_item->p_stats->i_ ## n ); \
lua_setfield( L, -2, #n );
#define STATS_FLOAT( n ) lua_pushnumber( L, p_item->p_stats->f_ ## n ); \
@@ -224,7 +223,6 @@ static int vlclua_input_item_stats( lua_State *L )
STATS_INT( lost_abuffers )
#undef STATS_INT
#undef STATS_FLOAT
- vlc_mutex_unlock( &p_item->p_stats->lock );
}
vlc_mutex_unlock( &p_item->lock );
return 1;
diff --git a/src/input/input.c b/src/input/input.c
index ed6a6eb9d1..4b654f5f65 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -344,7 +344,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
vlc_mutex_lock( &p_item->lock );
if( !p_item->p_stats )
- p_item->p_stats = stats_NewInputStats( p_input );
+ p_item->p_stats = calloc( 1, sizeof(*p_item->p_stats) );
/* setup the preparse depth of the item
* if we are preparsing, use the i_preparse_depth of the parent item */
@@ -669,9 +669,10 @@ static void MainLoopStatistics( input_thread_t *p_input )
/* update current bookmark */
vlc_mutex_lock( &input_priv(p_input)->p_item->lock );
input_priv(p_input)->bookmark.i_time_offset = i_time;
- vlc_mutex_unlock( &input_priv(p_input)->p_item->lock );
stats_ComputeInputStats( p_input, input_priv(p_input)->p_item->p_stats );
+ vlc_mutex_unlock( &input_priv(p_input)->p_item->lock );
+
input_SendEventStatistics( p_input );
}
@@ -1479,8 +1480,11 @@ do { \
if( libvlc_stats( p_input ) )
{
+ input_item_t *item = priv->p_item;
/* make sure we are up to date */
- stats_ComputeInputStats( p_input, priv->p_item->p_stats );
+ vlc_mutex_lock( &item->lock );
+ stats_ComputeInputStats( p_input, item->p_stats );
+ vlc_mutex_unlock( &item->lock );
CL_CO( input_bitrate );
CL_CO( demux_bitrate );
}
diff --git a/src/input/input_interface.h b/src/input/input_interface.h
index a98d3998b4..c89d2a7340 100644
--- a/src/input/input_interface.h
+++ b/src/input/input_interface.h
@@ -53,10 +53,6 @@ void input_item_SetEpgOffline( input_item_t * );
input_thread_t *input_CreatePreparser(vlc_object_t *obj, input_item_t *item)
VLC_USED;
-/* misc/stats.c
- * FIXME it should NOT be defined here or not coded in misc/stats.c */
-input_stats_t *stats_NewInputStats( input_thread_t *p_input );
-
/**
* This function deletes the current sout in the resources.
*/
diff --git a/src/input/item.c b/src/input/item.c
index 2000de84a2..8ad8a01f7c 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -486,11 +486,7 @@ void input_item_Release( input_item_t *p_item )
free( p_item->psz_name );
free( p_item->psz_uri );
- if( p_item->p_stats != NULL )
- {
- vlc_mutex_destroy( &p_item->p_stats->lock );
- free( p_item->p_stats );
- }
+ free( p_item->p_stats );
if( p_item->p_meta != NULL )
vlc_meta_Delete( p_item->p_meta );
diff --git a/src/input/stats.c b/src/input/stats.c
index 5210ea28de..ef13468522 100644
--- a/src/input/stats.c
+++ b/src/input/stats.c
@@ -67,18 +67,6 @@ static inline float stats_GetRate(const counter_t *counter)
/ (float)(counter->pp_samples[0]->date - counter->pp_samples[1]->date);
}
-input_stats_t *stats_NewInputStats( input_thread_t *p_input )
-{
- (void)p_input;
- input_stats_t *p_stats = calloc( 1, sizeof(input_stats_t) );
- if( !p_stats )
- return NULL;
-
- vlc_mutex_init( &p_stats->lock );
-
- return p_stats;
-}
-
void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
{
input_thread_private_t *priv = input_priv(input);
@@ -87,7 +75,6 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
return;
vlc_mutex_lock(&priv->counters.counters_lock);
- vlc_mutex_lock(&st->lock);
/* Input */
st->i_read_packets = priv->counters.read_packets;
@@ -118,7 +105,6 @@ void stats_ComputeInputStats(input_thread_t *input, input_stats_t *st)
st->i_displayed_pictures = priv->counters.displayed_pictures;
st->i_lost_pictures = priv->counters.lost_pictures;
- vlc_mutex_unlock(&st->lock);
vlc_mutex_unlock(&priv->counters.counters_lock);
}
diff --git a/src/text/strings.c b/src/text/strings.c
index 4b282bb397..d610c62cad 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -593,12 +593,8 @@ char *vlc_strfinput(input_thread_t *input, const char *s)
{
vlc_mutex_lock(&item->lock);
if (item->p_stats != NULL)
- {
- vlc_mutex_lock(&item->p_stats->lock);
vlc_memstream_printf(stream, "%"PRIi64,
item->p_stats->i_displayed_pictures);
- vlc_mutex_unlock(&item->p_stats->lock);
- }
else if (!b_empty_if_na)
vlc_memstream_putc(stream, '-');
vlc_mutex_unlock(&item->lock);
More information about the vlc-commits
mailing list