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

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

Issue 2876623002: base: remove FreeBSD port of platform_thread.h (Closed)
Patch Set: Created 3 years, 7 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 | 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
(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 #include <stddef.h>
10
11 #include "base/lazy_instance.h"
12 #include "base/logging.h"
13 #include "base/threading/platform_thread_internal_posix.h"
14 #include "base/threading/thread_id_name_manager.h"
15 #include "base/tracked_objects.h"
16 #include "build/build_config.h"
17
18 #if !defined(OS_NACL)
19 #include <pthread.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22 #endif
23
24 namespace base {
25
26 namespace internal {
27
28 namespace {
29 #if !defined(OS_NACL)
30 const struct sched_param kRealTimePrio = {8};
31 #endif
32 } // namespace
33
34 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
35 {ThreadPriority::BACKGROUND, 10},
36 {ThreadPriority::NORMAL, 0},
37 {ThreadPriority::DISPLAY, -6},
38 {ThreadPriority::REALTIME_AUDIO, -10},
39 };
40
41 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
42 #if !defined(OS_NACL)
43 return priority == ThreadPriority::REALTIME_AUDIO &&
44 pthread_setschedparam(pthread_self(), SCHED_RR, &kRealTimePrio) == 0;
45 #else
46 return false;
47 #endif
48 }
49
50 bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) {
51 #if !defined(OS_NACL)
52 int maybe_sched_rr = 0;
53 struct sched_param maybe_realtime_prio = {0};
54 if (pthread_getschedparam(pthread_self(), &maybe_sched_rr,
55 &maybe_realtime_prio) == 0 &&
56 maybe_sched_rr == SCHED_RR &&
57 maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) {
58 *priority = ThreadPriority::REALTIME_AUDIO;
59 return true;
60 }
61 #endif
62 return false;
63 }
64
65 } // namespace internal
66
67 // static
68 void PlatformThread::SetName(const std::string& name) {
69 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
70 tracked_objects::ThreadData::InitializeThreadContext(name);
71
72 #if !defined(OS_NACL)
73 // On FreeBSD we can get the thread names to show up in the debugger by
74 // setting the process name for the LWP. We don't want to do this for the
75 // main thread because that would rename the process, causing tools like
76 // killall to stop working.
77 if (PlatformThread::CurrentId() == getpid())
78 return;
79 setproctitle("%s", name.c_str());
80 #endif // !defined(OS_NACL)
81 }
82
83 void InitThreading() {}
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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698