Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #include "bin/loader.h" | 6 #include "bin/loader.h" |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
| 10 #include "bin/extensions.h" | 10 #include "bin/extensions.h" |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 free(part_uri); | 601 free(part_uri); |
| 602 return Dart_LoadSource(library, | 602 return Dart_LoadSource(library, |
| 603 part_uri_obj, | 603 part_uri_obj, |
| 604 Builtin::PartSource(id, url_string), 0, 0); | 604 Builtin::PartSource(id, url_string), 0, 0); |
| 605 } | 605 } |
| 606 // All cases should have been handled above. | 606 // All cases should have been handled above. |
| 607 UNREACHABLE(); | 607 UNREACHABLE(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 | 610 |
| 611 Mutex Loader::loader_infos_lock_; | 611 void Loader::InitOnce() { |
| 612 loader_infos_lock_ = new Mutex(); | |
|
zra
2016/07/13 14:51:38
Can this be deleted in a Loader::Shutdown() call s
Florian Schneider
2016/07/13 16:13:58
It could be. But since it is in the embedder, and
zra
2016/07/13 16:16:06
sgtm. Didn't notice this was in bin/
| |
| 613 } | |
| 614 | |
| 615 | |
| 616 Mutex* Loader::loader_infos_lock_; | |
| 612 Loader::LoaderInfo* Loader::loader_infos_ = NULL; | 617 Loader::LoaderInfo* Loader::loader_infos_ = NULL; |
| 613 intptr_t Loader::loader_infos_length_ = 0; | 618 intptr_t Loader::loader_infos_length_ = 0; |
| 614 intptr_t Loader::loader_infos_capacity_ = 0; | 619 intptr_t Loader::loader_infos_capacity_ = 0; |
| 615 | 620 |
| 616 | 621 |
| 617 // Add a mapping from |port| to |isolate_data| (really the loader). When a | 622 // Add a mapping from |port| to |isolate_data| (really the loader). When a |
| 618 // native message arrives, we use this map to report the I/O result to the | 623 // native message arrives, we use this map to report the I/O result to the |
| 619 // correct loader. | 624 // correct loader. |
| 620 // This happens whenever an isolate begins loading. | 625 // This happens whenever an isolate begins loading. |
| 621 void Loader::AddLoader(Dart_Port port, IsolateData* isolate_data) { | 626 void Loader::AddLoader(Dart_Port port, IsolateData* isolate_data) { |
| 622 MutexLocker ml(&loader_infos_lock_); | 627 MutexLocker ml(loader_infos_lock_); |
| 623 ASSERT(LoaderForLocked(port) == NULL); | 628 ASSERT(LoaderForLocked(port) == NULL); |
| 624 if (loader_infos_length_ == loader_infos_capacity_) { | 629 if (loader_infos_length_ == loader_infos_capacity_) { |
| 625 // Grow to an initial capacity or double in size. | 630 // Grow to an initial capacity or double in size. |
| 626 loader_infos_capacity_ = | 631 loader_infos_capacity_ = |
| 627 (loader_infos_capacity_ == 0) ? 4 : loader_infos_capacity_ * 2; | 632 (loader_infos_capacity_ == 0) ? 4 : loader_infos_capacity_ * 2; |
| 628 loader_infos_ = | 633 loader_infos_ = |
| 629 reinterpret_cast<Loader::LoaderInfo*>( | 634 reinterpret_cast<Loader::LoaderInfo*>( |
| 630 realloc(loader_infos_, | 635 realloc(loader_infos_, |
| 631 sizeof(Loader::LoaderInfo) * loader_infos_capacity_)); | 636 sizeof(Loader::LoaderInfo) * loader_infos_capacity_)); |
| 632 ASSERT(loader_infos_ != NULL); | 637 ASSERT(loader_infos_ != NULL); |
| 633 // Initialize new entries. | 638 // Initialize new entries. |
| 634 for (intptr_t i = loader_infos_length_; i < loader_infos_capacity_; i++) { | 639 for (intptr_t i = loader_infos_length_; i < loader_infos_capacity_; i++) { |
| 635 loader_infos_[i].port = ILLEGAL_PORT; | 640 loader_infos_[i].port = ILLEGAL_PORT; |
| 636 loader_infos_[i].isolate_data = NULL; | 641 loader_infos_[i].isolate_data = NULL; |
| 637 } | 642 } |
| 638 } | 643 } |
| 639 ASSERT(loader_infos_length_ < loader_infos_capacity_); | 644 ASSERT(loader_infos_length_ < loader_infos_capacity_); |
| 640 loader_infos_[loader_infos_length_].port = port; | 645 loader_infos_[loader_infos_length_].port = port; |
| 641 loader_infos_[loader_infos_length_].isolate_data = isolate_data; | 646 loader_infos_[loader_infos_length_].isolate_data = isolate_data; |
| 642 loader_infos_length_++; | 647 loader_infos_length_++; |
| 643 ASSERT(LoaderForLocked(port) != NULL); | 648 ASSERT(LoaderForLocked(port) != NULL); |
| 644 } | 649 } |
| 645 | 650 |
| 646 | 651 |
| 647 // Remove |port| from the map. | 652 // Remove |port| from the map. |
| 648 // This happens once an isolate has finished loading. | 653 // This happens once an isolate has finished loading. |
| 649 void Loader::RemoveLoader(Dart_Port port) { | 654 void Loader::RemoveLoader(Dart_Port port) { |
| 650 MutexLocker ml(&loader_infos_lock_); | 655 MutexLocker ml(loader_infos_lock_); |
| 651 const intptr_t index = LoaderIndexFor(port); | 656 const intptr_t index = LoaderIndexFor(port); |
| 652 ASSERT(index >= 0); | 657 ASSERT(index >= 0); |
| 653 const intptr_t last = loader_infos_length_ - 1; | 658 const intptr_t last = loader_infos_length_ - 1; |
| 654 ASSERT(last >= 0); | 659 ASSERT(last >= 0); |
| 655 if (index != last) { | 660 if (index != last) { |
| 656 // Swap with the tail. | 661 // Swap with the tail. |
| 657 loader_infos_[index] = loader_infos_[last]; | 662 loader_infos_[index] = loader_infos_[last]; |
| 658 } | 663 } |
| 659 loader_infos_length_--; | 664 loader_infos_length_--; |
| 660 } | 665 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 673 Loader* Loader::LoaderForLocked(Dart_Port port) { | 678 Loader* Loader::LoaderForLocked(Dart_Port port) { |
| 674 intptr_t index = LoaderIndexFor(port); | 679 intptr_t index = LoaderIndexFor(port); |
| 675 if (index < 0) { | 680 if (index < 0) { |
| 676 return NULL; | 681 return NULL; |
| 677 } | 682 } |
| 678 return loader_infos_[index].isolate_data->loader(); | 683 return loader_infos_[index].isolate_data->loader(); |
| 679 } | 684 } |
| 680 | 685 |
| 681 | 686 |
| 682 Loader* Loader::LoaderFor(Dart_Port port) { | 687 Loader* Loader::LoaderFor(Dart_Port port) { |
| 683 MutexLocker ml(&loader_infos_lock_); | 688 MutexLocker ml(loader_infos_lock_); |
| 684 return LoaderForLocked(port); | 689 return LoaderForLocked(port); |
| 685 } | 690 } |
| 686 | 691 |
| 687 | 692 |
| 688 void Loader::NativeMessageHandler(Dart_Port dest_port_id, | 693 void Loader::NativeMessageHandler(Dart_Port dest_port_id, |
| 689 Dart_CObject* message) { | 694 Dart_CObject* message) { |
| 690 MutexLocker ml(&loader_infos_lock_); | 695 MutexLocker ml(loader_infos_lock_); |
| 691 Loader* loader = LoaderForLocked(dest_port_id); | 696 Loader* loader = LoaderForLocked(dest_port_id); |
| 692 if (loader == NULL) { | 697 if (loader == NULL) { |
| 693 return; | 698 return; |
| 694 } | 699 } |
| 695 loader->QueueMessage(message); | 700 loader->QueueMessage(message); |
| 696 } | 701 } |
| 697 | 702 |
| 698 } // namespace bin | 703 } // namespace bin |
| 699 } // namespace dart | 704 } // namespace dart |
| OLD | NEW |