blob: 3e563734ec66bdc5b1aeaadc75e21e1bf66ceeeb [file] [log] [blame]
Mathias Agopian2bd99592012-02-25 23:02:14 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LIBS_UTILS_THREAD_DEFS_H
18#define _LIBS_UTILS_THREAD_DEFS_H
19
20#include <stdint.h>
21#include <sys/types.h>
22#include <system/graphics.h>
23
24// ---------------------------------------------------------------------------
25// C API
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31typedef void* android_thread_id_t;
32
33typedef int (*android_thread_func_t)(void*);
34
35enum {
36 /*
37 * ***********************************************
38 * ** Keep in sync with android.os.Process.java **
39 * ***********************************************
40 *
41 * This maps directly to the "nice" priorities we use in Android.
42 * A thread priority should be chosen inverse-proportionally to
43 * the amount of work the thread is expected to do. The more work
44 * a thread will do, the less favorable priority it should get so that
45 * it doesn't starve the system. Threads not behaving properly might
46 * be "punished" by the kernel.
47 * Use the levels below when appropriate. Intermediate values are
48 * acceptable, preferably use the {MORE|LESS}_FAVORABLE constants below.
49 */
50 ANDROID_PRIORITY_LOWEST = 19,
51
52 /* use for background tasks */
53 ANDROID_PRIORITY_BACKGROUND = 10,
54
55 /* most threads run at normal priority */
56 ANDROID_PRIORITY_NORMAL = 0,
57
58 /* threads currently running a UI that the user is interacting with */
59 ANDROID_PRIORITY_FOREGROUND = -2,
60
61 /* the main UI thread has a slightly more favorable priority */
62 ANDROID_PRIORITY_DISPLAY = -4,
63
64 /* ui service treads might want to run at a urgent display (uncommon) */
65 ANDROID_PRIORITY_URGENT_DISPLAY = HAL_PRIORITY_URGENT_DISPLAY,
66
67 /* all normal audio threads */
68 ANDROID_PRIORITY_AUDIO = -16,
69
70 /* service audio threads (uncommon) */
71 ANDROID_PRIORITY_URGENT_AUDIO = -19,
72
73 /* should never be used in practice. regular process might not
74 * be allowed to use this level */
75 ANDROID_PRIORITY_HIGHEST = -20,
76
77 ANDROID_PRIORITY_DEFAULT = ANDROID_PRIORITY_NORMAL,
78 ANDROID_PRIORITY_MORE_FAVORABLE = -1,
79 ANDROID_PRIORITY_LESS_FAVORABLE = +1,
80};
81
82enum {
83 ANDROID_TGROUP_DEFAULT = 0,
84 ANDROID_TGROUP_BG_NONINTERACT = 1,
85 ANDROID_TGROUP_FG_BOOST = 2,
86 ANDROID_TGROUP_MAX = ANDROID_TGROUP_FG_BOOST,
87};
88
89#ifdef __cplusplus
90} // extern "C"
91#endif
92
93// ---------------------------------------------------------------------------
94// C++ API
95#ifdef __cplusplus
96namespace android {
97// ---------------------------------------------------------------------------
98
99typedef android_thread_id_t thread_id_t;
100typedef android_thread_func_t thread_func_t;
101
102enum {
103 PRIORITY_LOWEST = ANDROID_PRIORITY_LOWEST,
104 PRIORITY_BACKGROUND = ANDROID_PRIORITY_BACKGROUND,
105 PRIORITY_NORMAL = ANDROID_PRIORITY_NORMAL,
106 PRIORITY_FOREGROUND = ANDROID_PRIORITY_FOREGROUND,
107 PRIORITY_DISPLAY = ANDROID_PRIORITY_DISPLAY,
108 PRIORITY_URGENT_DISPLAY = ANDROID_PRIORITY_URGENT_DISPLAY,
109 PRIORITY_AUDIO = ANDROID_PRIORITY_AUDIO,
110 PRIORITY_URGENT_AUDIO = ANDROID_PRIORITY_URGENT_AUDIO,
111 PRIORITY_HIGHEST = ANDROID_PRIORITY_HIGHEST,
112 PRIORITY_DEFAULT = ANDROID_PRIORITY_DEFAULT,
113 PRIORITY_MORE_FAVORABLE = ANDROID_PRIORITY_MORE_FAVORABLE,
114 PRIORITY_LESS_FAVORABLE = ANDROID_PRIORITY_LESS_FAVORABLE,
115};
116
117// ---------------------------------------------------------------------------
118}; // namespace android
119#endif // __cplusplus
120// ---------------------------------------------------------------------------
121
122
123#endif // _LIBS_UTILS_THREAD_DEFS_H