@@ -444,180 +444,131 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
444
444
<< " Committing " << total << " new items." ;
445
445
#endif /* I2_DEBUG */
446
446
447
- std::set<Type::Ptr> types;
448
- std::set<Type::Ptr> completed_types;
449
447
int itemsCount {0 };
450
448
451
- for (const Type::Ptr& type : Type::GetAllTypes ()) {
452
- if (ConfigObject::TypeInstance->IsAssignableFrom (type))
453
- types.insert (type);
454
- }
455
-
456
- while (types.size () != completed_types.size ()) {
457
- for (const Type::Ptr& type : types) {
458
- if (completed_types.find (type) != completed_types.end ())
459
- continue ;
449
+ for (auto & type : Type::GetConfigTypesSortedByLoadDependencies ()) {
450
+ std::atomic<int > committed_items (0 );
460
451
461
- bool unresolved_dep = false ;
452
+ {
453
+ auto items (itemsByType.find (type.get ()));
462
454
463
- /* skip this type (for now) if there are unresolved load dependencies */
464
- for (auto pLoadDep : type->GetLoadDependencies ()) {
465
- if (types.find (pLoadDep) != types.end () && completed_types.find (pLoadDep) == completed_types.end ()) {
466
- unresolved_dep = true ;
467
- break ;
455
+ if (items != itemsByType.end ()) {
456
+ for (const ItemPair& pair: items->second ) {
457
+ newItems.emplace_back (pair.first );
468
458
}
469
- }
470
-
471
- if (unresolved_dep)
472
- continue ;
473
459
474
- std::atomic<int > committed_items (0 );
460
+ upq.ParallelFor (items->second , [&committed_items](const ItemPair& ip) {
461
+ const ConfigItem::Ptr& item = ip.first ;
475
462
476
- {
477
- auto items (itemsByType.find (type.get ()));
463
+ if (!item->Commit (ip.second )) {
464
+ if (item->IsIgnoreOnError ()) {
465
+ item->Unregister ();
466
+ }
478
467
479
- if (items != itemsByType.end ()) {
480
- for (const ItemPair& pair: items->second ) {
481
- newItems.emplace_back (pair.first );
468
+ return ;
482
469
}
483
470
484
- upq. ParallelFor (items-> second , [& committed_items]( const ItemPair& ip) {
485
- const ConfigItem::Ptr& item = ip. first ;
471
+ committed_items++;
472
+ }) ;
486
473
487
- if (!item->Commit (ip.second )) {
488
- if (item->IsIgnoreOnError ()) {
489
- item->Unregister ();
490
- }
491
-
492
- return ;
493
- }
494
-
495
- committed_items++;
496
- });
497
-
498
- upq.Join ();
499
- }
474
+ upq.Join ();
500
475
}
476
+ }
501
477
502
- itemsCount += committed_items;
503
-
504
- completed_types.insert (type);
478
+ itemsCount += committed_items;
505
479
506
480
#ifdef I2_DEBUG
507
- if (committed_items > 0 )
508
- Log (LogDebug, " configitem" )
509
- << " Committed " << committed_items << " items of type '" << type->GetName () << " '." ;
481
+ if (committed_items > 0 )
482
+ Log (LogDebug, " configitem" )
483
+ << " Committed " << committed_items << " items of type '" << type->GetName () << " '." ;
510
484
#endif /* I2_DEBUG */
511
485
512
- if (upq.HasExceptions ())
513
- return false ;
514
- }
486
+ if (upq.HasExceptions ())
487
+ return false ;
515
488
}
516
489
517
490
#ifdef I2_DEBUG
518
491
Log (LogDebug, " configitem" )
519
492
<< " Committed " << itemsCount << " items." ;
520
493
#endif /* I2_DEBUG */
521
494
522
- completed_types.clear ();
495
+ for (auto & type : Type::GetConfigTypesSortedByLoadDependencies ()) {
496
+ std::atomic<int > notified_items (0 );
523
497
524
- while (types.size () != completed_types.size ()) {
525
- for (const Type::Ptr& type : types) {
526
- if (completed_types.find (type) != completed_types.end ())
527
- continue ;
498
+ {
499
+ auto items (itemsByType.find (type.get ()));
528
500
529
- bool unresolved_dep = false ;
501
+ if (items != itemsByType.end ()) {
502
+ upq.ParallelFor (items->second , [¬ified_items](const ItemPair& ip) {
503
+ const ConfigItem::Ptr& item = ip.first ;
530
504
531
- /* skip this type (for now) if there are unresolved load dependencies */
532
- for (auto pLoadDep : type->GetLoadDependencies ()) {
533
- if (types.find (pLoadDep) != types.end () && completed_types.find (pLoadDep) == completed_types.end ()) {
534
- unresolved_dep = true ;
535
- break ;
536
- }
537
- }
505
+ if (!item->m_Object )
506
+ return ;
538
507
539
- if (unresolved_dep)
540
- continue ;
541
-
542
- std::atomic<int > notified_items (0 );
543
-
544
- {
545
- auto items (itemsByType.find (type.get ()));
546
-
547
- if (items != itemsByType.end ()) {
548
- upq.ParallelFor (items->second , [¬ified_items](const ItemPair& ip) {
549
- const ConfigItem::Ptr& item = ip.first ;
550
-
551
- if (!item->m_Object )
552
- return ;
508
+ try {
509
+ item->m_Object ->OnAllConfigLoaded ();
510
+ notified_items++;
511
+ } catch (const std::exception& ex) {
512
+ if (!item->m_IgnoreOnError )
513
+ throw ;
553
514
554
- try {
555
- item->m_Object ->OnAllConfigLoaded ();
556
- notified_items++;
557
- } catch (const std::exception& ex) {
558
- if (!item->m_IgnoreOnError )
559
- throw ;
515
+ Log (LogNotice, " ConfigObject" )
516
+ << " Ignoring config object '" << item->m_Name << " ' of type '" << item->m_Type ->GetName () << " ' due to errors: " << DiagnosticInformation (ex);
560
517
561
- Log (LogNotice, " ConfigObject" )
562
- << " Ignoring config object '" << item->m_Name << " ' of type '" << item->m_Type ->GetName () << " ' due to errors: " << DiagnosticInformation (ex);
518
+ item->Unregister ();
563
519
564
- item->Unregister ();
565
-
566
- {
567
- std::unique_lock<std::mutex> lock (item->m_Mutex );
568
- item->m_IgnoredItems .push_back (item->m_DebugInfo .Path );
569
- }
520
+ {
521
+ std::unique_lock<std::mutex> lock (item->m_Mutex );
522
+ item->m_IgnoredItems .push_back (item->m_DebugInfo .Path );
570
523
}
571
- });
524
+ }
525
+ });
572
526
573
- upq.Join ();
574
- }
527
+ upq.Join ();
575
528
}
576
-
577
- completed_types.insert (type);
529
+ }
578
530
579
531
#ifdef I2_DEBUG
580
- if (notified_items > 0 )
581
- Log (LogDebug, " configitem" )
582
- << " Sent OnAllConfigLoaded to " << notified_items << " items of type '" << type->GetName () << " '." ;
532
+ if (notified_items > 0 )
533
+ Log (LogDebug, " configitem" )
534
+ << " Sent OnAllConfigLoaded to " << notified_items << " items of type '" << type->GetName () << " '." ;
583
535
#endif /* I2_DEBUG */
584
536
585
- if (upq.HasExceptions ())
586
- return false ;
537
+ if (upq.HasExceptions ())
538
+ return false ;
587
539
588
- notified_items = 0 ;
589
- for (auto loadDep : type->GetLoadDependencies ()) {
590
- auto items (itemsByType.find (loadDep));
540
+ notified_items = 0 ;
541
+ for (auto loadDep : type->GetLoadDependencies ()) {
542
+ auto items (itemsByType.find (loadDep));
591
543
592
- if (items != itemsByType.end ()) {
593
- upq.ParallelFor (items->second , [&type, ¬ified_items](const ItemPair& ip) {
594
- const ConfigItem::Ptr& item = ip.first ;
544
+ if (items != itemsByType.end ()) {
545
+ upq.ParallelFor (items->second , [&type, ¬ified_items](const ItemPair& ip) {
546
+ const ConfigItem::Ptr& item = ip.first ;
595
547
596
- if (!item->m_Object )
597
- return ;
548
+ if (!item->m_Object )
549
+ return ;
598
550
599
- ActivationScope ascope (item->m_ActivationContext );
600
- item->m_Object ->CreateChildObjects (type);
601
- notified_items++;
602
- });
603
- }
551
+ ActivationScope ascope (item->m_ActivationContext );
552
+ item->m_Object ->CreateChildObjects (type);
553
+ notified_items++;
554
+ });
604
555
}
556
+ }
605
557
606
- upq.Join ();
558
+ upq.Join ();
607
559
608
560
#ifdef I2_DEBUG
609
- if (notified_items > 0 )
610
- Log (LogDebug, " configitem" )
611
- << " Sent CreateChildObjects to " << notified_items << " items of type '" << type->GetName () << " '." ;
561
+ if (notified_items > 0 )
562
+ Log (LogDebug, " configitem" )
563
+ << " Sent CreateChildObjects to " << notified_items << " items of type '" << type->GetName () << " '." ;
612
564
#endif /* I2_DEBUG */
613
565
614
- if (upq.HasExceptions ())
615
- return false ;
566
+ if (upq.HasExceptions ())
567
+ return false ;
616
568
617
- // Make sure to activate any additionally generated items
618
- if (!CommitNewItems (context, upq, newItems))
619
- return false ;
620
- }
569
+ // Make sure to activate any additionally generated items
570
+ if (!CommitNewItems (context, upq, newItems))
571
+ return false ;
621
572
}
622
573
623
574
return true ;
0 commit comments