Changeset 257fdd4aead1f254c01cb4d1132a14cd5e0389a4
- Timestamp:
- 27/08/07 20:49:07
(1 year ago)
- Author:
- Pierre d'Herbemont <pdherbemont@videolan.org>
- git-committer:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1188240547 +0000
- git-parent:
[00749a2f54c87f20dfea50f5574e234702ef6433]
- git-author:
- Pierre d'Herbemont <pdherbemont@videolan.org> 1188240547 +0000
- Message:
control/event.c: Locking for libvlc event.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r8239a93 |
r257fdd4 |
|
| 77 | 77 | p_em->p_libvlc_instance = p_libvlc_inst; |
|---|
| 78 | 78 | ARRAY_INIT( p_em->listeners_groups ); |
|---|
| | 79 | vlc_mutex_init( p_libvlc_inst->p_libvlc_int, &p_em->object_lock ); |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | return p_em; |
|---|
| … | … | |
| 90 | 91 | libvlc_event_listeners_group_t * listeners_group; |
|---|
| 91 | 92 | libvlc_event_listener_t * listener; |
|---|
| | 93 | |
|---|
| | 94 | vlc_mutex_destroy( &p_em->object_lock ); |
|---|
| 92 | 95 | |
|---|
| 93 | 96 | FOREACH_ARRAY( listeners_group, p_em->listeners_groups ) |
|---|
| … | … | |
| 121 | 124 | ARRAY_INIT( listeners_group->listeners ); |
|---|
| 122 | 125 | |
|---|
| | 126 | vlc_mutex_lock( &p_em->object_lock ); |
|---|
| 123 | 127 | ARRAY_APPEND( p_em->listeners_groups, listeners_group ); |
|---|
| | 128 | vlc_mutex_unlock( &p_em->object_lock ); |
|---|
| 124 | 129 | } |
|---|
| 125 | 130 | |
|---|
| … | … | |
| 133 | 138 | { |
|---|
| 134 | 139 | libvlc_event_listeners_group_t * listeners_group; |
|---|
| 135 | | libvlc_event_listener_t * listener; |
|---|
| | 140 | libvlc_event_listener_t * listener_cached; |
|---|
| | 141 | libvlc_event_listener_t * listener; |
|---|
| | 142 | libvlc_event_listener_t * array_listeners_cached = NULL; |
|---|
| | 143 | int i, i_cached_listeners = 0; |
|---|
| | 144 | |
|---|
| 136 | 145 | /* Fill event with the sending object now */ |
|---|
| 137 | 146 | p_event->p_obj = p_em->p_obj; |
|---|
| 138 | 147 | |
|---|
| | 148 | vlc_mutex_lock( &p_em->object_lock ); |
|---|
| 139 | 149 | FOREACH_ARRAY( listeners_group, p_em->listeners_groups ) |
|---|
| 140 | 150 | if( listeners_group->event_type == p_event->type ) |
|---|
| 141 | 151 | { |
|---|
| 142 | | /* We found the group, now send every one the event */ |
|---|
| | 152 | if( listeners_group->listeners.i_size <= 0 ) |
|---|
| | 153 | break; |
|---|
| | 154 | |
|---|
| | 155 | /* Cache a copy of the listener to avoid locking issues */ |
|---|
| | 156 | i_cached_listeners = listeners_group->listeners.i_size; |
|---|
| | 157 | array_listeners_cached = malloc(sizeof(libvlc_event_listener_t)*(i_cached_listeners)); |
|---|
| | 158 | if( !array_listeners_cached ) |
|---|
| | 159 | { |
|---|
| | 160 | printf( "Can't alloc memory in libvlc_event_send" ); |
|---|
| | 161 | break; |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | listener_cached = array_listeners_cached; |
|---|
| 143 | 165 | FOREACH_ARRAY( listener, listeners_group->listeners ) |
|---|
| 144 | | listener->pf_callback( p_event, listener->p_user_data ); |
|---|
| | 166 | memcpy( listener_cached, listener, sizeof(libvlc_event_listener_t)); |
|---|
| | 167 | listener_cached += sizeof(libvlc_event_listener_t) ; |
|---|
| 145 | 168 | FOREACH_END() |
|---|
| 146 | 169 | break; |
|---|
| 147 | 170 | } |
|---|
| 148 | 171 | FOREACH_END() |
|---|
| | 172 | vlc_mutex_unlock( &p_em->object_lock ); |
|---|
| | 173 | |
|---|
| | 174 | listener_cached = array_listeners_cached; |
|---|
| | 175 | for( i = 0; i < i_cached_listeners; i++ ) |
|---|
| | 176 | { |
|---|
| | 177 | listener_cached->pf_callback( p_event, listener_cached->p_user_data ); |
|---|
| | 178 | listener_cached += sizeof(libvlc_event_listener_t) ; |
|---|
| | 179 | } |
|---|
| | 180 | free( array_listeners_cached ); |
|---|
| 149 | 181 | } |
|---|
| 150 | 182 | |
|---|
| … | … | |
| 176 | 208 | listener->p_user_data = p_user_data; |
|---|
| 177 | 209 | listener->pf_callback = pf_callback; |
|---|
| 178 | | |
|---|
| | 210 | |
|---|
| | 211 | vlc_mutex_lock( &p_event_manager->object_lock ); |
|---|
| 179 | 212 | FOREACH_ARRAY( listeners_group, p_event_manager->listeners_groups ) |
|---|
| 180 | 213 | if( listeners_group->event_type == listener->event_type ) |
|---|
| 181 | 214 | { |
|---|
| 182 | 215 | ARRAY_APPEND( listeners_group->listeners, listener ); |
|---|
| | 216 | vlc_mutex_unlock( &p_event_manager->object_lock ); |
|---|
| 183 | 217 | return; |
|---|
| 184 | 218 | } |
|---|
| 185 | 219 | FOREACH_END() |
|---|
| 186 | | |
|---|
| | 220 | vlc_mutex_unlock( &p_event_manager->object_lock ); |
|---|
| | 221 | |
|---|
| 187 | 222 | free(listener); |
|---|
| 188 | 223 | libvlc_exception_raise( p_e, |
|---|
| … | … | |
| 204 | 239 | libvlc_event_listeners_group_t * listeners_group; |
|---|
| 205 | 240 | libvlc_event_listener_t * listener; |
|---|
| | 241 | |
|---|
| | 242 | vlc_mutex_lock( &p_event_manager->object_lock ); |
|---|
| 206 | 243 | FOREACH_ARRAY( listeners_group, p_event_manager->listeners_groups ) |
|---|
| 207 | 244 | if( listeners_group->event_type == event_type ) |
|---|
| … | … | |
| 217 | 254 | fe_idx /* This comes from the macro (and that's why |
|---|
| 218 | 255 | I hate macro) */ ); |
|---|
| | 256 | vlc_mutex_unlock( &p_event_manager->object_lock ); |
|---|
| 219 | 257 | return; |
|---|
| 220 | 258 | } |
|---|
| … | … | |
| 222 | 260 | } |
|---|
| 223 | 261 | FOREACH_END() |
|---|
| | 262 | vlc_mutex_unlock( &p_event_manager->object_lock ); |
|---|
| 224 | 263 | |
|---|
| 225 | 264 | libvlc_exception_raise( p_e, |
|---|
| … | … | |
| 227 | 266 | event_type, pf_callback, p_user_data ); |
|---|
| 228 | 267 | } |
|---|
| 229 | | |
|---|
| r48586f5 |
r257fdd4 |
|
| 224 | 224 | struct libvlc_instance_t * p_libvlc_instance; |
|---|
| 225 | 225 | DECL_ARRAY(libvlc_event_listeners_group_t *) listeners_groups; |
|---|
| | 226 | vlc_mutex_t object_lock; |
|---|
| 226 | 227 | } libvlc_event_sender_t; |
|---|
| 227 | 228 | |
|---|
| … | … | |
| 248 | 249 | |
|---|
| 249 | 250 | /* Media List */ |
|---|
| 250 | | VLC_EXPORT ( void, libvlc_media_list_flat_media_list_release, |
|---|
| 251 | | ( libvlc_media_list_t * ) ); |
|---|
| | 251 | VLC_EXPORT ( void, libvlc_media_list_flat_media_list_release, ( libvlc_media_list_t * ) ); |
|---|
| 252 | 252 | |
|---|
| 253 | 253 | /* Events */ |
|---|