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

Side by Side Diff: src/platform-cygwin.cc

Issue 6816038: Do not rely on uniquiness of pthread_t Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Win32 build fix Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/platform.h ('k') | src/platform-freebsd.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 2006-2011 the V8 project authors. All rights reserved. 1 // Copyright 2006-2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 return true; 355 return true;
356 } 356 }
357 357
358 358
359 bool VirtualMemory::Uncommit(void* address, size_t size) { 359 bool VirtualMemory::Uncommit(void* address, size_t size) {
360 ASSERT(IsReserved()); 360 ASSERT(IsReserved());
361 return VirtualFree(address, size, MEM_DECOMMIT) != false; 361 return VirtualFree(address, size, MEM_DECOMMIT) != false;
362 } 362 }
363 363
364 364
365 class ThreadHandle::PlatformData : public Malloced { 365 class Thread::PlatformData : public Malloced {
366 public: 366 public:
367 explicit PlatformData(ThreadHandle::Kind kind) { 367 PlatformData() : thread_(kNoThread) {}
368 Initialize(kind);
369 }
370
371 void Initialize(ThreadHandle::Kind kind) {
372 switch (kind) {
373 case ThreadHandle::SELF: thread_ = pthread_self(); break;
374 case ThreadHandle::INVALID: thread_ = kNoThread; break;
375 }
376 }
377
378 pthread_t thread_; // Thread handle for pthread. 368 pthread_t thread_; // Thread handle for pthread.
379 }; 369 };
380 370
381 371
382 ThreadHandle::ThreadHandle(Kind kind) {
383 data_ = new PlatformData(kind);
384 }
385
386
387 void ThreadHandle::Initialize(ThreadHandle::Kind kind) {
388 data_->Initialize(kind);
389 }
390
391
392 ThreadHandle::~ThreadHandle() {
393 delete data_;
394 }
395
396
397 bool ThreadHandle::IsSelf() const {
398 return pthread_equal(data_->thread_, pthread_self());
399 }
400
401
402 bool ThreadHandle::IsValid() const {
403 return data_->thread_ != kNoThread;
404 }
405 372
406 373
407 Thread::Thread(Isolate* isolate, const Options& options) 374 Thread::Thread(Isolate* isolate, const Options& options)
408 : ThreadHandle(ThreadHandle::INVALID), 375 : data_(new PlatformData),
409 isolate_(isolate), 376 isolate_(isolate),
410 stack_size_(options.stack_size) { 377 stack_size_(options.stack_size) {
411 set_name(options.name); 378 set_name(options.name);
412 } 379 }
413 380
414 381
415 Thread::Thread(Isolate* isolate, const char* name) 382 Thread::Thread(Isolate* isolate, const char* name)
416 : ThreadHandle(ThreadHandle::INVALID), 383 : data_(new PlatformData),
417 isolate_(isolate), 384 isolate_(isolate),
418 stack_size_(0) { 385 stack_size_(0) {
419 set_name(name); 386 set_name(name);
420 } 387 }
421 388
422 389
423 Thread::~Thread() { 390 Thread::~Thread() {
391 delete data_;
424 } 392 }
425 393
426 394
427 static void* ThreadEntry(void* arg) { 395 static void* ThreadEntry(void* arg) {
428 Thread* thread = reinterpret_cast<Thread*>(arg); 396 Thread* thread = reinterpret_cast<Thread*>(arg);
429 // This is also initialized by the first argument to pthread_create() but we 397 // This is also initialized by the first argument to pthread_create() but we
430 // don't know which thread will run first (the original thread or the new 398 // don't know which thread will run first (the original thread or the new
431 // one) so we initialize it here too. 399 // one) so we initialize it here too.
432 thread->thread_handle_data()->thread_ = pthread_self(); 400 thread->data()->thread_ = pthread_self();
433 ASSERT(thread->IsValid()); 401 ASSERT(thread->data()->thread_ != kNoThread);
434 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 402 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
435 thread->Run(); 403 thread->Run();
436 return NULL; 404 return NULL;
437 } 405 }
438 406
439 407
440 void Thread::set_name(const char* name) { 408 void Thread::set_name(const char* name) {
441 strncpy(name_, name, sizeof(name_)); 409 strncpy(name_, name, sizeof(name_));
442 name_[sizeof(name_) - 1] = '\0'; 410 name_[sizeof(name_) - 1] = '\0';
443 } 411 }
444 412
445 413
446 void Thread::Start() { 414 void Thread::Start() {
447 pthread_attr_t* attr_ptr = NULL; 415 pthread_attr_t* attr_ptr = NULL;
448 pthread_attr_t attr; 416 pthread_attr_t attr;
449 if (stack_size_ > 0) { 417 if (stack_size_ > 0) {
450 pthread_attr_init(&attr); 418 pthread_attr_init(&attr);
451 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_)); 419 pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
452 attr_ptr = &attr; 420 attr_ptr = &attr;
453 } 421 }
454 pthread_create(&thread_handle_data()->thread_, attr_ptr, ThreadEntry, this); 422 pthread_create(&data_->thread_, attr_ptr, ThreadEntry, this);
455 ASSERT(IsValid()); 423 ASSERT(data_->thread_ != kNoThread);
456 } 424 }
457 425
458 426
459 void Thread::Join() { 427 void Thread::Join() {
460 pthread_join(thread_handle_data()->thread_, NULL); 428 pthread_join(data_->thread_, NULL);
461 } 429 }
462 430
463 431
464 static inline Thread::LocalStorageKey PthreadKeyToLocalKey( 432 static inline Thread::LocalStorageKey PthreadKeyToLocalKey(
465 pthread_key_t pthread_key) { 433 pthread_key_t pthread_key) {
466 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps 434 // We need to cast pthread_key_t to Thread::LocalStorageKey in two steps
467 // because pthread_key_t is a pointer type on Cygwin. This will probably not 435 // because pthread_key_t is a pointer type on Cygwin. This will probably not
468 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway. 436 // work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway.
469 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t)); 437 STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
470 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key); 438 intptr_t ptr_key = reinterpret_cast<intptr_t>(pthread_key);
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 void Sampler::Stop() { 770 void Sampler::Stop() {
803 ASSERT(IsActive()); 771 ASSERT(IsActive());
804 SamplerThread::RemoveActiveSampler(this); 772 SamplerThread::RemoveActiveSampler(this);
805 SetActive(false); 773 SetActive(false);
806 } 774 }
807 775
808 #endif // ENABLE_LOGGING_AND_PROFILING 776 #endif // ENABLE_LOGGING_AND_PROFILING
809 777
810 } } // namespace v8::internal 778 } } // namespace v8::internal
811 779
OLDNEW
« no previous file with comments | « src/platform.h ('k') | src/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698