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

Unified Diff: runtime/platform/thread_linux.cc

Issue 9141005: Change the thread interface in runtime/platform and use it starting all threads (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: runtime/platform/thread_linux.cc
diff --git a/runtime/platform/thread_linux.cc b/runtime/platform/thread_linux.cc
index 338c4c8d1cab8cf9ebb01ae465117f5e20c6b779..f8c8cbfdfacbe424a66fe474e5823fcf6acd3400 100644
--- a/runtime/platform/thread_linux.cc
+++ b/runtime/platform/thread_linux.cc
@@ -11,6 +11,8 @@
namespace dart {
+const ThreadHandle Thread::kInvalidThreadHandle = 0;
+
#define VALIDATE_PTHREAD_RESULT(result) \
if (result != 0) { \
FATAL2("pthread error: %d (%s)", result, strerror(result)); \
@@ -32,48 +34,10 @@ static void ComputeTimeSpec(struct timespec* ts, int64_t millis) {
}
-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) {
Ivan Posva 2012/01/20 16:45:55 In the past I have found this extra trampoline hel
Søren Gjesse 2012/01/23 13:14:58 OK, I added it back. It was also still there on Wi
- 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);
@@ -84,23 +48,23 @@ Thread::Thread(ThreadStartFunction function, uword parameter) {
result = pthread_attr_setstacksize(&attr, 1024 * 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);
+ VALIDATE_PTHREAD_RESULT(result);
}

Powered by Google App Engine
This is Rietveld 408576698