summaryrefslogtreecommitdiffstats
path: root/security/sandbox/chromium-shim/base/threading/platform_thread_linux.cpp
blob: aed65a06bdab3e52f64be1b893eef3d05057dab8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This is a cut down version of Chromium source file base/threading/platform_thread_linux.h
// with only the functions required. It also has a dummy implementation of
// SetCurrentThreadPriorityForPlatform, which should not be called.

#include "base/threading/platform_thread.h"

#include "base/threading/platform_thread_internal_posix.h"

#include "mozilla/Assertions.h"

namespace base {
namespace internal {

namespace {
const struct sched_param kRealTimePrio = {8};
}  // namespace

const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = {
    {ThreadPriority::BACKGROUND, 10},
    {ThreadPriority::NORMAL, 0},
    {ThreadPriority::DISPLAY, -8},
    {ThreadPriority::REALTIME_AUDIO, -10},
};


Optional<bool> CanIncreaseCurrentThreadPriorityForPlatform(
    ThreadPriority priority) {
  MOZ_CRASH();
}

bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
  MOZ_CRASH();
}

Optional<ThreadPriority> GetCurrentThreadPriorityForPlatform() {
  int maybe_sched_rr = 0;
  struct sched_param maybe_realtime_prio = {0};
  if (pthread_getschedparam(pthread_self(), &maybe_sched_rr,
                            &maybe_realtime_prio) == 0 &&
      maybe_sched_rr == SCHED_RR &&
      maybe_realtime_prio.sched_priority == kRealTimePrio.sched_priority) {
    return base::make_optional(ThreadPriority::REALTIME_AUDIO);
  }
  return base::nullopt;
}

}  // namespace internal

void InitThreading() {}

void TerminateOnThread() {}

size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) {
#if !defined(THREAD_SANITIZER)
  return 0;
#else
  // ThreadSanitizer bloats the stack heavily. Evidence has been that the
  // default stack size isn't enough for some browser tests.
  return 2 * (1 << 23);  // 2 times 8192K (the default stack size on Linux).
#endif
}

}  // namespace base