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

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

Issue 1978153002: Uses an open thread handle as the ThreadJoinId on Windows. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix test Created 4 years, 7 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/bin/thread_win.cc ('k') | runtime/vm/os_thread.h » ('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) 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 #include "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.h"
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 9696 matching lines...) Expand 10 before | Expand all | Expand 10 after
9707 // Free buffer allocated by AppendStreamConsumer 9707 // Free buffer allocated by AppendStreamConsumer
9708 free(data.buffer); 9708 free(data.buffer);
9709 } 9709 }
9710 9710
9711 9711
9712 class GlobalTimelineThreadData { 9712 class GlobalTimelineThreadData {
9713 public: 9713 public:
9714 GlobalTimelineThreadData() 9714 GlobalTimelineThreadData()
9715 : monitor_(new Monitor()), 9715 : monitor_(new Monitor()),
9716 data_(new AppendData()), 9716 data_(new AppendData()),
9717 running_(true), 9717 running_(true) {
9718 join_id_(OSThread::kInvalidThreadJoinId) {
9719 } 9718 }
9720 9719
9721 ~GlobalTimelineThreadData() { 9720 ~GlobalTimelineThreadData() {
9722 delete monitor_; 9721 delete monitor_;
9723 monitor_ = NULL; 9722 monitor_ = NULL;
9724 free(data_->buffer); 9723 free(data_->buffer);
9725 data_->buffer = NULL; 9724 data_->buffer = NULL;
9726 data_->buffer_length = 0; 9725 data_->buffer_length = 0;
9727 delete data_; 9726 delete data_;
9728 data_ = NULL; 9727 data_ = NULL;
9729 } 9728 }
9730 9729
9731 Monitor* monitor() const { return monitor_; } 9730 Monitor* monitor() const { return monitor_; }
9732 bool running() const { return running_; } 9731 bool running() const { return running_; }
9733 AppendData* data() const { return data_; } 9732 AppendData* data() const { return data_; }
9734 uint8_t* buffer() const { return data_->buffer; } 9733 uint8_t* buffer() const { return data_->buffer; }
9735 intptr_t buffer_length() const { return data_->buffer_length; } 9734 intptr_t buffer_length() const { return data_->buffer_length; }
9736 ThreadJoinId join_id() const { return join_id_; }
9737 9735
9738 void set_running(bool running) { running_ = running; } 9736 void set_running(bool running) { running_ = running; }
9739 void set_join_id(ThreadJoinId join_id) { join_id_ = join_id; }
9740 9737
9741 private: 9738 private:
9742 Monitor* monitor_; 9739 Monitor* monitor_;
9743 AppendData* data_; 9740 AppendData* data_;
9744 bool running_; 9741 bool running_;
9745 ThreadJoinId join_id_;
9746 }; 9742 };
9747 9743
9748 9744
9749 static void GlobalTimelineThread(uword parameter) { 9745 static void GlobalTimelineThread(uword parameter) {
9750 GlobalTimelineThreadData* data = 9746 GlobalTimelineThreadData* data =
9751 reinterpret_cast<GlobalTimelineThreadData*>(parameter); 9747 reinterpret_cast<GlobalTimelineThreadData*>(parameter);
9752 Thread* T = Thread::Current(); 9748 Thread* T = Thread::Current();
9753 // When there is no current Thread, then Zone allocation will fail. 9749 // When there is no current Thread, then Zone allocation will fail.
9754 EXPECT(T == NULL); 9750 EXPECT(T == NULL);
9755 { 9751 {
9756 MonitorLocker ml(data->monitor()); 9752 MonitorLocker ml(data->monitor());
9757 bool success = 9753 bool success =
9758 Dart_GlobalTimelineGetTrace(AppendStreamConsumer, data->data()); 9754 Dart_GlobalTimelineGetTrace(AppendStreamConsumer, data->data());
9759 EXPECT(success); 9755 EXPECT(success);
9760 data->set_running(false); 9756 data->set_running(false);
9761 data->set_join_id(OSThread::Current()->join_id());
9762 ml.Notify(); 9757 ml.Notify();
9763 } 9758 }
9764 } 9759 }
9765 9760
9766 9761
9767 // This test is the same as the one above except that the calls to 9762 // This test is the same as the one above except that the calls to
9768 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that 9763 // Dart_GlobalTimelineGetTrace are made from a fresh thread. This ensures that
9769 // we can call the function from a thread for which we have not set up a 9764 // we can call the function from a thread for which we have not set up a
9770 // Thread object. 9765 // Thread object.
9771 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) { 9766 TEST_CASE(Timeline_Dart_GlobalTimelineGetTrace_Threaded) {
(...skipping 26 matching lines...) Expand all
9798 int err = OSThread::Start("Timeline test thread", 9793 int err = OSThread::Start("Timeline test thread",
9799 GlobalTimelineThread, reinterpret_cast<uword>(&data)); 9794 GlobalTimelineThread, reinterpret_cast<uword>(&data));
9800 EXPECT(err == 0); 9795 EXPECT(err == 0);
9801 { 9796 {
9802 MonitorLocker ml(data.monitor()); 9797 MonitorLocker ml(data.monitor());
9803 while (data.running()) { 9798 while (data.running()) {
9804 ml.Wait(); 9799 ml.Wait();
9805 } 9800 }
9806 buffer = reinterpret_cast<char*>(data.buffer()); 9801 buffer = reinterpret_cast<char*>(data.buffer());
9807 buffer_length = data.buffer_length(); 9802 buffer_length = data.buffer_length();
9808 OSThread::Join(data.join_id());
9809 } 9803 }
9810 EXPECT(buffer_length > 0); 9804 EXPECT(buffer_length > 0);
9811 EXPECT(buffer != NULL); 9805 EXPECT(buffer != NULL);
9812 9806
9813 // Response starts with a '{' character and not a '['. 9807 // Response starts with a '{' character and not a '['.
9814 EXPECT(buffer[0] == '{'); 9808 EXPECT(buffer[0] == '{');
9815 // Response ends with a '}' character and not a ']'. 9809 // Response ends with a '}' character and not a ']'.
9816 EXPECT(buffer[buffer_length - 1] == '\0'); 9810 EXPECT(buffer[buffer_length - 1] == '\0');
9817 EXPECT(buffer[buffer_length - 2] == '}'); 9811 EXPECT(buffer[buffer_length - 2] == '}');
9818 9812
(...skipping 21 matching lines...) Expand all
9840 err = OSThread::Start("Timeline test thread", 9834 err = OSThread::Start("Timeline test thread",
9841 GlobalTimelineThread, reinterpret_cast<uword>(&data2)); 9835 GlobalTimelineThread, reinterpret_cast<uword>(&data2));
9842 EXPECT(err == 0); 9836 EXPECT(err == 0);
9843 { 9837 {
9844 MonitorLocker ml(data2.monitor()); 9838 MonitorLocker ml(data2.monitor());
9845 while (data2.running()) { 9839 while (data2.running()) {
9846 ml.Wait(); 9840 ml.Wait();
9847 } 9841 }
9848 buffer = reinterpret_cast<char*>(data2.buffer()); 9842 buffer = reinterpret_cast<char*>(data2.buffer());
9849 buffer_length = data2.buffer_length(); 9843 buffer_length = data2.buffer_length();
9850 OSThread::Join(data2.join_id());
9851 } 9844 }
9852 9845
9853 EXPECT(buffer_length > 0); 9846 EXPECT(buffer_length > 0);
9854 EXPECT(buffer != NULL); 9847 EXPECT(buffer != NULL);
9855 // Response starts with a '{' character and not a '['. 9848 // Response starts with a '{' character and not a '['.
9856 EXPECT(buffer[0] == '{'); 9849 EXPECT(buffer[0] == '{');
9857 // Response ends with a '}' character and not a ']'. 9850 // Response ends with a '}' character and not a ']'.
9858 EXPECT(buffer[buffer_length - 1] == '\0'); 9851 EXPECT(buffer[buffer_length - 1] == '\0');
9859 EXPECT(buffer[buffer_length - 2] == '}'); 9852 EXPECT(buffer[buffer_length - 2] == '}');
9860 9853
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
10053 result = Dart_Invoke(lib, 10046 result = Dart_Invoke(lib,
10054 NewString("foozoo"), 10047 NewString("foozoo"),
10055 0, 10048 0,
10056 NULL); 10049 NULL);
10057 EXPECT(Dart_IsError(result)); 10050 EXPECT(Dart_IsError(result));
10058 } 10051 }
10059 10052
10060 #endif // !PRODUCT 10053 #endif // !PRODUCT
10061 10054
10062 } // namespace dart 10055 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/thread_win.cc ('k') | runtime/vm/os_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698