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