Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 197963002: Remove the ability to allow multiple gc prologue and gc epilogue callbacks (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "include/dart_native_api.h" 7 #include "include/dart_native_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 return Api::Success(); 761 return Api::Success();
762 } 762 }
763 763
764 764
765 // --- Garbage Collection Callbacks -- 765 // --- Garbage Collection Callbacks --
766 766
767 DART_EXPORT Dart_Handle Dart_AddGcPrologueCallback( 767 DART_EXPORT Dart_Handle Dart_AddGcPrologueCallback(
768 Dart_GcPrologueCallback callback) { 768 Dart_GcPrologueCallback callback) {
769 Isolate* isolate = Isolate::Current(); 769 Isolate* isolate = Isolate::Current();
770 CHECK_ISOLATE(isolate); 770 CHECK_ISOLATE(isolate);
771 GcPrologueCallbacks& callbacks = isolate->gc_prologue_callbacks(); 771 if (isolate->gc_prologue_callback() != NULL) {
772 if (callbacks.Contains(callback)) {
773 return Api::NewError( 772 return Api::NewError(
774 "%s permits only one instance of 'callback' to be present in the " 773 "%s permits only one gc prologue callback to be registered, please "
775 "prologue callback list.", 774 "remove the existing callback using Dart_RemoveGcPrologueCallback "
775 "and then add this callback",
776 CURRENT_FUNC); 776 CURRENT_FUNC);
777 } 777 }
778 callbacks.Add(callback); 778 isolate->set_gc_prologue_callback(callback);
779 return Api::Success(); 779 return Api::Success();
780 } 780 }
781 781
782 782
783 DART_EXPORT Dart_Handle Dart_RemoveGcPrologueCallback( 783 DART_EXPORT Dart_Handle Dart_RemoveGcPrologueCallback(
784 Dart_GcPrologueCallback callback) { 784 Dart_GcPrologueCallback callback) {
785 Isolate* isolate = Isolate::Current(); 785 Isolate* isolate = Isolate::Current();
786 CHECK_ISOLATE(isolate); 786 CHECK_ISOLATE(isolate);
787 GcPrologueCallbacks& callbacks = isolate->gc_prologue_callbacks(); 787 if (isolate->gc_prologue_callback() != callback) {
788 if (!callbacks.Contains(callback)) {
789 return Api::NewError( 788 return Api::NewError(
790 "%s expects 'callback' to be present in the prologue callback list.", 789 "%s expects 'callback' to be the currently registered gc prologue "
790 "callback.",
791 CURRENT_FUNC); 791 CURRENT_FUNC);
792 } 792 }
793 callbacks.Remove(callback); 793 isolate->set_gc_prologue_callback(NULL);
794 return Api::Success(); 794 return Api::Success();
795 } 795 }
796 796
797 797
798 DART_EXPORT Dart_Handle Dart_AddGcEpilogueCallback( 798 DART_EXPORT Dart_Handle Dart_AddGcEpilogueCallback(
799 Dart_GcEpilogueCallback callback) { 799 Dart_GcEpilogueCallback callback) {
800 Isolate* isolate = Isolate::Current(); 800 Isolate* isolate = Isolate::Current();
801 CHECK_ISOLATE(isolate); 801 CHECK_ISOLATE(isolate);
802 GcEpilogueCallbacks& callbacks = isolate->gc_epilogue_callbacks(); 802 if (isolate->gc_epilogue_callback() != NULL) {
803 if (callbacks.Contains(callback)) {
804 return Api::NewError( 803 return Api::NewError(
805 "%s permits only one instance of 'callback' to be present in the " 804 "%s permits only one gc epilogue callback to be registered, please "
806 "epilogue callback list.", 805 "remove the existing callback using Dart_RemoveGcEpilogueCallback "
806 "and then add this callback",
807 CURRENT_FUNC); 807 CURRENT_FUNC);
808 } 808 }
809 callbacks.Add(callback); 809 isolate->set_gc_epilogue_callback(callback);
810 return Api::Success(); 810 return Api::Success();
811 } 811 }
812 812
813 813
814 DART_EXPORT Dart_Handle Dart_RemoveGcEpilogueCallback( 814 DART_EXPORT Dart_Handle Dart_RemoveGcEpilogueCallback(
815 Dart_GcEpilogueCallback callback) { 815 Dart_GcEpilogueCallback callback) {
816 Isolate* isolate = Isolate::Current(); 816 Isolate* isolate = Isolate::Current();
817 CHECK_ISOLATE(isolate); 817 CHECK_ISOLATE(isolate);
818 GcEpilogueCallbacks& callbacks = isolate->gc_epilogue_callbacks(); 818 if (isolate->gc_epilogue_callback() != callback) {
819 if (!callbacks.Contains(callback)) {
820 return Api::NewError( 819 return Api::NewError(
821 "%s expects 'callback' to be present in the epilogue callback list.", 820 "%s expects 'callback' to be the currently registered gc epilogue "
821 " callback.",
822 CURRENT_FUNC); 822 CURRENT_FUNC);
823 } 823 }
824 callbacks.Remove(callback); 824 isolate->set_gc_epilogue_callback(NULL);
825 return Api::Success();
826 }
827
828
829 DART_EXPORT Dart_Handle Dart_SetGcCallbacks(
830 Dart_GcPrologueCallback prologue_callback,
831 Dart_GcEpilogueCallback epilogue_callback) {
832 Isolate* isolate = Isolate::Current();
833 CHECK_ISOLATE(isolate);
834 if (prologue_callback != NULL) {
835 if (isolate->gc_prologue_callback() != NULL) {
836 return Api::NewError(
837 "%s permits only one gc prologue callback to be registered, please "
838 "remove the existing callback and then add this callback",
839 CURRENT_FUNC);
840 }
841 } else {
842 if (isolate->gc_prologue_callback() == NULL) {
843 return Api::NewError(
844 "%s expects 'prologue_callback' to be present in the callback set.",
845 CURRENT_FUNC);
846 }
847 }
848 if (epilogue_callback != NULL) {
849 if (isolate->gc_epilogue_callback() != NULL) {
850 return Api::NewError(
851 "%s permits only one gc epilogue callback to be registered, please "
852 "remove the existing callback and then add this callback",
853 CURRENT_FUNC);
854 }
855 } else {
856 if (isolate->gc_epilogue_callback() == NULL) {
857 return Api::NewError(
858 "%s expects 'epilogue_callback' to be present in the callback set.",
859 CURRENT_FUNC);
860 }
861 }
862 isolate->set_gc_prologue_callback(prologue_callback);
863 isolate->set_gc_epilogue_callback(epilogue_callback);
825 return Api::Success(); 864 return Api::Success();
826 } 865 }
827 866
828 867
829 // --- Initialization and Globals --- 868 // --- Initialization and Globals ---
830 869
831 DART_EXPORT const char* Dart_VersionString() { 870 DART_EXPORT const char* Dart_VersionString() {
832 return Version::String(); 871 return Version::String();
833 } 872 }
834 873
(...skipping 3820 matching lines...) Expand 10 before | Expand all | Expand 10 after
4655 4694
4656 4695
4657 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( 4696 DART_EXPORT void Dart_RegisterRootServiceRequestCallback(
4658 const char* name, 4697 const char* name,
4659 Dart_ServiceRequestCallback callback, 4698 Dart_ServiceRequestCallback callback,
4660 void* user_data) { 4699 void* user_data) {
4661 Service::RegisterRootEmbedderCallback(name, callback, user_data); 4700 Service::RegisterRootEmbedderCallback(name, callback, user_data);
4662 } 4701 }
4663 4702
4664 } // namespace dart 4703 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698