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

Side by Side Diff: runtime/vm/os_thread_macos.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_linux.cc ('k') | runtime/vm/os_thread_win.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_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/os_thread.h" 8 #include "vm/os_thread.h"
9 9
10 #include <sys/errno.h> // NOLINT 10 #include <sys/errno.h> // NOLINT
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return result; \ 50 return result; \
51 } 51 }
52 #else 52 #else
53 #define RETURN_ON_PTHREAD_FAILURE(result) \ 53 #define RETURN_ON_PTHREAD_FAILURE(result) \
54 if (result != 0) return result; 54 if (result != 0) return result;
55 #endif 55 #endif
56 56
57 57
58 class ThreadStartData { 58 class ThreadStartData {
59 public: 59 public:
60 ThreadStartData(OSThread::ThreadStartFunction function, 60 ThreadStartData(const char* name,
61 OSThread::ThreadStartFunction function,
61 uword parameter) 62 uword parameter)
62 : function_(function), parameter_(parameter) {} 63 : name_(name), function_(function), parameter_(parameter) {}
63 64
65 const char* name() const { return name_; }
64 OSThread::ThreadStartFunction function() const { return function_; } 66 OSThread::ThreadStartFunction function() const { return function_; }
65 uword parameter() const { return parameter_; } 67 uword parameter() const { return parameter_; }
66 68
67 private: 69 private:
70 const char* name_;
68 OSThread::ThreadStartFunction function_; 71 OSThread::ThreadStartFunction function_;
69 uword parameter_; 72 uword parameter_;
70 73
71 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); 74 DISALLOW_COPY_AND_ASSIGN(ThreadStartData);
72 }; 75 };
73 76
74 77
75 // Dispatch to the thread start function provided by the caller. This trampoline 78 // Dispatch to the thread start function provided by the caller. This trampoline
76 // is used to ensure that the thread is properly destroyed if the thread just 79 // is used to ensure that the thread is properly destroyed if the thread just
77 // exits. 80 // exits.
78 static void* ThreadStart(void* data_ptr) { 81 static void* ThreadStart(void* data_ptr) {
79 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); 82 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
80 83
84 const char* name = data->name();
81 OSThread::ThreadStartFunction function = data->function(); 85 OSThread::ThreadStartFunction function = data->function();
82 uword parameter = data->parameter(); 86 uword parameter = data->parameter();
83 delete data; 87 delete data;
84 88
89 // Create new OSThread object and set as TLS for new thread.
90 OSThread* thread = new OSThread();
91 OSThread::SetCurrent(thread);
92 thread->set_name(name);
93
85 // Call the supplied thread start function handing it its parameters. 94 // Call the supplied thread start function handing it its parameters.
86 function(parameter); 95 function(parameter);
87 96
88 return NULL; 97 return NULL;
89 } 98 }
90 99
91 100
92 int OSThread::Start(ThreadStartFunction function, uword parameter) { 101 int OSThread::Start(const char* name,
102 ThreadStartFunction function,
103 uword parameter) {
93 pthread_attr_t attr; 104 pthread_attr_t attr;
94 int result = pthread_attr_init(&attr); 105 int result = pthread_attr_init(&attr);
95 RETURN_ON_PTHREAD_FAILURE(result); 106 RETURN_ON_PTHREAD_FAILURE(result);
96 107
97 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); 108 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize());
98 RETURN_ON_PTHREAD_FAILURE(result); 109 RETURN_ON_PTHREAD_FAILURE(result);
99 110
100 ThreadStartData* data = new ThreadStartData(function, parameter); 111 ThreadStartData* data = new ThreadStartData(name, function, parameter);
101 112
102 pthread_t tid; 113 pthread_t tid;
103 result = pthread_create(&tid, &attr, ThreadStart, data); 114 result = pthread_create(&tid, &attr, ThreadStart, data);
104 RETURN_ON_PTHREAD_FAILURE(result); 115 RETURN_ON_PTHREAD_FAILURE(result);
105 116
106 result = pthread_attr_destroy(&attr); 117 result = pthread_attr_destroy(&attr);
107 RETURN_ON_PTHREAD_FAILURE(result); 118 RETURN_ON_PTHREAD_FAILURE(result);
108 119
109 return 0; 120 return 0;
110 } 121 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 void Monitor::NotifyAll() { 416 void Monitor::NotifyAll() {
406 // When running with assertions enabled we track the owner. 417 // When running with assertions enabled we track the owner.
407 ASSERT(IsOwnedByCurrentThread()); 418 ASSERT(IsOwnedByCurrentThread());
408 int result = pthread_cond_broadcast(data_.cond()); 419 int result = pthread_cond_broadcast(data_.cond());
409 VALIDATE_PTHREAD_RESULT(result); 420 VALIDATE_PTHREAD_RESULT(result);
410 } 421 }
411 422
412 } // namespace dart 423 } // namespace dart
413 424
414 #endif // defined(TARGET_OS_MACOS) 425 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/os_thread_linux.cc ('k') | runtime/vm/os_thread_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698