Changeset 8dba805732a431558c1218104dfeb667d9b5df63
- Timestamp:
- 05/16/08 18:01:19
(4 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1210953679 +0300
- git-parent:
[414624cea784dc0c97bb99826bad98b3c95fda36]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1210949943 +0300
- Message:
Hide i_children and pp_children away
They can only be read safely under the Big Structure Lock in
src/misc/objects.c, so it makes no sense for them to be public.
By the way, making i_children volatile wouldn't magically solve
thread-safety issues. The only correct use of volatile is in dealing
with asynchronous changes _within_ the same thread, such as signal
handling.
P.S.: I wish modules were not objects, and I wonder why they are
(they don't don't use threads, nor plugins, nor variables)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r9a719ad |
r8dba805 |
|
| 482 | 482 | \ |
|---|
| 483 | 483 | vlc_object_t * p_parent; /**< our parent */ \ |
|---|
| 484 | | vlc_object_t ** pp_children; /**< our children */ \ |
|---|
| 485 | | volatile int i_children; \ |
|---|
| 486 | 484 | \ |
|---|
| 487 | 485 | /* Private data */ \ |
|---|
| r4ec082c |
r8dba805 |
|
| 427 | 427 | |
|---|
| 428 | 428 | msg_Dbg( p_libvlc, "module bank initialized, found %i modules", |
|---|
| 429 | | p_libvlc_global->p_module_bank->i_children ); |
|---|
| | 429 | vlc_internals( p_libvlc_global->p_module_bank )->i_children ); |
|---|
| 430 | 430 | |
|---|
| 431 | 431 | /* Check for help on modules */ |
|---|
| rc79a340 |
r8dba805 |
|
| 182 | 182 | unsigned i_refcount; |
|---|
| 183 | 183 | vlc_destructor_t pf_destructor; |
|---|
| | 184 | |
|---|
| | 185 | vlc_object_t **pp_children; |
|---|
| | 186 | int i_children; |
|---|
| 184 | 187 | }; |
|---|
| 185 | 188 | |
|---|
| r73edaec |
r8dba805 |
|
| 160 | 160 | p_priv->b_thread = false; |
|---|
| 161 | 161 | p_new->p_parent = NULL; |
|---|
| 162 | | p_new->pp_children = NULL; |
|---|
| 163 | | p_new->i_children = 0; |
|---|
| | 162 | p_priv->pp_children = NULL; |
|---|
| | 163 | p_priv->i_children = 0; |
|---|
| 164 | 164 | |
|---|
| 165 | 165 | p_new->p_private = NULL; |
|---|
| … | … | |
| 323 | 323 | |
|---|
| 324 | 324 | /* Sanity checks */ |
|---|
| 325 | | if( p_this->i_children ) |
|---|
| | 325 | if( p_priv->i_children ) |
|---|
| 326 | 326 | { |
|---|
| 327 | 327 | int i; |
|---|
| … | … | |
| 330 | 330 | "ERROR: cannot delete object (%i, %s) with %d children\n", |
|---|
| 331 | 331 | p_this->i_object_id, p_this->psz_object_name, |
|---|
| 332 | | p_this->i_children ); |
|---|
| 333 | | |
|---|
| 334 | | for( i = 0; i < p_this->i_children; i++ ) |
|---|
| | 332 | p_priv->i_children ); |
|---|
| | 333 | |
|---|
| | 334 | for( i = 0; i < p_priv->i_children; i++ ) |
|---|
| 335 | 335 | { |
|---|
| 336 | 336 | fprintf( stderr, |
|---|
| 337 | 337 | "ERROR: Remaining children object " |
|---|
| 338 | 338 | "(id:%i, type:%s, name:%s)\n", |
|---|
| 339 | | p_this->pp_children[i]->i_object_id, |
|---|
| 340 | | p_this->pp_children[i]->psz_object_type, |
|---|
| 341 | | p_this->pp_children[i]->psz_object_name ); |
|---|
| | 339 | p_priv->pp_children[i]->i_object_id, |
|---|
| | 340 | p_priv->pp_children[i]->psz_object_type, |
|---|
| | 341 | p_priv->pp_children[i]->psz_object_name ); |
|---|
| 342 | 342 | } |
|---|
| 343 | 343 | fflush(stderr); |
|---|
| … | … | |
| 653 | 653 | |
|---|
| 654 | 654 | if( p_this->i_object_type == VLC_OBJECT_LIBVLC ) |
|---|
| 655 | | for( int i = 0; i < p_this->i_children ; i++ ) |
|---|
| 656 | | vlc_object_kill( p_this->pp_children[i] ); |
|---|
| | 655 | for( int i = 0; i < internals->i_children ; i++ ) |
|---|
| | 656 | vlc_object_kill( internals->pp_children[i] ); |
|---|
| 657 | 657 | |
|---|
| 658 | 658 | vlc_object_signal_unlocked( p_this ); |
|---|
| … | … | |
| 881 | 881 | vlc_object_detach_unlocked (p_this); |
|---|
| 882 | 882 | /* Detach from children to protect against FIND_PARENT */ |
|---|
| 883 | | for (int i = 0; i < p_this->i_children; i++) |
|---|
| 884 | | p_this->pp_children[i]->p_parent = NULL; |
|---|
| | 883 | for (int i = 0; i < internals->i_children; i++) |
|---|
| | 884 | internals->pp_children[i]->p_parent = NULL; |
|---|
| 885 | 885 | } |
|---|
| 886 | 886 | |
|---|
| … | … | |
| 909 | 909 | |
|---|
| 910 | 910 | /* Attach the child to its parent */ |
|---|
| 911 | | INSERT_ELEM( p_parent->pp_children, p_parent->i_children, |
|---|
| 912 | | p_parent->i_children, p_this ); |
|---|
| | 911 | vlc_object_internals_t *priv = vlc_internals( p_parent ); |
|---|
| | 912 | INSERT_ELEM( priv->pp_children, priv->i_children, priv->i_children, |
|---|
| | 913 | p_this ); |
|---|
| 913 | 914 | |
|---|
| 914 | 915 | vlc_mutex_unlock( &structure_lock ); |
|---|
| … | … | |
| 920 | 921 | assert (p_this->p_parent); |
|---|
| 921 | 922 | |
|---|
| 922 | | vlc_object_t *p_parent = p_this->p_parent; |
|---|
| | 923 | vlc_object_internals_t *priv = vlc_internals( p_this->p_parent ); |
|---|
| | 924 | |
|---|
| 923 | 925 | int i_index, i; |
|---|
| 924 | 926 | |
|---|
| … | … | |
| 927 | 929 | |
|---|
| 928 | 930 | /* Remove all of p_parent's children which are p_this */ |
|---|
| 929 | | for( i_index = p_parent->i_children ; i_index-- ; ) |
|---|
| 930 | | { |
|---|
| 931 | | if( p_parent->pp_children[i_index] == p_this ) |
|---|
| 932 | | { |
|---|
| 933 | | p_parent->i_children--; |
|---|
| 934 | | for( i = i_index ; i < p_parent->i_children ; i++ ) |
|---|
| 935 | | { |
|---|
| 936 | | p_parent->pp_children[i] = p_parent->pp_children[i+1]; |
|---|
| 937 | | } |
|---|
| 938 | | } |
|---|
| 939 | | } |
|---|
| 940 | | |
|---|
| 941 | | if( p_parent->i_children ) |
|---|
| 942 | | { |
|---|
| 943 | | p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children, |
|---|
| 944 | | p_parent->i_children * sizeof(vlc_object_t *) ); |
|---|
| | 931 | for( i_index = priv->i_children ; i_index-- ; ) |
|---|
| | 932 | { |
|---|
| | 933 | if( priv->pp_children[i_index] == p_this ) |
|---|
| | 934 | { |
|---|
| | 935 | priv->i_children--; |
|---|
| | 936 | for( i = i_index ; i < priv->i_children ; i++ ) |
|---|
| | 937 | priv->pp_children[i] = priv->pp_children[i+1]; |
|---|
| | 938 | } |
|---|
| | 939 | } |
|---|
| | 940 | |
|---|
| | 941 | if( priv->i_children ) |
|---|
| | 942 | { |
|---|
| | 943 | priv->pp_children = (vlc_object_t **)realloc( priv->pp_children, |
|---|
| | 944 | priv->i_children * sizeof(vlc_object_t *) ); |
|---|
| 945 | 945 | } |
|---|
| 946 | 946 | else |
|---|
| 947 | 947 | { |
|---|
| 948 | 948 | /* Special case - don't realloc() to zero to avoid leaking */ |
|---|
| 949 | | free( p_parent->pp_children ); |
|---|
| 950 | | p_parent->pp_children = NULL; |
|---|
| | 949 | free( priv->pp_children ); |
|---|
| | 950 | priv->pp_children = NULL; |
|---|
| 951 | 951 | } |
|---|
| 952 | 952 | } |
|---|
| … | … | |
| 1030 | 1030 | { |
|---|
| 1031 | 1031 | vlc_list_t *l; |
|---|
| | 1032 | vlc_object_internals_t *priv = vlc_internals( obj ); |
|---|
| 1032 | 1033 | |
|---|
| 1033 | 1034 | vlc_mutex_lock( &structure_lock ); |
|---|
| 1034 | | l = NewList( obj->i_children ); |
|---|
| | 1035 | l = NewList( priv->i_children ); |
|---|
| 1035 | 1036 | for (int i = 0; i < l->i_count; i++) |
|---|
| 1036 | 1037 | { |
|---|
| 1037 | | vlc_object_yield( obj->pp_children[i] ); |
|---|
| 1038 | | l->p_values[i].p_object = obj->pp_children[i]; |
|---|
| | 1038 | vlc_object_yield( priv->pp_children[i] ); |
|---|
| | 1039 | l->p_values[i].p_object = priv->pp_children[i]; |
|---|
| 1039 | 1040 | } |
|---|
| 1040 | 1041 | vlc_mutex_unlock( &structure_lock ); |
|---|
| … | … | |
| 1305 | 1306 | |
|---|
| 1306 | 1307 | case FIND_CHILD: |
|---|
| 1307 | | for( i = p_this->i_children; i--; ) |
|---|
| 1308 | | { |
|---|
| 1309 | | p_tmp = p_this->pp_children[i]; |
|---|
| | 1308 | for( i = vlc_internals( p_this )->i_children; i--; ) |
|---|
| | 1309 | { |
|---|
| | 1310 | p_tmp = vlc_internals( p_this )->pp_children[i]; |
|---|
| 1310 | 1311 | if( p_tmp->i_object_type == i_type ) |
|---|
| 1311 | 1312 | { |
|---|
| … | … | |
| 1313 | 1314 | return p_tmp; |
|---|
| 1314 | 1315 | } |
|---|
| 1315 | | else if( p_tmp->i_children ) |
|---|
| | 1316 | else if( vlc_internals( p_tmp )->i_children ) |
|---|
| 1316 | 1317 | { |
|---|
| 1317 | 1318 | p_tmp = FindObject( p_tmp, i_type, i_mode ); |
|---|
| … | … | |
| 1359 | 1360 | |
|---|
| 1360 | 1361 | case FIND_CHILD: |
|---|
| 1361 | | for( i = p_this->i_children; i--; ) |
|---|
| 1362 | | { |
|---|
| 1363 | | p_tmp = p_this->pp_children[i]; |
|---|
| | 1362 | for( i = vlc_internals( p_this )->i_children; i--; ) |
|---|
| | 1363 | { |
|---|
| | 1364 | p_tmp = vlc_internals( p_this )->pp_children[i]; |
|---|
| 1364 | 1365 | if( p_tmp->psz_object_name |
|---|
| 1365 | 1366 | && !strcmp( p_tmp->psz_object_name, psz_name ) ) |
|---|
| … | … | |
| 1368 | 1369 | return p_tmp; |
|---|
| 1369 | 1370 | } |
|---|
| 1370 | | else if( p_tmp->i_children ) |
|---|
| | 1371 | else if( vlc_internals( p_tmp )->i_children ) |
|---|
| 1371 | 1372 | { |
|---|
| 1372 | 1373 | p_tmp = FindObjectName( p_tmp, psz_name, i_mode ); |
|---|
| … | … | |
| 1402 | 1403 | |
|---|
| 1403 | 1404 | psz_children[0] = '\0'; |
|---|
| 1404 | | switch( p_this->i_children ) |
|---|
| | 1405 | switch( vlc_internals( p_this )->i_children ) |
|---|
| 1405 | 1406 | { |
|---|
| 1406 | 1407 | case 0: |
|---|
| … | … | |
| 1410 | 1411 | break; |
|---|
| 1411 | 1412 | default: |
|---|
| 1412 | | snprintf( psz_children, 19, ", %i children", p_this->i_children ); |
|---|
| | 1413 | snprintf( psz_children, 19, ", %i children", |
|---|
| | 1414 | vlc_internals( p_this )->i_children ); |
|---|
| 1413 | 1415 | break; |
|---|
| 1414 | 1416 | } |
|---|
| … | … | |
| 1450 | 1452 | } |
|---|
| 1451 | 1453 | |
|---|
| 1452 | | for( i = 0 ; i < p_this->i_children ; i++ ) |
|---|
| | 1454 | for( i = 0 ; i < vlc_internals( p_this )->i_children ; i++ ) |
|---|
| 1453 | 1455 | { |
|---|
| 1454 | 1456 | if( i_level ) |
|---|
| … | … | |
| 1462 | 1464 | } |
|---|
| 1463 | 1465 | |
|---|
| 1464 | | if( i == p_this->i_children - 1 ) |
|---|
| | 1466 | if( i == vlc_internals( p_this )->i_children - 1 ) |
|---|
| 1465 | 1467 | { |
|---|
| 1466 | 1468 | psz_foo[i_level] = '`'; |
|---|
| … | … | |
| 1474 | 1476 | psz_foo[i_level+2] = '\0'; |
|---|
| 1475 | 1477 | |
|---|
| 1476 | | DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo ); |
|---|
| | 1478 | DumpStructure( vlc_internals( p_this )->pp_children[i], i_level + 2, |
|---|
| | 1479 | psz_foo ); |
|---|
| 1477 | 1480 | } |
|---|
| 1478 | 1481 | } |
|---|
| … | … | |
| 1547 | 1550 | int i, i_count = 0; |
|---|
| 1548 | 1551 | |
|---|
| 1549 | | for( i = 0; i < p_this->i_children; i++ ) |
|---|
| 1550 | | { |
|---|
| 1551 | | p_tmp = p_this->pp_children[i]; |
|---|
| | 1552 | for( i = 0; i < vlc_internals( p_this )->i_children; i++ ) |
|---|
| | 1553 | { |
|---|
| | 1554 | p_tmp = vlc_internals( p_this )->pp_children[i]; |
|---|
| 1552 | 1555 | |
|---|
| 1553 | 1556 | if( p_tmp->i_object_type == i_type ) |
|---|
| … | … | |
| 1555 | 1558 | i_count++; |
|---|
| 1556 | 1559 | } |
|---|
| 1557 | | |
|---|
| 1558 | | if( p_tmp->i_children ) |
|---|
| 1559 | | { |
|---|
| 1560 | | i_count += CountChildren( p_tmp, i_type ); |
|---|
| 1561 | | } |
|---|
| | 1560 | i_count += CountChildren( p_tmp, i_type ); |
|---|
| 1562 | 1561 | } |
|---|
| 1563 | 1562 | |
|---|
| … | … | |
| 1570 | 1569 | int i; |
|---|
| 1571 | 1570 | |
|---|
| 1572 | | for( i = 0; i < p_this->i_children; i++ ) |
|---|
| 1573 | | { |
|---|
| 1574 | | p_tmp = p_this->pp_children[i]; |
|---|
| | 1571 | for( i = 0; i < vlc_internals( p_this )->i_children; i++ ) |
|---|
| | 1572 | { |
|---|
| | 1573 | p_tmp = vlc_internals( p_this )->pp_children[i]; |
|---|
| 1575 | 1574 | |
|---|
| 1576 | 1575 | if( p_tmp->i_object_type == i_type ) |
|---|
| 1577 | | { |
|---|
| 1578 | 1576 | ListReplace( p_list, p_tmp, p_list->i_count++ ); |
|---|
| 1579 | | } |
|---|
| 1580 | | |
|---|
| 1581 | | if( p_tmp->i_children ) |
|---|
| 1582 | | { |
|---|
| 1583 | | ListChildren( p_list, p_tmp, i_type ); |
|---|
| 1584 | | } |
|---|
| 1585 | | } |
|---|
| 1586 | | } |
|---|
| | 1577 | |
|---|
| | 1578 | ListChildren( p_list, p_tmp, i_type ); |
|---|
| | 1579 | } |
|---|
| | 1580 | } |
|---|
| r75c438d |
r8dba805 |
|
| 35 | 35 | #include <stdio.h> /* sprintf() */ |
|---|
| 36 | 36 | #include <string.h> /* strdup() */ |
|---|
| | 37 | #include <vlc_plugin.h> |
|---|
| 37 | 38 | |
|---|
| 38 | 39 | #ifdef HAVE_SYS_TYPES_H |
|---|
| … | … | |
| 563 | 564 | SAVE_STRING( pp_cache[i]->p_module->psz_filename ); |
|---|
| 564 | 565 | |
|---|
| 565 | | i_submodule = pp_cache[i]->p_module->i_children; |
|---|
| | 566 | i_submodule = vlc_internals( pp_cache[i]->p_module )->i_children; |
|---|
| 566 | 567 | SAVE_IMMEDIATE( i_submodule ); |
|---|
| 567 | 568 | for( i_submodule = 0; |
|---|
| 568 | | i_submodule < (unsigned)pp_cache[i]->p_module->i_children; |
|---|
| | 569 | i_submodule < (unsigned)vlc_internals( pp_cache[i]->p_module)->i_children; |
|---|
| 569 | 570 | i_submodule++ ) |
|---|
| 570 | 571 | { |
|---|
| 571 | 572 | module_t *p_module = |
|---|
| 572 | | (module_t *)pp_cache[i]->p_module->pp_children[i_submodule]; |
|---|
| | 573 | (module_t *)vlc_internals( pp_cache[i]->p_module )->pp_children[i_submodule]; |
|---|
| 573 | 574 | |
|---|
| 574 | 575 | SAVE_STRING( p_module->psz_object_name ); |
|---|
| … | … | |
| 687 | 688 | p_cache->handle = p_module->handle; |
|---|
| 688 | 689 | |
|---|
| 689 | | for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) |
|---|
| 690 | | { |
|---|
| 691 | | module_t *p_child = (module_t*)p_module->pp_children[i_submodule]; |
|---|
| 692 | | module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule]; |
|---|
| | 690 | for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) |
|---|
| | 691 | { |
|---|
| | 692 | module_t *p_child = (module_t*)vlc_internals( p_module )->pp_children[i_submodule]; |
|---|
| | 693 | module_t *p_cchild = (module_t*)vlc_internals( p_cache )->pp_children[i_submodule]; |
|---|
| 693 | 694 | p_cchild->pf_activate = p_child->pf_activate; |
|---|
| 694 | 695 | p_cchild->pf_deactivate = p_child->pf_deactivate; |
|---|
| r48a985e |
r8dba805 |
|
| 215 | 215 | vlc_object_detach( p_libvlc_global->p_module_bank ); |
|---|
| 216 | 216 | |
|---|
| 217 | | while( p_libvlc_global->p_module_bank->i_children ) |
|---|
| 218 | | { |
|---|
| 219 | | p_next = (module_t *)p_libvlc_global->p_module_bank->pp_children[0]; |
|---|
| | 217 | while( vlc_internals( p_libvlc_global->p_module_bank )->i_children ) |
|---|
| | 218 | { |
|---|
| | 219 | p_next = (module_t *)vlc_internals( p_libvlc_global->p_module_bank )->pp_children[0]; |
|---|
| 220 | 220 | DeleteModule( p_next, true ); |
|---|
| 221 | 221 | } |
|---|
| … | … | |
| 1291 | 1291 | : NULL; |
|---|
| 1292 | 1292 | |
|---|
| 1293 | | for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) |
|---|
| 1294 | | { |
|---|
| 1295 | | DupModule( (module_t*)p_module->pp_children[ i_submodule ] ); |
|---|
| | 1293 | for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) |
|---|
| | 1294 | { |
|---|
| | 1295 | DupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] ); |
|---|
| 1296 | 1296 | } |
|---|
| 1297 | 1297 | } |
|---|
| … | … | |
| 1307 | 1307 | int i_submodule; |
|---|
| 1308 | 1308 | |
|---|
| 1309 | | for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ ) |
|---|
| 1310 | | { |
|---|
| 1311 | | UndupModule( (module_t*)p_module->pp_children[ i_submodule ] ); |
|---|
| | 1309 | for( i_submodule = 0; i_submodule < vlc_internals( p_module )->i_children; i_submodule++ ) |
|---|
| | 1310 | { |
|---|
| | 1311 | UndupModule( (module_t*)vlc_internals( p_module )->pp_children[ i_submodule ] ); |
|---|
| 1312 | 1312 | } |
|---|
| 1313 | 1313 | |
|---|
| … | … | |
| 1394 | 1394 | |
|---|
| 1395 | 1395 | /* Free and detach the object's children */ |
|---|
| 1396 | | while( p_module->i_children ) |
|---|
| 1397 | | { |
|---|
| 1398 | | vlc_object_t *p_this = p_module->pp_children[0]; |
|---|
| | 1396 | while( vlc_internals( p_module )->i_children ) |
|---|
| | 1397 | { |
|---|
| | 1398 | vlc_object_t *p_this = vlc_internals( p_module )->pp_children[0]; |
|---|
| 1399 | 1399 | vlc_object_detach( p_this ); |
|---|
| 1400 | 1400 | vlc_object_release( p_this ); |
|---|