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

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

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
(Empty)
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.
4
5 #include "base/threading/platform_thread.h"
6
7 #include <errno.h>
8 #include <sched.h>
9
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"
14
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
21
22 namespace base {
23
24 namespace internal {
25
26 namespace {
27 #if !defined(OS_NACL)
28 const struct sched_param kRealTimePrio = {8};
29 #endif
30 } // namespace
31
32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
33 {ThreadPriority::BACKGROUND, 10},
34 {ThreadPriority::NORMAL, 0},
35 {ThreadPriority::DISPLAY, -6},
36 {ThreadPriority::REALTIME_AUDIO, -10},
37 }
38
39 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
40 #if !defined(OS_NACL)
41 return priority == ThreadPriority::REALTIME_AUDIO &&
42 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0;
43 #else
44 return false;
45 #endif
46 }
47
48 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) {
49 #if !defined(OS_NACL)
50 int maybe_sched_rr = 0;
51 struct sched_param maybe_realtime_prio = {0};
52 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr,
53 &maybe_realtime_prio) == 0 &&
54 maybe_sched_rr == SCHED_RR &&
55 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) {
56 *priority = ThreadPriority::REALTIME_AUDIO;
57 return true;
58 }
59 #endif
60 return false;
61 }
62
63 } // namespace internal
64
65 // static
66 void PlatformThread::SetName(const std::string& name) {
67 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
68 tracked_objects::ThreadData::InitializeThreadContext(name);
69
70 #if !defined(OS_NACL)
71 // On FreeBSD we can get the thread names to show up in the debugger by
72 // setting the process name for the LWP. We don't want to do this for the
73 // main thread because that would rename the process, causing tools like
74 // killall to stop working.
75 if (PlatformThread::CurrentId() == getpid())
76 return;
77 setproctitle("%s", name.c_str());
78 #endif // !defined(OS_NACL)
79 }
80
81 void InitThreading() {}
82
83 void InitOnThread() {}
84
85 void TerminateOnThread() {}
86
87 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
88 #if !defined(THREAD_SANITIZER)
89 return 0;
90 #else
91 // ThreadSanitizer bloats the stack heavily. Evidence has been that the
92 // default stack size isn't enough for some browser tests.
93 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux).
94 #endif
95 }
96
97 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/platform_thread_android.cc ('k') | base/threading/platform_thread_internal_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698