Port Android relocation packer to chromium build
[chromium-blink-merge.git] / base / threading / platform_thread_freebsd.cc
bloba163f650443d08f1602ff295e8c985dab7c7ddd2
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/threading/platform_thread.h"
7 #include <errno.h>
8 #include <sched.h>
10 #include "base/lazy_instance.h"
11 #include "base/logging.h"
12 #include "base/threading/thread_id_name_manager.h"
13 #include "base/tracked_objects.h"
15 #if !defined(OS_NACL)
16 #include <pthread.h>
17 #include <sys/prctl.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20 #endif
22 namespace base {
24 namespace internal {
26 namespace {
27 #if !defined(OS_NACL)
28 const struct sched_param kRealTimePrio = {8};
29 #endif
30 } // namespace
32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
33 { kThreadPriority_RealtimeAudio, -10 },
34 { kThreadPriority_Background, 10 },
35 { kThreadPriority_Normal, 0 },
36 { kThreadPriority_Display, -6 },
39 bool HandleSetThreadPriorityForPlatform(PlatformThreadHandle handle,
40 ThreadPriority priority) {
41 #if !defined(OS_NACL)
42 return priority == kThreadPriority_RealtimeAudio &&
43 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0;
44 #else
45 return false;
46 #endif
49 } // namespace internal
51 // static
52 void PlatformThread::SetName(const char* name) {
53 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
54 tracked_objects::ThreadData::InitializeThreadContext(name);
56 #if !defined(OS_NACL)
57 // On FreeBSD we can get the thread names to show up in the debugger by
58 // setting the process name for the LWP. We don't want to do this for the
59 // main thread because that would rename the process, causing tools like
60 // killall to stop working.
61 if (PlatformThread::CurrentId() == getpid())
62 return;
63 setproctitle("%s", name);
64 #endif // !defined(OS_NACL)
67 void InitThreading() {}
69 void InitOnThread() {}
71 void TerminateOnThread() {}
73 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
74 #if !defined(THREAD_SANITIZER)
75 return 0;
76 #else
77 // ThreadSanitizer bloats the stack heavily. Evidence has been that the
78 // default stack size isn't enough for some browser tests.
79 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux).
80 #endif
83 } // namespace base