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

Side by Side Diff: runtime/vm/isolate.h

Issue 1560853002: Fix Shutdown race. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.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 #ifndef VM_ISOLATE_H_ 5 #ifndef VM_ISOLATE_H_
6 #define VM_ISOLATE_H_ 6 #define VM_ISOLATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/atomic.h" 10 #include "vm/atomic.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 416 }
417 417
418 Dart_GcEpilogueCallback gc_epilogue_callback() const { 418 Dart_GcEpilogueCallback gc_epilogue_callback() const {
419 return gc_epilogue_callback_; 419 return gc_epilogue_callback_;
420 } 420 }
421 421
422 void set_gc_epilogue_callback(Dart_GcEpilogueCallback callback) { 422 void set_gc_epilogue_callback(Dart_GcEpilogueCallback callback) {
423 gc_epilogue_callback_ = callback; 423 gc_epilogue_callback_ = callback;
424 } 424 }
425 425
426 Monitor* spawn_count_monitor() const { return spawn_count_monitor_; }
427 intptr_t* spawn_count() { return &spawn_count_; }
428
429 void IncrementSpawnCount();
430 void WaitForOutstandingSpawns();
431
426 static void SetCreateCallback(Dart_IsolateCreateCallback cb) { 432 static void SetCreateCallback(Dart_IsolateCreateCallback cb) {
427 create_callback_ = cb; 433 create_callback_ = cb;
428 } 434 }
429 static Dart_IsolateCreateCallback CreateCallback() { 435 static Dart_IsolateCreateCallback CreateCallback() {
430 return create_callback_; 436 return create_callback_;
431 } 437 }
432 438
433 static void SetShutdownCallback(Dart_IsolateShutdownCallback cb) { 439 static void SetShutdownCallback(Dart_IsolateShutdownCallback cb) {
434 shutdown_callback_ = cb; 440 shutdown_callback_ = cb;
435 } 441 }
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // Used to wake the isolate when it is in the pause event loop. 822 // Used to wake the isolate when it is in the pause event loop.
817 Monitor* pause_loop_monitor_; 823 Monitor* pause_loop_monitor_;
818 824
819 // Invalidation generations; used to track events occuring in parallel 825 // Invalidation generations; used to track events occuring in parallel
820 // to background compilation. The counters may overflow, which is OK 826 // to background compilation. The counters may overflow, which is OK
821 // since we check for equality to detect if an event occured. 827 // since we check for equality to detect if an event occured.
822 uint32_t cha_invalidation_gen_; 828 uint32_t cha_invalidation_gen_;
823 uint32_t field_invalidation_gen_; 829 uint32_t field_invalidation_gen_;
824 uint32_t prefix_invalidation_gen_; 830 uint32_t prefix_invalidation_gen_;
825 831
832 // This guards spawn_count_. An isolate cannot complete shutdown and be
833 // destroyed while there are child isolates in the midst of a spawn.
834 Monitor* spawn_count_monitor_;
835 intptr_t spawn_count_;
836
826 #define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \ 837 #define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \
827 type metric_##variable##_; 838 type metric_##variable##_;
828 ISOLATE_METRIC_LIST(ISOLATE_METRIC_VARIABLE); 839 ISOLATE_METRIC_LIST(ISOLATE_METRIC_VARIABLE);
829 #undef ISOLATE_METRIC_VARIABLE 840 #undef ISOLATE_METRIC_VARIABLE
830 841
831 #define ISOLATE_TIMELINE_STREAM_VARIABLE(name, not_used) \ 842 #define ISOLATE_TIMELINE_STREAM_VARIABLE(name, not_used) \
832 TimelineStream stream_##name##_; 843 TimelineStream stream_##name##_;
833 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_VARIABLE) 844 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_VARIABLE)
834 #undef ISOLATE_TIMELINE_STREAM_VARIABLE 845 #undef ISOLATE_TIMELINE_STREAM_VARIABLE
835 846
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 }; 921 };
911 922
912 923
913 class IsolateSpawnState { 924 class IsolateSpawnState {
914 public: 925 public:
915 IsolateSpawnState(Dart_Port parent_port, 926 IsolateSpawnState(Dart_Port parent_port,
916 Dart_Port origin_id, 927 Dart_Port origin_id,
917 void* init_data, 928 void* init_data,
918 const Function& func, 929 const Function& func,
919 const Instance& message, 930 const Instance& message,
931 Monitor* spawn_count_monitor,
932 intptr_t* spawn_count,
920 bool paused, 933 bool paused,
921 bool errorsAreFatal, 934 bool errorsAreFatal,
922 Dart_Port onExit, 935 Dart_Port onExit,
923 Dart_Port onError); 936 Dart_Port onError);
924 IsolateSpawnState(Dart_Port parent_port, 937 IsolateSpawnState(Dart_Port parent_port,
925 void* init_data, 938 void* init_data,
926 const char* script_url, 939 const char* script_url,
927 const char* package_root, 940 const char* package_root,
928 const char** package_map, 941 const char** package_map,
929 const Instance& args, 942 const Instance& args,
930 const Instance& message, 943 const Instance& message,
944 Monitor* spawn_count_monitor,
945 intptr_t* spawn_count,
931 bool paused, 946 bool paused,
932 bool errorsAreFatal, 947 bool errorsAreFatal,
933 Dart_Port onExit, 948 Dart_Port onExit,
934 Dart_Port onError); 949 Dart_Port onError);
935 ~IsolateSpawnState(); 950 ~IsolateSpawnState();
936 951
937 Isolate* isolate() const { return isolate_; } 952 Isolate* isolate() const { return isolate_; }
938 void set_isolate(Isolate* value) { isolate_ = value; } 953 void set_isolate(Isolate* value) { isolate_ = value; }
939 954
940 Dart_Port parent_port() const { return parent_port_; } 955 Dart_Port parent_port() const { return parent_port_; }
941 Dart_Port origin_id() const { return origin_id_; } 956 Dart_Port origin_id() const { return origin_id_; }
942 void* init_data() const { return init_data_; } 957 void* init_data() const { return init_data_; }
943 Dart_Port on_exit_port() const { return on_exit_port_; } 958 Dart_Port on_exit_port() const { return on_exit_port_; }
944 Dart_Port on_error_port() const { return on_error_port_; } 959 Dart_Port on_error_port() const { return on_error_port_; }
945 const char* script_url() const { return script_url_; } 960 const char* script_url() const { return script_url_; }
946 const char* package_root() const { return package_root_; } 961 const char* package_root() const { return package_root_; }
947 const char** package_map() const { return package_map_; } 962 const char** package_map() const { return package_map_; }
948 const char* library_url() const { return library_url_; } 963 const char* library_url() const { return library_url_; }
949 const char* class_name() const { return class_name_; } 964 const char* class_name() const { return class_name_; }
950 const char* function_name() const { return function_name_; } 965 const char* function_name() const { return function_name_; }
951 bool is_spawn_uri() const { return library_url_ == NULL; } 966 bool is_spawn_uri() const { return library_url_ == NULL; }
952 bool paused() const { return paused_; } 967 bool paused() const { return paused_; }
953 bool errors_are_fatal() const { return errors_are_fatal_; } 968 bool errors_are_fatal() const { return errors_are_fatal_; }
954 Isolate::Flags* isolate_flags() { return &isolate_flags_; } 969 Isolate::Flags* isolate_flags() { return &isolate_flags_; }
955 970
956 RawObject* ResolveFunction(); 971 RawObject* ResolveFunction();
957 RawInstance* BuildArgs(Thread* thread); 972 RawInstance* BuildArgs(Thread* thread);
958 RawInstance* BuildMessage(Thread* thread); 973 RawInstance* BuildMessage(Thread* thread);
959 974
975 void DecrementSpawnCount();
976
960 private: 977 private:
961 Isolate* isolate_; 978 Isolate* isolate_;
962 Dart_Port parent_port_; 979 Dart_Port parent_port_;
963 Dart_Port origin_id_; 980 Dart_Port origin_id_;
964 void* init_data_; 981 void* init_data_;
965 Dart_Port on_exit_port_; 982 Dart_Port on_exit_port_;
966 Dart_Port on_error_port_; 983 Dart_Port on_error_port_;
967 const char* script_url_; 984 const char* script_url_;
968 const char* package_root_; 985 const char* package_root_;
969 const char** package_map_; 986 const char** package_map_;
970 const char* library_url_; 987 const char* library_url_;
971 const char* class_name_; 988 const char* class_name_;
972 const char* function_name_; 989 const char* function_name_;
973 uint8_t* serialized_args_; 990 uint8_t* serialized_args_;
974 intptr_t serialized_args_len_; 991 intptr_t serialized_args_len_;
975 uint8_t* serialized_message_; 992 uint8_t* serialized_message_;
976 intptr_t serialized_message_len_; 993 intptr_t serialized_message_len_;
994
995 // This counter tracks the number of outstanding calls to spawn by the parent
996 // isolate.
997 Monitor* spawn_count_monitor_;
998 intptr_t* spawn_count_;
999
977 Isolate::Flags isolate_flags_; 1000 Isolate::Flags isolate_flags_;
978 bool paused_; 1001 bool paused_;
979 bool errors_are_fatal_; 1002 bool errors_are_fatal_;
980 }; 1003 };
981 1004
982 } // namespace dart 1005 } // namespace dart
983 1006
984 #endif // VM_ISOLATE_H_ 1007 #endif // VM_ISOLATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698