Chromium Code Reviews| Index: runtime/platform/thread_macos.cc |
| diff --git a/runtime/platform/thread_macos.cc b/runtime/platform/thread_macos.cc |
| index 29e571915796fbe7072df5b38fb897d37d9bf491..65770d8b9f8173fdccc3cd752273aeb936123610 100644 |
| --- a/runtime/platform/thread_macos.cc |
| +++ b/runtime/platform/thread_macos.cc |
| @@ -10,54 +10,15 @@ |
| 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); |
| - |
| - // 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 +29,31 @@ 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<void* (*)(void*)>(function), // NOLINT |
|
Mads Ager (google)
2012/01/20 12:35:34
Ditto.
Søren Gjesse
2012/01/20 13:25:45
Done.
|
| + reinterpret_cast<void*>(parameter)); |
| VALIDATE_PTHREAD_RESULT(result); |
| - data_.tid_ = tid; |
| - |
| result = pthread_attr_destroy(&attr); |
| VALIDATE_PTHREAD_RESULT(result); |
| + |
| + return tid; |
| } |
| -Thread::~Thread() { |
| +bool Thread::Join(ThreadHandle thread, int64_t millis) { |
| + int result; |
| + if (millis == kNoTimeout) { |
| + result = pthread_join(thread, NULL); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + return true; |
| + } else { |
| + // TODO(sgjesse): Is there a Mac OS alternative to pthread_timedjoin_np? |
| + UNIMPLEMENTED(); |
| + return false; |
| + } |
| } |