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

Side by Side Diff: base/threading/platform_thread_win.cc

Issue 75133004: Close duplicated handle on windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/platform_thread.h" 5 #include "base/threading/platform_thread.h"
6 6
7 #include "base/debug/alias.h" 7 #include "base/debug/alias.h"
8 #include "base/debug/profiler.h" 8 #include "base/debug/profiler.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_id_name_manager.h" 10 #include "base/threading/thread_id_name_manager.h"
11 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
12 #include "base/tracked_objects.h" 12 #include "base/tracked_objects.h"
13 13 #include "base/win/scoped_handle.h"
14 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 namespace { 18 namespace {
19 19
20 // The information on how to set the thread name comes from 20 // The information on how to set the thread name comes from
21 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx 21 // a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx
22 const DWORD kVCThreadNameException = 0x406D1388; 22 const DWORD kVCThreadNameException = 0x406D1388;
23 23
(...skipping 23 matching lines...) Expand all
47 PlatformThread::Delegate* delegate; 47 PlatformThread::Delegate* delegate;
48 bool joinable; 48 bool joinable;
49 }; 49 };
50 50
51 DWORD __stdcall ThreadFunc(void* params) { 51 DWORD __stdcall ThreadFunc(void* params) {
52 ThreadParams* thread_params = static_cast<ThreadParams*>(params); 52 ThreadParams* thread_params = static_cast<ThreadParams*>(params);
53 PlatformThread::Delegate* delegate = thread_params->delegate; 53 PlatformThread::Delegate* delegate = thread_params->delegate;
54 if (!thread_params->joinable) 54 if (!thread_params->joinable)
55 base::ThreadRestrictions::SetSingletonAllowed(false); 55 base::ThreadRestrictions::SetSingletonAllowed(false);
56 56
57 /* Retrieve a copy of the thread handle to use as the key in the 57 // Retrieve a copy of the thread handle to use as the key in the
58 * thread name mapping. */ 58 // thread name mapping.
59 PlatformThreadHandle::Handle platform_handle; 59 PlatformThreadHandle::Handle platform_handle;
60 DuplicateHandle( 60 BOOL did_dup = DuplicateHandle(GetCurrentProcess(),
61 GetCurrentProcess(), 61 GetCurrentThread(),
62 GetCurrentThread(), 62 GetCurrentProcess(),
63 GetCurrentProcess(), 63 &platform_handle,
64 &platform_handle, 64 0,
65 0, 65 FALSE,
66 FALSE, 66 DUPLICATE_SAME_ACCESS);
67 DUPLICATE_SAME_ACCESS);
68 67
69 ThreadIdNameManager::GetInstance()->RegisterThread( 68 win::ScopedHandle scoped_platform_handle;
70 platform_handle, 69
71 PlatformThread::CurrentId()); 70 if (did_dup) {
71 scoped_platform_handle.Set(platform_handle);
72 ThreadIdNameManager::GetInstance()->RegisterThread(
73 scoped_platform_handle.Get(),
74 PlatformThread::CurrentId());
75 }
72 76
73 delete thread_params; 77 delete thread_params;
74 delegate->ThreadMain(); 78 delegate->ThreadMain();
75 79
76 ThreadIdNameManager::GetInstance()->RemoveName( 80 if (did_dup) {
77 platform_handle, 81 ThreadIdNameManager::GetInstance()->RemoveName(
78 PlatformThread::CurrentId()); 82 scoped_platform_handle.Get(),
83 PlatformThread::CurrentId());
84 }
85
79 return NULL; 86 return NULL;
80 } 87 }
81 88
82 // CreateThreadInternal() matches PlatformThread::Create(), except that 89 // CreateThreadInternal() matches PlatformThread::Create(), except that
83 // |out_thread_handle| may be NULL, in which case a non-joinable thread is 90 // |out_thread_handle| may be NULL, in which case a non-joinable thread is
84 // created. 91 // created.
85 bool CreateThreadInternal(size_t stack_size, 92 bool CreateThreadInternal(size_t stack_size,
86 PlatformThread::Delegate* delegate, 93 PlatformThread::Delegate* delegate,
87 PlatformThreadHandle* out_thread_handle) { 94 PlatformThreadHandle* out_thread_handle) {
88 unsigned int flags = 0; 95 unsigned int flags = 0;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 case kThreadPriority_RealtimeAudio: 237 case kThreadPriority_RealtimeAudio:
231 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL); 238 ::SetThreadPriority(handle.handle_, THREAD_PRIORITY_TIME_CRITICAL);
232 break; 239 break;
233 default: 240 default:
234 NOTREACHED() << "Unknown priority."; 241 NOTREACHED() << "Unknown priority.";
235 break; 242 break;
236 } 243 }
237 } 244 }
238 245
239 } // namespace base 246 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698