Mathias Agopian | f91bb05 | 2012-02-25 23:02:14 -0800 | [diff] [blame] | 1 | /* |
| 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 |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | typedef void* android_thread_id_t; |
| 32 | |
| 33 | typedef int (*android_thread_func_t)(void*); |
| 34 | |
| 35 | enum { |
| 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 | |
Mathias Agopian | f91bb05 | 2012-02-25 23:02:14 -0800 | [diff] [blame] | 82 | #ifdef __cplusplus |
| 83 | } // extern "C" |
| 84 | #endif |
| 85 | |
| 86 | // --------------------------------------------------------------------------- |
| 87 | // C++ API |
| 88 | #ifdef __cplusplus |
| 89 | namespace android { |
| 90 | // --------------------------------------------------------------------------- |
| 91 | |
| 92 | typedef android_thread_id_t thread_id_t; |
| 93 | typedef android_thread_func_t thread_func_t; |
| 94 | |
| 95 | enum { |
| 96 | PRIORITY_LOWEST = ANDROID_PRIORITY_LOWEST, |
| 97 | PRIORITY_BACKGROUND = ANDROID_PRIORITY_BACKGROUND, |
| 98 | PRIORITY_NORMAL = ANDROID_PRIORITY_NORMAL, |
| 99 | PRIORITY_FOREGROUND = ANDROID_PRIORITY_FOREGROUND, |
| 100 | PRIORITY_DISPLAY = ANDROID_PRIORITY_DISPLAY, |
| 101 | PRIORITY_URGENT_DISPLAY = ANDROID_PRIORITY_URGENT_DISPLAY, |
| 102 | PRIORITY_AUDIO = ANDROID_PRIORITY_AUDIO, |
| 103 | PRIORITY_URGENT_AUDIO = ANDROID_PRIORITY_URGENT_AUDIO, |
| 104 | PRIORITY_HIGHEST = ANDROID_PRIORITY_HIGHEST, |
| 105 | PRIORITY_DEFAULT = ANDROID_PRIORITY_DEFAULT, |
| 106 | PRIORITY_MORE_FAVORABLE = ANDROID_PRIORITY_MORE_FAVORABLE, |
| 107 | PRIORITY_LESS_FAVORABLE = ANDROID_PRIORITY_LESS_FAVORABLE, |
| 108 | }; |
| 109 | |
| 110 | // --------------------------------------------------------------------------- |
| 111 | }; // namespace android |
| 112 | #endif // __cplusplus |
| 113 | // --------------------------------------------------------------------------- |
| 114 | |
| 115 | |
| 116 | #endif // _LIBS_UTILS_THREAD_DEFS_H |