Changeset 358c28c444e3063246c6d966b0834b1078018fdf
- Timestamp:
- 28/05/08 19:56:15
(4 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1211997375 +0300
- git-parent:
[2e7d3d7d1581487800fbdb820e26559b5f43de15]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1211997375 +0300
- Message:
intf_Destroy(): use vlc_object_release() and a destructor instead
While reading this, you will find a bunch of:
while (find (VLC_OBJECT_INTERFACE))
release; release;
These are of course plain BUGS (which are neither introduced nor fixed
by this commit). Imagine, for instance, what happens if two threads run
the code above at the same time... they end up releasing the interface
once too many.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9d85c35 |
r358c28c |
|
| 121 | 121 | VLC_EXPORT( int, intf_RunThread, ( intf_thread_t * ) ); |
|---|
| 122 | 122 | VLC_EXPORT( void, intf_StopThread, ( intf_thread_t * ) ); |
|---|
| 123 | | VLC_EXPORT( void, intf_Destroy, ( intf_thread_t * ) ); |
|---|
| 124 | 123 | |
|---|
| 125 | 124 | /* If the interface is in the main thread, it should listen both to |
|---|
| r6300760 |
r358c28c |
|
| 130 | 130 | vlc_object_detach( p_intf ); |
|---|
| 131 | 131 | vlc_object_release( p_intf ); |
|---|
| 132 | | intf_Destroy( p_intf ); |
|---|
| | 132 | vlc_object_release( p_intf ); |
|---|
| 133 | 133 | } |
|---|
| 134 | 134 | |
|---|
| r13ae40b |
r358c28c |
|
| 190 | 190 | vlc_object_detach( p_intf ); |
|---|
| 191 | 191 | vlc_object_release( p_intf ); |
|---|
| 192 | | intf_Destroy( p_intf ); |
|---|
| | 192 | vlc_object_release( p_intf ); |
|---|
| 193 | 193 | } |
|---|
| 194 | 194 | |
|---|
| r13ae40b |
r358c28c |
|
| 165 | 165 | vlc_object_detach( p_extraintf ); |
|---|
| 166 | 166 | vlc_object_release( p_extraintf ); |
|---|
| 167 | | intf_Destroy( p_extraintf ); |
|---|
| | 167 | vlc_object_release( p_extraintf ); |
|---|
| 168 | 168 | } |
|---|
| 169 | 169 | |
|---|
| … | … | |
| 333 | 333 | { |
|---|
| 334 | 334 | vlc_object_detach( p_new_intf ); |
|---|
| 335 | | intf_Destroy( p_new_intf ); |
|---|
| | 335 | vlc_object_release( p_new_intf ); |
|---|
| 336 | 336 | msg_Err( p_intf, "interface \"%s\" cannot run", psz_temp ); |
|---|
| 337 | 337 | } |
|---|
| r13ae40b |
r358c28c |
|
| 1544 | 1544 | { |
|---|
| 1545 | 1545 | vlc_object_detach( p_newintf ); |
|---|
| 1546 | | intf_Destroy( p_newintf ); |
|---|
| | 1546 | vlc_object_release( p_newintf ); |
|---|
| 1547 | 1547 | } |
|---|
| 1548 | 1548 | } |
|---|
| r6da90a1 |
r358c28c |
|
| 55 | 55 | vlc_value_t , vlc_value_t , void * ); |
|---|
| 56 | 56 | |
|---|
| | 57 | /** |
|---|
| | 58 | * \brief Destroy the interface after the main loop endeed. |
|---|
| | 59 | * |
|---|
| | 60 | * \param p_intf the interface thread |
|---|
| | 61 | * \return nothing |
|---|
| | 62 | */ |
|---|
| | 63 | static void intf_Destroy( vlc_object_t *obj ) |
|---|
| | 64 | { |
|---|
| | 65 | intf_thread_t *p_intf = (intf_thread_t *)obj; |
|---|
| | 66 | |
|---|
| | 67 | /* Unlock module if present (a switch may have failed) */ |
|---|
| | 68 | if( p_intf->p_module ) |
|---|
| | 69 | module_Unneed( p_intf, p_intf->p_module ); |
|---|
| | 70 | |
|---|
| | 71 | free( p_intf->psz_intf ); |
|---|
| | 72 | vlc_mutex_destroy( &p_intf->change_lock ); |
|---|
| | 73 | } |
|---|
| | 74 | |
|---|
| 57 | 75 | /***************************************************************************** |
|---|
| 58 | 76 | * intf_Create: prepare interface before main loop |
|---|
| … | … | |
| 115 | 133 | /* Attach interface to its parent object */ |
|---|
| 116 | 134 | vlc_object_attach( p_intf, p_this ); |
|---|
| | 135 | vlc_object_set_destructor( p_intf, intf_Destroy ); |
|---|
| 117 | 136 | |
|---|
| 118 | 137 | return p_intf; |
|---|
| … | … | |
| 141 | 160 | { |
|---|
| 142 | 161 | RunInterface( p_intf ); |
|---|
| | 162 | vlc_object_detach( p_intf ); |
|---|
| | 163 | vlc_object_release( p_intf ); |
|---|
| 143 | 164 | return VLC_SUCCESS; |
|---|
| 144 | 165 | } |
|---|
| … | … | |
| 172 | 193 | } |
|---|
| 173 | 194 | } |
|---|
| 174 | | |
|---|
| 175 | | /** |
|---|
| 176 | | * \brief Destroy the interface after the main loop endeed. |
|---|
| 177 | | * |
|---|
| 178 | | * Destroys interfaces and closes output devices |
|---|
| 179 | | * \param p_intf the interface thread |
|---|
| 180 | | * \return nothing |
|---|
| 181 | | */ |
|---|
| 182 | | void intf_Destroy( intf_thread_t *p_intf ) |
|---|
| 183 | | { |
|---|
| 184 | | /* Unlock module if present (a switch may have failed) */ |
|---|
| 185 | | if( p_intf->p_module ) |
|---|
| 186 | | { |
|---|
| 187 | | module_Unneed( p_intf, p_intf->p_module ); |
|---|
| 188 | | } |
|---|
| 189 | | free( p_intf->psz_intf ); |
|---|
| 190 | | |
|---|
| 191 | | vlc_mutex_destroy( &p_intf->change_lock ); |
|---|
| 192 | | |
|---|
| 193 | | /* Free structure */ |
|---|
| 194 | | vlc_object_release( p_intf ); |
|---|
| 195 | | } |
|---|
| 196 | | |
|---|
| 197 | 195 | |
|---|
| 198 | 196 | /* Following functions are local */ |
|---|
| … | … | |
| 284 | 282 | { |
|---|
| 285 | 283 | vlc_object_detach( p_intf ); |
|---|
| 286 | | intf_Destroy( p_intf ); |
|---|
| | 284 | vlc_object_release( p_intf ); |
|---|
| 287 | 285 | return VLC_EGENERIC; |
|---|
| 288 | 286 | } |
|---|
| re9b987f |
r358c28c |
|
| 937 | 937 | intf_StopThread( p_intf ); |
|---|
| 938 | 938 | vlc_object_detach( p_intf ); |
|---|
| 939 | | vlc_object_release( p_intf ); |
|---|
| 940 | | intf_Destroy( p_intf ); |
|---|
| 941 | | p_intf = NULL; |
|---|
| | 939 | vlc_object_release( p_intf ); /* for intf_Create() */ |
|---|
| | 940 | vlc_object_release( p_intf ); /* for vlc_object_find() */ |
|---|
| 942 | 941 | } |
|---|
| 943 | 942 | |
|---|
| … | … | |
| 1145 | 1144 | p_intf->b_play = b_play; |
|---|
| 1146 | 1145 | i_err = intf_RunThread( p_intf ); |
|---|
| 1147 | | if( i_err || p_intf->b_should_run_on_first_thread ) |
|---|
| | 1146 | if( i_err ) |
|---|
| 1148 | 1147 | { |
|---|
| 1149 | 1148 | vlc_object_detach( p_intf ); |
|---|
| 1150 | | intf_Destroy( p_intf ); |
|---|
| 1151 | | p_intf = NULL; |
|---|
| | 1149 | vlc_object_release( p_intf ); |
|---|
| 1152 | 1150 | return i_err; |
|---|
| 1153 | 1151 | } |
|---|
| … | … | |
| 1162 | 1160 | |
|---|
| 1163 | 1161 | vlc_object_detach( p_intf ); |
|---|
| 1164 | | intf_Destroy( p_intf ); |
|---|
| | 1162 | vlc_object_release( p_intf ); |
|---|
| 1165 | 1163 | } |
|---|
| 1166 | 1164 | |
|---|
| ra5387cb |
r358c28c |
|
| 148 | 148 | input_vaControl |
|---|
| 149 | 149 | __intf_Create |
|---|
| 150 | | intf_Destroy |
|---|
| 151 | 150 | __intf_Eject |
|---|
| 152 | 151 | __intf_Progress |
|---|