| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #ifndef RUNTIME_VM_DART_API_STATE_H_ | 5 #ifndef RUNTIME_VM_DART_API_STATE_H_ |
| 6 #define RUNTIME_VM_DART_API_STATE_H_ | 6 #define RUNTIME_VM_DART_API_STATE_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 void FreeHandle(PersistentHandle* handle) { | 505 void FreeHandle(PersistentHandle* handle) { |
| 506 handle->FreeHandle(free_list()); | 506 handle->FreeHandle(free_list()); |
| 507 set_free_list(handle); | 507 set_free_list(handle); |
| 508 } | 508 } |
| 509 | 509 |
| 510 // Validate if passed in handle is a Persistent Handle. | 510 // Validate if passed in handle is a Persistent Handle. |
| 511 bool IsValidHandle(Dart_PersistentHandle object) const { | 511 bool IsValidHandle(Dart_PersistentHandle object) const { |
| 512 return IsValidScopedHandle(reinterpret_cast<uword>(object)); | 512 return IsValidScopedHandle(reinterpret_cast<uword>(object)); |
| 513 } | 513 } |
| 514 | 514 |
| 515 bool IsFreeHandle(Dart_PersistentHandle object) const { |
| 516 PersistentHandle* handle = free_list_; |
| 517 while (handle != NULL) { |
| 518 if (handle == reinterpret_cast<PersistentHandle*>(object)) { |
| 519 return true; |
| 520 } |
| 521 handle = handle->Next(); |
| 522 } |
| 523 return false; |
| 524 } |
| 525 |
| 515 // Returns a count of active handles (used for testing purposes). | 526 // Returns a count of active handles (used for testing purposes). |
| 516 int CountHandles() const { return CountScopedHandles(); } | 527 int CountHandles() const { return CountScopedHandles(); } |
| 517 | 528 |
| 518 private: | 529 private: |
| 519 PersistentHandle* free_list_; | 530 PersistentHandle* free_list_; |
| 520 DISALLOW_COPY_AND_ASSIGN(PersistentHandles); | 531 DISALLOW_COPY_AND_ASSIGN(PersistentHandles); |
| 521 }; | 532 }; |
| 522 | 533 |
| 523 | 534 |
| 524 // Finalizable persistent handles repository structure. | 535 // Finalizable persistent handles repository structure. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 handle->FreeHandle(free_list()); | 598 handle->FreeHandle(free_list()); |
| 588 set_free_list(handle); | 599 set_free_list(handle); |
| 589 } | 600 } |
| 590 | 601 |
| 591 // Validate if passed in handle is a Persistent Handle. | 602 // Validate if passed in handle is a Persistent Handle. |
| 592 bool IsValidHandle(Dart_WeakPersistentHandle object) const { | 603 bool IsValidHandle(Dart_WeakPersistentHandle object) const { |
| 593 MutexLocker ml(mutex_); | 604 MutexLocker ml(mutex_); |
| 594 return IsValidScopedHandle(reinterpret_cast<uword>(object)); | 605 return IsValidScopedHandle(reinterpret_cast<uword>(object)); |
| 595 } | 606 } |
| 596 | 607 |
| 608 bool IsFreeHandle(Dart_WeakPersistentHandle object) const { |
| 609 MutexLocker ml(mutex_); |
| 610 FinalizablePersistentHandle* handle = free_list_; |
| 611 while (handle != NULL) { |
| 612 if (handle == reinterpret_cast<FinalizablePersistentHandle*>(object)) { |
| 613 return true; |
| 614 } |
| 615 handle = handle->Next(); |
| 616 } |
| 617 return false; |
| 618 } |
| 619 |
| 597 // Returns a count of active handles (used for testing purposes). | 620 // Returns a count of active handles (used for testing purposes). |
| 598 int CountHandles() const { return CountScopedHandles(); } | 621 int CountHandles() const { return CountScopedHandles(); } |
| 599 | 622 |
| 600 private: | 623 private: |
| 601 FinalizablePersistentHandle* free_list_; | 624 FinalizablePersistentHandle* free_list_; |
| 602 Mutex* mutex_; | 625 Mutex* mutex_; |
| 603 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandles); | 626 DISALLOW_COPY_AND_ASSIGN(FinalizablePersistentHandles); |
| 604 }; | 627 }; |
| 605 | 628 |
| 606 | 629 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 } | 758 } |
| 736 | 759 |
| 737 void VisitWeakHandles(HandleVisitor* visitor) { | 760 void VisitWeakHandles(HandleVisitor* visitor) { |
| 738 weak_persistent_handles().VisitHandles(visitor); | 761 weak_persistent_handles().VisitHandles(visitor); |
| 739 } | 762 } |
| 740 | 763 |
| 741 bool IsValidPersistentHandle(Dart_PersistentHandle object) const { | 764 bool IsValidPersistentHandle(Dart_PersistentHandle object) const { |
| 742 return persistent_handles_.IsValidHandle(object); | 765 return persistent_handles_.IsValidHandle(object); |
| 743 } | 766 } |
| 744 | 767 |
| 768 bool IsFreePersistentHandle(Dart_PersistentHandle object) const { |
| 769 return persistent_handles_.IsFreeHandle(object); |
| 770 } |
| 771 |
| 772 bool IsActivePersistentHandle(Dart_PersistentHandle object) const { |
| 773 return IsValidPersistentHandle(object) && !IsFreePersistentHandle(object); |
| 774 } |
| 775 |
| 745 bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object) const { | 776 bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object) const { |
| 746 return weak_persistent_handles_.IsValidHandle(object); | 777 return weak_persistent_handles_.IsValidHandle(object); |
| 747 } | 778 } |
| 748 | 779 |
| 780 bool IsFreeWeakPersistentHandle(Dart_WeakPersistentHandle object) const { |
| 781 return weak_persistent_handles_.IsFreeHandle(object); |
| 782 } |
| 783 |
| 784 bool IsActiveWeakPersistentHandle(Dart_WeakPersistentHandle object) const { |
| 785 return IsValidWeakPersistentHandle(object) && |
| 786 !IsFreeWeakPersistentHandle(object); |
| 787 } |
| 788 |
| 749 bool IsProtectedHandle(PersistentHandle* object) const { | 789 bool IsProtectedHandle(PersistentHandle* object) const { |
| 750 if (object == NULL) return false; | 790 if (object == NULL) return false; |
| 751 return object == null_ || object == true_ || object == false_; | 791 return object == null_ || object == true_ || object == false_; |
| 752 } | 792 } |
| 753 | 793 |
| 754 int CountPersistentHandles() const { | 794 int CountPersistentHandles() const { |
| 755 return persistent_handles_.CountHandles(); | 795 return persistent_handles_.CountHandles(); |
| 756 } | 796 } |
| 757 | 797 |
| 758 void SetupAcquiredError() { | 798 void SetupAcquiredError() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 ref->set_callback(callback); | 841 ref->set_callback(callback); |
| 802 ref->set_is_queued_for_finalization(false); | 842 ref->set_is_queued_for_finalization(false); |
| 803 // This may trigger GC, so it must be called last. | 843 // This may trigger GC, so it must be called last. |
| 804 ref->SetExternalSize(external_size, isolate); | 844 ref->SetExternalSize(external_size, isolate); |
| 805 return ref; | 845 return ref; |
| 806 } | 846 } |
| 807 | 847 |
| 808 } // namespace dart | 848 } // namespace dart |
| 809 | 849 |
| 810 #endif // RUNTIME_VM_DART_API_STATE_H_ | 850 #endif // RUNTIME_VM_DART_API_STATE_H_ |
| OLD | NEW |