Chromium Code Reviews| 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 SetCurThreadName(const char* name) { | |
|
Benedikt Meurer
2014/03/31 06:57:02
Nit: Use SetCurrentThreadName()
Jarin
2014/03/31 07:46:00
How about taking the code from Chromium? See https
| |
| 1427 // Reference: http://www.codeproject.com/KB/threads/Name_threads_in_debugger.a spx | |
|
Jarin
2014/03/31 07:46:00
I would prefer to link Microsoft rather than codep
| |
| 1428 | |
| 1429 typedef struct tagTHREADNAME_INFO { | |
| 1430 DWORD dwType; // Must be 0x1000. | |
| 1431 LPCSTR szName; // Pointer to name (in user addr space). | |
| 1432 DWORD dwThreadID; // Thread ID (-1=caller thread). | |
| 1433 DWORD dwFlags; // Reserved for future use, must be zero. | |
| 1434 } THREADNAME_INFO; | |
| 1435 | |
| 1436 THREADNAME_INFO info; | |
| 1437 { | |
|
Benedikt Meurer
2014/03/31 06:57:02
Nit: no need for a {}-block here.
| |
| 1438 info.dwType = 0x1000; | |
| 1439 info.szName = name; | |
| 1440 info.dwThreadID = (DWORD)-1; | |
|
Benedikt Meurer
2014/03/31 06:57:02
Use static_cast<DWORD>(-1)
| |
| 1441 info.dwFlags = 0; | |
| 1442 } | |
| 1443 | |
| 1444 __try { | |
| 1445 RaiseException( | |
| 1446 0x406D1388 /* MSVC EXCEPTION */, 0, | |
| 1447 sizeof(info)/sizeof(DWORD), reinterpret_cast<ULONG_PTR*>(&info)); | |
|
Jarin
2014/03/31 07:46:00
The Microsoft article says the third arg should be
| |
| 1448 } | |
| 1449 __except(EXCEPTION_CONTINUE_EXECUTION) {} | |
| 1450 } | |
| 1451 | |
| 1426 // Entry point for threads. The supplied argument is a pointer to the thread | 1452 // 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 | 1453 // object. The entry function dispatches to the run method in the thread |
| 1428 // object. It is important that this function has __stdcall calling | 1454 // object. It is important that this function has __stdcall calling |
| 1429 // convention. | 1455 // convention. |
| 1430 static unsigned int __stdcall ThreadEntry(void* arg) { | 1456 static unsigned int __stdcall ThreadEntry(void* arg) { |
| 1431 Thread* thread = reinterpret_cast<Thread*>(arg); | 1457 Thread* thread = reinterpret_cast<Thread*>(arg); |
| 1458 SetCurThreadName(thread->name()); | |
| 1432 thread->NotifyStartedAndRun(); | 1459 thread->NotifyStartedAndRun(); |
| 1433 return 0; | 1460 return 0; |
| 1434 } | 1461 } |
| 1435 | 1462 |
| 1436 | 1463 |
| 1437 class Thread::PlatformData : public Malloced { | 1464 class Thread::PlatformData : public Malloced { |
| 1438 public: | 1465 public: |
| 1439 explicit PlatformData(HANDLE thread) : thread_(thread) {} | 1466 explicit PlatformData(HANDLE thread) : thread_(thread) {} |
| 1440 HANDLE thread_; | 1467 HANDLE thread_; |
| 1441 unsigned thread_id_; | 1468 unsigned thread_id_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1513 ASSERT(result); | 1540 ASSERT(result); |
| 1514 } | 1541 } |
| 1515 | 1542 |
| 1516 | 1543 |
| 1517 | 1544 |
| 1518 void Thread::YieldCPU() { | 1545 void Thread::YieldCPU() { |
| 1519 Sleep(0); | 1546 Sleep(0); |
| 1520 } | 1547 } |
| 1521 | 1548 |
| 1522 } } // namespace v8::internal | 1549 } } // namespace v8::internal |
| OLD | NEW |