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

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: 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-solaris.cc ('k') | src/runtime.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 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 ASSERT(IsReserved()); 1461 ASSERT(IsReserved());
1462 return VirtualFree(address, size, MEM_DECOMMIT) != false; 1462 return VirtualFree(address, size, MEM_DECOMMIT) != false;
1463 } 1463 }
1464 1464
1465 1465
1466 // ---------------------------------------------------------------------------- 1466 // ----------------------------------------------------------------------------
1467 // Win32 thread support. 1467 // Win32 thread support.
1468 1468
1469 // Definition of invalid thread handle and id. 1469 // Definition of invalid thread handle and id.
1470 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; 1470 static const HANDLE kNoThread = INVALID_HANDLE_VALUE;
1471 static const DWORD kNoThreadId = 0;
1472
1473
1474 class ThreadHandle::PlatformData : public Malloced {
1475 public:
1476 explicit PlatformData(ThreadHandle::Kind kind) {
1477 Initialize(kind);
1478 }
1479
1480 void Initialize(ThreadHandle::Kind kind) {
1481 switch (kind) {
1482 case ThreadHandle::SELF: tid_ = GetCurrentThreadId(); break;
1483 case ThreadHandle::INVALID: tid_ = kNoThreadId; break;
1484 }
1485 }
1486 DWORD tid_; // Win32 thread identifier.
1487 };
1488
1489 1471
1490 // Entry point for threads. The supplied argument is a pointer to the thread 1472 // 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 1473 // object. The entry function dispatches to the run method in the thread
1492 // object. It is important that this function has __stdcall calling 1474 // object. It is important that this function has __stdcall calling
1493 // convention. 1475 // convention.
1494 static unsigned int __stdcall ThreadEntry(void* arg) { 1476 static unsigned int __stdcall ThreadEntry(void* arg) {
1495 Thread* thread = reinterpret_cast<Thread*>(arg); 1477 Thread* thread = reinterpret_cast<Thread*>(arg);
1496 // This is also initialized by the last parameter to _beginthreadex() but we 1478 // 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 1479 // don't know which thread will run first (the original thread or the new
1498 // one) so we initialize it here too. 1480 // one) so we initialize it here too.
1499 thread->thread_handle_data()->tid_ = GetCurrentThreadId();
1500 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate()); 1481 Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
1501 thread->Run(); 1482 thread->Run();
1502 return 0; 1483 return 0;
1503 } 1484 }
1504 1485
1505 1486
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 { 1487 class Thread::PlatformData : public Malloced {
1535 public: 1488 public:
1536 explicit PlatformData(HANDLE thread) : thread_(thread) {} 1489 explicit PlatformData(HANDLE thread) : thread_(thread) {}
1537 HANDLE thread_; 1490 HANDLE thread_;
1538 }; 1491 };
1539 1492
1540 1493
1541 // Initialize a Win32 thread object. The thread has an invalid thread 1494 // Initialize a Win32 thread object. The thread has an invalid thread
1542 // handle until it is started. 1495 // handle until it is started.
1543 1496
1544 Thread::Thread(Isolate* isolate, const Options& options) 1497 Thread::Thread(Isolate* isolate, const Options& options)
1545 : ThreadHandle(ThreadHandle::INVALID), 1498 : isolate_(isolate),
1546 isolate_(isolate),
1547 stack_size_(options.stack_size) { 1499 stack_size_(options.stack_size) {
1548 data_ = new PlatformData(kNoThread); 1500 data_ = new PlatformData(kNoThread);
1549 set_name(options.name); 1501 set_name(options.name);
1550 } 1502 }
1551 1503
1552 1504
1553 Thread::Thread(Isolate* isolate, const char* name) 1505 Thread::Thread(Isolate* isolate, const char* name)
1554 : ThreadHandle(ThreadHandle::INVALID), 1506 : isolate_(isolate),
1555 isolate_(isolate),
1556 stack_size_(0) { 1507 stack_size_(0) {
1557 data_ = new PlatformData(kNoThread); 1508 data_ = new PlatformData(kNoThread);
1558 set_name(name); 1509 set_name(name);
1559 } 1510 }
1560 1511
1561 1512
1562 void Thread::set_name(const char* name) { 1513 void Thread::set_name(const char* name) {
1563 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); 1514 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name));
1564 name_[sizeof(name_) - 1] = '\0'; 1515 name_[sizeof(name_) - 1] = '\0';
1565 } 1516 }
1566 1517
1567 1518
1568 // Close our own handle for the thread. 1519 // Close our own handle for the thread.
1569 Thread::~Thread() { 1520 Thread::~Thread() {
1570 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_); 1521 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_);
1571 delete data_; 1522 delete data_;
1572 } 1523 }
1573 1524
1574 1525
1575 // Create a new thread. It is important to use _beginthreadex() instead of 1526 // Create a new thread. It is important to use _beginthreadex() instead of
1576 // the Win32 function CreateThread(), because the CreateThread() does not 1527 // the Win32 function CreateThread(), because the CreateThread() does not
1577 // initialize thread specific structures in the C runtime library. 1528 // initialize thread specific structures in the C runtime library.
1578 void Thread::Start() { 1529 void Thread::Start() {
1579 data_->thread_ = reinterpret_cast<HANDLE>( 1530 data_->thread_ = reinterpret_cast<HANDLE>(
1580 _beginthreadex(NULL, 1531 _beginthreadex(NULL,
1581 static_cast<unsigned>(stack_size_), 1532 static_cast<unsigned>(stack_size_),
1582 ThreadEntry, 1533 ThreadEntry,
1583 this, 1534 this,
1584 0, 1535 0,
1585 reinterpret_cast<unsigned int*>( 1536 NULL));
1586 &thread_handle_data()->tid_)));
1587 ASSERT(IsValid()); 1537 ASSERT(IsValid());
1588 } 1538 }
1589 1539
1590 1540
1591 // Wait for thread to terminate. 1541 // Wait for thread to terminate.
1592 void Thread::Join() { 1542 void Thread::Join() {
1593 WaitForSingleObject(data_->thread_, INFINITE); 1543 WaitForSingleObject(data_->thread_, INFINITE);
1594 } 1544 }
1595 1545
1596 1546
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2013
2064 void Sampler::Stop() { 2014 void Sampler::Stop() {
2065 ASSERT(IsActive()); 2015 ASSERT(IsActive());
2066 SamplerThread::RemoveActiveSampler(this); 2016 SamplerThread::RemoveActiveSampler(this);
2067 SetActive(false); 2017 SetActive(false);
2068 } 2018 }
2069 2019
2070 #endif // ENABLE_LOGGING_AND_PROFILING 2020 #endif // ENABLE_LOGGING_AND_PROFILING
2071 2021
2072 } } // namespace v8::internal 2022 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698