Index: runtime/platform/thread_macos.cc |
diff --git a/runtime/platform/thread_macos.cc b/runtime/platform/thread_macos.cc |
index 29e571915796fbe7072df5b38fb897d37d9bf491..89082742d17e29e7bc744c17c87270d930d8db35 100644 |
--- a/runtime/platform/thread_macos.cc |
+++ b/runtime/platform/thread_macos.cc |
@@ -10,54 +10,18 @@ |
namespace dart { |
-#define VALIDATE_PTHREAD_RESULT(result) \ |
+const ThreadHandle Thread::kInvalidThreadHandle = 0; |
+ |
+#define VALIDATE_PTHREAD_RESULT(result) \ |
if (result != 0) { \ |
FATAL2("pthread error: %d (%s)", result, strerror(result)); \ |
} |
-class ThreadStartData { |
- public: |
- ThreadStartData(Thread::ThreadStartFunction function, |
- uword parameter, |
- Thread* thread) |
- : function_(function), parameter_(parameter), thread_(thread) {} |
- |
- Thread::ThreadStartFunction function() const { return function_; } |
- uword parameter() const { return parameter_; } |
- Thread* thread() const { return thread_; } |
- |
- private: |
- Thread::ThreadStartFunction function_; |
- uword parameter_; |
- Thread* thread_; |
- |
- DISALLOW_COPY_AND_ASSIGN(ThreadStartData); |
-}; |
- |
- |
-// Dispatch to the thread start function provided by the caller. This trampoline |
-// is used to ensure that the thread is properly destroyed if the thread just |
-// exits. |
-static void* ThreadStart(void* data_ptr) { |
- ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); |
- |
- Thread::ThreadStartFunction function = data->function(); |
- uword parameter = data->parameter(); |
- Thread* thread = data->thread(); |
- delete data; |
- |
- // Call the supplied thread start function handing it its parameters. |
- function(parameter); |
+typedef void* (*PThreadStartFunction)(void* args); |
- // When the function returns here, make sure that the thread is deleted. |
- delete thread; |
- return NULL; |
-} |
- |
- |
-Thread::Thread(ThreadStartFunction function, uword parameter) { |
+ThreadHandle Thread::Start(ThreadStartFunction function, uword parameter) { |
pthread_attr_t attr; |
int result = pthread_attr_init(&attr); |
VALIDATE_PTHREAD_RESULT(result); |
@@ -68,23 +32,23 @@ Thread::Thread(ThreadStartFunction function, uword parameter) { |
result = pthread_attr_setstacksize(&attr, 128 * KB); |
VALIDATE_PTHREAD_RESULT(result); |
- ThreadStartData* data = new ThreadStartData(function, parameter, this); |
- |
pthread_t tid; |
result = pthread_create(&tid, |
&attr, |
- ThreadStart, |
- data); |
+ reinterpret_cast<PThreadStartFunction>(function), |
+ reinterpret_cast<void*>(parameter)); |
VALIDATE_PTHREAD_RESULT(result); |
- data_.tid_ = tid; |
- |
result = pthread_attr_destroy(&attr); |
VALIDATE_PTHREAD_RESULT(result); |
+ |
+ return tid; |
} |
-Thread::~Thread() { |
+void Thread::Join(ThreadHandle thread) { |
+ int result = pthread_join(thread, NULL); |
Ivan Posva
2012/01/20 16:45:55
The threads are created detached (as they should b
Søren Gjesse
2012/01/23 13:14:58
Obviously I did not run the VM tests.
How about t
|
+ VALIDATE_PTHREAD_RESULT(result); |
} |