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

Side by Side Diff: base/threading/platform_thread.h

Issue 11729002: Set Realtime Audio Thread priority on Android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address bulach's comments Created 7 years, 11 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
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 // WARNING: You should *NOT* be using this class directly. PlatformThread is 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is
6 // the low-level platform-specific abstraction to the OS's threading interface. 6 // the low-level platform-specific abstraction to the OS's threading interface.
7 // You should instead be using a message-loop driven Thread, see thread.h. 7 // You should instead be using a message-loop driven Thread, see thread.h.
8 8
9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_
10 #define BASE_THREADING_PLATFORM_THREAD_H_ 10 #define BASE_THREADING_PLATFORM_THREAD_H_
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 16
17 #if defined(OS_WIN) 17 #if defined(OS_WIN)
18 #include <windows.h> 18 #include <windows.h>
19 #elif defined(OS_POSIX) 19 #elif defined(OS_POSIX)
20 #include <pthread.h> 20 #include <pthread.h>
21 #include <unistd.h> 21 #include <unistd.h>
22 #endif 22 #endif
23 23
24 #if defined(OS_ANDROID)
25 #include "jni.h"
26 #endif
27
24 namespace base { 28 namespace base {
25 29
26 // PlatformThreadHandle should not be assumed to be a numeric type, since the 30 // PlatformThreadHandle should not be assumed to be a numeric type, since the
27 // standard intends to allow pthread_t to be a structure. This means you 31 // standard intends to allow pthread_t to be a structure. This means you
28 // should not initialize it to a value, like 0. If it's a member variable, the 32 // should not initialize it to a value, like 0. If it's a member variable, the
29 // constructor can safely "value initialize" using () in the initializer list. 33 // constructor can safely "value initialize" using () in the initializer list.
30 #if defined(OS_WIN) 34 #if defined(OS_WIN)
31 typedef DWORD PlatformThreadId; 35 typedef DWORD PlatformThreadId;
32 typedef void* PlatformThreadHandle; // HANDLE 36 typedef void* PlatformThreadHandle; // HANDLE
33 const PlatformThreadHandle kNullThreadHandle = NULL; 37 const PlatformThreadHandle kNullThreadHandle = NULL;
34 #elif defined(OS_POSIX) 38 #elif defined(OS_POSIX)
35 typedef pthread_t PlatformThreadHandle; 39 typedef pthread_t PlatformThreadHandle;
36 const PlatformThreadHandle kNullThreadHandle = 0; 40 const PlatformThreadHandle kNullThreadHandle = 0;
37 typedef pid_t PlatformThreadId; 41 typedef pid_t PlatformThreadId;
38 #endif 42 #endif
39 43
40 const PlatformThreadId kInvalidThreadId = 0; 44 const PlatformThreadId kInvalidThreadId = 0;
41 45
42 // Valid values for SetThreadPriority() 46 // Valid values for SetThreadPriority()
43 enum ThreadPriority{ 47 enum ThreadPriority{
44 kThreadPriority_Normal, 48 kThreadPriority_Normal,
45 // Suitable for low-latency, glitch-resistant audio. 49 // Suitable for low-latency, glitch-resistant audio.
46 kThreadPriority_RealtimeAudio 50 kThreadPriority_RealtimeAudio
47 }; 51 };
48 52
53 #if defined(OS_ANDROID)
54 bool RegisterThreadUtils(JNIEnv* env);
55 #endif
56
49 // A namespace for low-level thread functions. 57 // A namespace for low-level thread functions.
50 class BASE_EXPORT PlatformThread { 58 class BASE_EXPORT PlatformThread {
51 public: 59 public:
52 // Implement this interface to run code on a background thread. Your 60 // Implement this interface to run code on a background thread. Your
53 // ThreadMain method will be called on the newly created thread. 61 // ThreadMain method will be called on the newly created thread.
54 class BASE_EXPORT Delegate { 62 class BASE_EXPORT Delegate {
55 public: 63 public:
56 virtual void ThreadMain() = 0; 64 virtual void ThreadMain() = 0;
57 65
58 protected: 66 protected:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 static void SetThreadPriority(PlatformThreadHandle handle, 119 static void SetThreadPriority(PlatformThreadHandle handle,
112 ThreadPriority priority); 120 ThreadPriority priority);
113 121
114 private: 122 private:
115 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); 123 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread);
116 }; 124 };
117 125
118 } // namespace base 126 } // namespace base
119 127
120 #endif // BASE_THREADING_PLATFORM_THREAD_H_ 128 #endif // BASE_THREADING_PLATFORM_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698