| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 return false; | 1416 return false; |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 | 1419 |
| 1420 // ---------------------------------------------------------------------------- | 1420 // ---------------------------------------------------------------------------- |
| 1421 // Win32 thread support. | 1421 // Win32 thread support. |
| 1422 | 1422 |
| 1423 // Definition of invalid thread handle and id. | 1423 // Definition of invalid thread handle and id. |
| 1424 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; | 1424 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; |
| 1425 | 1425 |
| 1426 static void SetCurrentThreadName(const char* name) { |
| 1427 // Reference: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx |
| 1428 // https://code.google.com/p/chromium/codesearch#chromium/src/base/threading
/platform_thread_win.cc |
| 1429 |
| 1430 typedef struct tagTHREADNAME_INFO { |
| 1431 DWORD dwType; // Must be 0x1000. |
| 1432 LPCSTR szName; // Pointer to name (in user addr space). |
| 1433 DWORD dwThreadID; // Thread ID (-1=caller thread). |
| 1434 DWORD dwFlags; // Reserved for future use, must be zero. |
| 1435 } THREADNAME_INFO; |
| 1436 |
| 1437 THREADNAME_INFO info; |
| 1438 info.dwType = 0x1000; |
| 1439 info.szName = name; |
| 1440 info.dwThreadID = static_cast<DWORD>(-1); |
| 1441 info.dwFlags = 0; |
| 1442 |
| 1443 __try { |
| 1444 RaiseException( |
| 1445 0x406D1388 /* MSVC EXCEPTION */, 0, |
| 1446 sizeof(info)/sizeof(ULONG_PTR), reinterpret_cast<ULONG_PTR*>(&info)); |
| 1447 } |
| 1448 __except(EXCEPTION_CONTINUE_EXECUTION) {} |
| 1449 } |
| 1450 |
| 1426 // Entry point for threads. The supplied argument is a pointer to the thread | 1451 // Entry point for threads. The supplied argument is a pointer to the thread |
| 1427 // object. The entry function dispatches to the run method in the thread | 1452 // object. The entry function dispatches to the run method in the thread |
| 1428 // object. It is important that this function has __stdcall calling | 1453 // object. It is important that this function has __stdcall calling |
| 1429 // convention. | 1454 // convention. |
| 1430 static unsigned int __stdcall ThreadEntry(void* arg) { | 1455 static unsigned int __stdcall ThreadEntry(void* arg) { |
| 1431 Thread* thread = reinterpret_cast<Thread*>(arg); | 1456 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 1457 SetCurrentThreadName(thread->name()); |
| 1432 thread->NotifyStartedAndRun(); | 1458 thread->NotifyStartedAndRun(); |
| 1433 return 0; | 1459 return 0; |
| 1434 } | 1460 } |
| 1435 | 1461 |
| 1436 | 1462 |
| 1437 class Thread::PlatformData : public Malloced { | 1463 class Thread::PlatformData : public Malloced { |
| 1438 public: | 1464 public: |
| 1439 explicit PlatformData(HANDLE thread) : thread_(thread) {} | 1465 explicit PlatformData(HANDLE thread) : thread_(thread) {} |
| 1440 HANDLE thread_; | 1466 HANDLE thread_; |
| 1441 unsigned thread_id_; | 1467 unsigned thread_id_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 ASSERT(result); | 1539 ASSERT(result); |
| 1514 } | 1540 } |
| 1515 | 1541 |
| 1516 | 1542 |
| 1517 | 1543 |
| 1518 void Thread::YieldCPU() { | 1544 void Thread::YieldCPU() { |
| 1519 Sleep(0); | 1545 Sleep(0); |
| 1520 } | 1546 } |
| 1521 | 1547 |
| 1522 } } // namespace v8::internal | 1548 } } // namespace v8::internal |
| OLD | NEW |