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

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

Issue 6816038: Do not rely on uniquiness of pthread_t Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ThreadRef -> ThreadId 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
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 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 1489
1490 // Entry point for threads. The supplied argument is a pointer to the thread 1490 // Entry point for threads. The supplied argument is a pointer to the thread
1491 // object. The entry function dispatches to the run method in the thread 1491 // object. The entry function dispatches to the run method in the thread
1492 // object. It is important that this function has __stdcall calling 1492 // object. It is important that this function has __stdcall calling
1493 // convention. 1493 // convention.
1494 static unsigned int __stdcall ThreadEntry(void* arg) { 1494 static unsigned int __stdcall ThreadEntry(void* arg) {
1495 Thread* thread = reinterpret_cast<Thread*>(arg); 1495 Thread* thread = reinterpret_cast<Thread*>(arg);
1496 // This is also initialized by the last parameter to _beginthreadex() but we 1496 // This is also initialized by the last parameter to _beginthreadex() but we
1497 // don't know which thread will run first (the original thread or the new 1497 // don't know which thread will run first (the original thread or the new
1498 // one) so we initialize it here too. 1498 // one) so we initialize it here too.
1499 thread->thread_handle_data()->tid_ = GetCurrentThreadId();
1500 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 1499 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
1501 thread->Run(); 1500 thread->Run();
1502 return 0; 1501 return 0;
1503 } 1502 }
1504 1503
1505 1504
1506 // Initialize thread handle to invalid handle.
1507 ThreadHandle::ThreadHandle(ThreadHandle::Kind kind) {
1508 data_ = new PlatformData(kind);
1509 }
1510
1511
1512 ThreadHandle::~ThreadHandle() {
1513 delete data_;
1514 }
1515
1516
1517 // The thread is running if it has the same id as the current thread.
1518 bool ThreadHandle::IsSelf() const {
1519 return GetCurrentThreadId() == data_->tid_;
1520 }
1521
1522
1523 // Test for invalid thread handle.
1524 bool ThreadHandle::IsValid() const {
1525 return data_->tid_ != kNoThreadId;
1526 }
1527
1528
1529 void ThreadHandle::Initialize(ThreadHandle::Kind kind) {
1530 data_->Initialize(kind);
1531 }
1532
1533
1534 class Thread::PlatformData : public Malloced { 1505 class Thread::PlatformData : public Malloced {
1535 public: 1506 public:
1536 explicit PlatformData(HANDLE thread) : thread_(thread) {} 1507 explicit PlatformData(HANDLE thread) : thread_(thread) {}
1537 HANDLE thread_; 1508 HANDLE thread_;
1538 }; 1509 };
1539 1510
1540 1511
1541 // Initialize a Win32 thread object. The thread has an invalid thread 1512 // Initialize a Win32 thread object. The thread has an invalid thread
1542 // handle until it is started. 1513 // handle until it is started.
1543 1514
1544 Thread::Thread(Isolate* isolate, const Options& options) 1515 Thread::Thread(Isolate* isolate, const Options& options)
1545 : ThreadHandle(ThreadHandle::INVALID), 1516 : isolate_(isolate),
1546 isolate_(isolate),
1547 stack_size_(options.stack_size) { 1517 stack_size_(options.stack_size) {
1548 data_ = new PlatformData(kNoThread); 1518 data_ = new PlatformData(kNoThread);
1549 set_name(options.name); 1519 set_name(options.name);
1550 } 1520 }
1551 1521
1552 1522
1553 Thread::Thread(Isolate* isolate, const char* name) 1523 Thread::Thread(Isolate* isolate, const char* name)
1554 : ThreadHandle(ThreadHandle::INVALID), 1524 : isolate_(isolate),
1555 isolate_(isolate),
1556 stack_size_(0) { 1525 stack_size_(0) {
1557 data_ = new PlatformData(kNoThread); 1526 data_ = new PlatformData(kNoThread);
1558 set_name(name); 1527 set_name(name);
1559 } 1528 }
1560 1529
1561 1530
1562 void Thread::set_name(const char* name) { 1531 void Thread::set_name(const char* name) {
1563 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); 1532 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name));
1564 name_[sizeof(name_) - 1] = '\0'; 1533 name_[sizeof(name_) - 1] = '\0';
1565 } 1534 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2032
2064 void Sampler::Stop() { 2033 void Sampler::Stop() {
2065 ASSERT(IsActive()); 2034 ASSERT(IsActive());
2066 SamplerThread::RemoveActiveSampler(this); 2035 SamplerThread::RemoveActiveSampler(this);
2067 SetActive(false); 2036 SetActive(false);
2068 } 2037 }
2069 2038
2070 #endif // ENABLE_LOGGING_AND_PROFILING 2039 #endif // ENABLE_LOGGING_AND_PROFILING
2071 2040
2072 } } // namespace v8::internal 2041 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698