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

Side by Side Diff: base/platform_thread_mac.mm

Issue 2774001: posix: set thread names (Closed)
Patch Set: disable linux Created 10 years, 6 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
« no previous file with comments | « no previous file | base/platform_thread_posix.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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/platform_thread.h" 5 #include "base/platform_thread.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #include <dlfcn.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/safe_strerror_posix.h"
10 12
11 // A simple class that demonstrates our impressive ability to do nothing. 13 // A simple class that demonstrates our impressive ability to do nothing.
12 @interface NoOp : NSObject 14 @interface NoOp : NSObject
13 15
14 // Does the deed. Or does it? 16 // Does the deed. Or does it?
15 + (void)noOp; 17 + (void)noOp;
16 18
17 @end 19 @end
18 20
19 @implementation NoOp 21 @implementation NoOp
(...skipping 19 matching lines...) Expand all
39 [NSThread detachNewThreadSelector:@selector(noOp) 41 [NSThread detachNewThreadSelector:@selector(noOp)
40 toTarget:[NoOp class] 42 toTarget:[NoOp class]
41 withObject:nil]; 43 withObject:nil];
42 multithreaded = YES; 44 multithreaded = YES;
43 45
44 DCHECK([NSThread isMultiThreaded]); 46 DCHECK([NSThread isMultiThreaded]);
45 } 47 }
46 } 48 }
47 49
48 } // namespace base 50 } // namespace base
51
52 // static
53 void PlatformThread::SetName(const char* name) {
54 // pthread_setname_np is only available in 10.6 or later, so test
55 // for it at runtime.
56 int (*dynamic_pthread_setname_np)(const char*);
57 *reinterpret_cast<void**>(&dynamic_pthread_setname_np) =
58 dlsym(RTLD_DEFAULT, "pthread_setname_np");
59 if (!dynamic_pthread_setname_np)
60 return;
61
62 // Mac OS X does not expose the length limit of the name, so
63 // hardcode it.
64 const int kMaxNameLength = 63;
65 std::string shortened_name = std::string(name).substr(0, kMaxNameLength);
66 int err = dynamic_pthread_setname_np(shortened_name.c_str());
67 if (err < 0)
68 LOG(ERROR) << "pthread_setname_np: " << safe_strerror(err);
69 }
OLDNEW
« no previous file with comments | « no previous file | base/platform_thread_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698