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

Side by Side Diff: src/platform-freebsd.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-cygwin.cc ('k') | src/platform-linux.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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 } 384 }
385 385
386 386
387 bool VirtualMemory::Uncommit(void* address, size_t size) { 387 bool VirtualMemory::Uncommit(void* address, size_t size) {
388 return mmap(address, size, PROT_NONE, 388 return mmap(address, size, PROT_NONE,
389 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 389 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED,
390 kMmapFd, kMmapFdOffset) != MAP_FAILED; 390 kMmapFd, kMmapFdOffset) != MAP_FAILED;
391 } 391 }
392 392
393 393
394 class ThreadHandle::PlatformData : public Malloced { 394 class Thread::PlatformData : public Malloced {
395 public: 395 public:
396 explicit PlatformData(ThreadHandle::Kind kind) {
397 Initialize(kind);
398 }
399
400 void Initialize(ThreadHandle::Kind kind) {
401 switch (kind) {
402 case ThreadHandle::SELF: thread_ = pthread_self(); break;
403 case ThreadHandle::INVALID: thread_ = kNoThread; break;
404 }
405 }
406 pthread_t thread_; // Thread handle for pthread. 396 pthread_t thread_; // Thread handle for pthread.
407 }; 397 };
408 398
409 399
410 ThreadHandle::ThreadHandle(Kind kind) { 400 ThreadHandle::ThreadHandle(Kind kind) {
411 data_ = new PlatformData(kind); 401 data_ = new PlatformData(kind);
412 } 402 }
413 403
414 404
415 void ThreadHandle::Initialize(ThreadHandle::Kind kind) { 405 void ThreadHandle::Initialize(ThreadHandle::Kind kind) {
(...skipping 10 matching lines...) Expand all
426 return pthread_equal(data_->thread_, pthread_self()); 416 return pthread_equal(data_->thread_, pthread_self());
427 } 417 }
428 418
429 419
430 bool ThreadHandle::IsValid() const { 420 bool ThreadHandle::IsValid() const {
431 return data_->thread_ != kNoThread; 421 return data_->thread_ != kNoThread;
432 } 422 }
433 423
434 424
435 Thread::Thread(Isolate* isolate, const Options& options) 425 Thread::Thread(Isolate* isolate, const Options& options)
436 : ThreadHandle(ThreadHandle::INVALID), 426 : data_(new PlatformData),
437 isolate_(isolate), 427 isolate_(isolate),
438 stack_size_(options.stack_size) { 428 stack_size_(options.stack_size) {
439 set_name(options.name); 429 set_name(options.name);
440 } 430 }
441 431
442 432
443 Thread::Thread(Isolate* isolate, const char* name) 433 Thread::Thread(Isolate* isolate, const char* name)
444 : ThreadHandle(ThreadHandle::INVALID), 434 : data_(new PlatformData),
445 isolate_(isolate), 435 isolate_(isolate),
446 stack_size_(0) { 436 stack_size_(0) {
447 set_name(name); 437 set_name(name);
448 } 438 }
449 439
450 440
451 Thread::~Thread() { 441 Thread::~Thread() {
442 delete data_;
452 } 443 }
453 444
454 445
455 static void* ThreadEntry(void* arg) { 446 static void* ThreadEntry(void* arg) {
456 Thread* thread = reinterpret_cast<Thread*>(arg); 447 Thread* thread = reinterpret_cast<Thread*>(arg);
457 // This is also initialized by the first argument to pthread_create() but we 448 // This is also initialized by the first argument to pthread_create() but we
458 // don't know which thread will run first (the original thread or the new 449 // don't know which thread will run first (the original thread or the new
459 // one) so we initialize it here too. 450 // one) so we initialize it here too.
460 thread->thread_handle_data()->thread_ = pthread_self(); 451 thread_->data_->thread_ = pthread_self();
461 ASSERT(thread->IsValid()); 452 ASSERT(thread->IsValid());
462 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 453 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
463 thread->Run(); 454 thread->Run();
464 return NULL; 455 return NULL;
465 } 456 }
466 457
467 458
468 void Thread::set_name(const char* name) { 459 void Thread::set_name(const char* name) {
469 strncpy(name_, name, sizeof(name_)); 460 strncpy(name_, name, sizeof(name_));
470 name_[sizeof(name_) - 1] = '\0'; 461 name_[sizeof(name_) - 1] = '\0';
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 836
846 void Sampler::Stop() { 837 void Sampler::Stop() {
847 ASSERT(IsActive()); 838 ASSERT(IsActive());
848 SignalSender::RemoveActiveSampler(this); 839 SignalSender::RemoveActiveSampler(this);
849 SetActive(false); 840 SetActive(false);
850 } 841 }
851 842
852 #endif // ENABLE_LOGGING_AND_PROFILING 843 #endif // ENABLE_LOGGING_AND_PROFILING
853 844
854 } } // namespace v8::internal 845 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-cygwin.cc ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698