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

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

Issue 1439483003: - Add an OSThread structure which is the generic TLS structure for all C++ (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review Created 5 years, 1 month 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/os_thread.cc ('k') | runtime/vm/os_thread_linux.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) 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 "platform/globals.h" // NOLINT 5 #include "platform/globals.h" // NOLINT
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "vm/os_thread.h" 8 #include "vm/os_thread.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ts->tv_nsec = (tv.tv_usec + remaining_micros) * kNanosecondsPerMicrosecond; 57 ts->tv_nsec = (tv.tv_usec + remaining_micros) * kNanosecondsPerMicrosecond;
58 if (ts->tv_nsec >= kNanosecondsPerSecond) { 58 if (ts->tv_nsec >= kNanosecondsPerSecond) {
59 ts->tv_sec += 1; 59 ts->tv_sec += 1;
60 ts->tv_nsec -= kNanosecondsPerSecond; 60 ts->tv_nsec -= kNanosecondsPerSecond;
61 } 61 }
62 } 62 }
63 63
64 64
65 class ThreadStartData { 65 class ThreadStartData {
66 public: 66 public:
67 ThreadStartData(OSThread::ThreadStartFunction function, 67 ThreadStartData(const char* name,
68 OSThread::ThreadStartFunction function,
68 uword parameter) 69 uword parameter)
69 : function_(function), parameter_(parameter) {} 70 : name_(name), function_(function), parameter_(parameter) {}
70 71
72 const char* name() const { return name_; }
71 OSThread::ThreadStartFunction function() const { return function_; } 73 OSThread::ThreadStartFunction function() const { return function_; }
72 uword parameter() const { return parameter_; } 74 uword parameter() const { return parameter_; }
73 75
74 private: 76 private:
77 const char* name_;
75 OSThread::ThreadStartFunction function_; 78 OSThread::ThreadStartFunction function_;
76 uword parameter_; 79 uword parameter_;
77 80
78 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); 81 DISALLOW_COPY_AND_ASSIGN(ThreadStartData);
79 }; 82 };
80 83
81 84
82 // Dispatch to the thread start function provided by the caller. This trampoline 85 // Dispatch to the thread start function provided by the caller. This trampoline
83 // is used to ensure that the thread is properly destroyed if the thread just 86 // is used to ensure that the thread is properly destroyed if the thread just
84 // exits. 87 // exits.
85 static void* ThreadStart(void* data_ptr) { 88 static void* ThreadStart(void* data_ptr) {
86 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); 89 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
87 90
91 const char* name = data->name();
88 OSThread::ThreadStartFunction function = data->function(); 92 OSThread::ThreadStartFunction function = data->function();
89 uword parameter = data->parameter(); 93 uword parameter = data->parameter();
90 delete data; 94 delete data;
91 95
96 // Create new OSThread object and set as TLS for new thread.
97 OSThread* thread = new OSThread();
98 OSThread::SetCurrent(thread);
99 thread->set_name(name);
100
92 // Call the supplied thread start function handing it its parameters. 101 // Call the supplied thread start function handing it its parameters.
93 function(parameter); 102 function(parameter);
94 103
95 return NULL; 104 return NULL;
96 } 105 }
97 106
98 107
99 int OSThread::Start(ThreadStartFunction function, uword parameter) { 108 int OSThread::Start(const char* name,
109 ThreadStartFunction function,
110 uword parameter) {
100 pthread_attr_t attr; 111 pthread_attr_t attr;
101 int result = pthread_attr_init(&attr); 112 int result = pthread_attr_init(&attr);
102 RETURN_ON_PTHREAD_FAILURE(result); 113 RETURN_ON_PTHREAD_FAILURE(result);
103 114
104 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); 115 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize());
105 RETURN_ON_PTHREAD_FAILURE(result); 116 RETURN_ON_PTHREAD_FAILURE(result);
106 117
107 ThreadStartData* data = new ThreadStartData(function, parameter); 118 ThreadStartData* data = new ThreadStartData(name, function, parameter);
108 119
109 pthread_t tid; 120 pthread_t tid;
110 result = pthread_create(&tid, &attr, ThreadStart, data); 121 result = pthread_create(&tid, &attr, ThreadStart, data);
111 RETURN_ON_PTHREAD_FAILURE(result); 122 RETURN_ON_PTHREAD_FAILURE(result);
112 123
113 result = pthread_attr_destroy(&attr); 124 result = pthread_attr_destroy(&attr);
114 RETURN_ON_PTHREAD_FAILURE(result); 125 RETURN_ON_PTHREAD_FAILURE(result);
115 126
116 return 0; 127 return 0;
117 } 128 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 void Monitor::NotifyAll() { 406 void Monitor::NotifyAll() {
396 // When running with assertions enabled we track the owner. 407 // When running with assertions enabled we track the owner.
397 ASSERT(IsOwnedByCurrentThread()); 408 ASSERT(IsOwnedByCurrentThread());
398 int result = pthread_cond_broadcast(data_.cond()); 409 int result = pthread_cond_broadcast(data_.cond());
399 VALIDATE_PTHREAD_RESULT(result); 410 VALIDATE_PTHREAD_RESULT(result);
400 } 411 }
401 412
402 } // namespace dart 413 } // namespace dart
403 414
404 #endif // defined(TARGET_OS_ANDROID) 415 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread.cc ('k') | runtime/vm/os_thread_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698