| OLD | NEW |
| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <sched.h> | 8 #include <sched.h> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 *priority = ThreadPriority::REALTIME_AUDIO; | 63 *priority = ThreadPriority::REALTIME_AUDIO; |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 #endif | 66 #endif |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace internal | 70 } // namespace internal |
| 71 | 71 |
| 72 // static | 72 // static |
| 73 void PlatformThread::SetName(const char* name) { | 73 void PlatformThread::SetName(const std::string& name) { |
| 74 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 74 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
| 75 tracked_objects::ThreadData::InitializeThreadContext(name); | 75 tracked_objects::ThreadData::InitializeThreadContext(name); |
| 76 | 76 |
| 77 #if !defined(OS_NACL) | 77 #if !defined(OS_NACL) |
| 78 // On linux we can get the thread names to show up in the debugger by setting | 78 // On linux we can get the thread names to show up in the debugger by setting |
| 79 // the process name for the LWP. We don't want to do this for the main | 79 // the process name for the LWP. We don't want to do this for the main |
| 80 // thread because that would rename the process, causing tools like killall | 80 // thread because that would rename the process, causing tools like killall |
| 81 // to stop working. | 81 // to stop working. |
| 82 if (PlatformThread::CurrentId() == getpid()) | 82 if (PlatformThread::CurrentId() == getpid()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 // http://0pointer.de/blog/projects/name-your-threads.html | 85 // http://0pointer.de/blog/projects/name-your-threads.html |
| 86 // Set the name for the LWP (which gets truncated to 15 characters). | 86 // Set the name for the LWP (which gets truncated to 15 characters). |
| 87 // Note that glibc also has a 'pthread_setname_np' api, but it may not be | 87 // Note that glibc also has a 'pthread_setname_np' api, but it may not be |
| 88 // available everywhere and it's only benefit over using prctl directly is | 88 // available everywhere and it's only benefit over using prctl directly is |
| 89 // that it can set the name of threads other than the current thread. | 89 // that it can set the name of threads other than the current thread. |
| 90 int err = prctl(PR_SET_NAME, name); | 90 int err = prctl(PR_SET_NAME, name.c_str()); |
| 91 // We expect EPERM failures in sandboxed processes, just ignore those. | 91 // We expect EPERM failures in sandboxed processes, just ignore those. |
| 92 if (err < 0 && errno != EPERM) | 92 if (err < 0 && errno != EPERM) |
| 93 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 93 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
| 94 #endif // !defined(OS_NACL) | 94 #endif // !defined(OS_NACL) |
| 95 } | 95 } |
| 96 | 96 |
| 97 void InitThreading() {} | 97 void InitThreading() {} |
| 98 | 98 |
| 99 void InitOnThread() {} | 99 void InitOnThread() {} |
| 100 | 100 |
| 101 void TerminateOnThread() {} | 101 void TerminateOnThread() {} |
| 102 | 102 |
| 103 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 103 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
| 104 #if !defined(THREAD_SANITIZER) | 104 #if !defined(THREAD_SANITIZER) |
| 105 return 0; | 105 return 0; |
| 106 #else | 106 #else |
| 107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 107 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
| 108 // default stack size isn't enough for some browser tests. | 108 // default stack size isn't enough for some browser tests. |
| 109 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 109 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
| 110 #endif | 110 #endif |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace base | 113 } // namespace base |
| OLD | NEW |