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