xref: /aosp_15_r20/frameworks/av/services/audioflinger/fastpath/FastThreadState.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright (C) 2014 The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker 
17*ec779b8eSAndroid Build Coastguard Worker #pragma once
18*ec779b8eSAndroid Build Coastguard Worker 
19*ec779b8eSAndroid Build Coastguard Worker #include <type_traits>
20*ec779b8eSAndroid Build Coastguard Worker #include "Configuration.h"
21*ec779b8eSAndroid Build Coastguard Worker #include <stdint.h>
22*ec779b8eSAndroid Build Coastguard Worker #include <media/nblog/NBLog.h>
23*ec779b8eSAndroid Build Coastguard Worker 
24*ec779b8eSAndroid Build Coastguard Worker namespace android {
25*ec779b8eSAndroid Build Coastguard Worker 
26*ec779b8eSAndroid Build Coastguard Worker struct FastThreadDumpState;
27*ec779b8eSAndroid Build Coastguard Worker 
28*ec779b8eSAndroid Build Coastguard Worker // Represents a single state of a FastThread
29*ec779b8eSAndroid Build Coastguard Worker struct FastThreadState {
30*ec779b8eSAndroid Build Coastguard Worker     using Command = uint32_t;
31*ec779b8eSAndroid Build Coastguard Worker     static const Command
32*ec779b8eSAndroid Build Coastguard Worker         INITIAL = 0,            // used only for the initial state
33*ec779b8eSAndroid Build Coastguard Worker         HOT_IDLE = 1,           // do nothing
34*ec779b8eSAndroid Build Coastguard Worker         COLD_IDLE = 2,          // wait for the futex
35*ec779b8eSAndroid Build Coastguard Worker         IDLE = 3,               // either HOT_IDLE or COLD_IDLE
36*ec779b8eSAndroid Build Coastguard Worker         EXIT = 4;               // exit from thread
37*ec779b8eSAndroid Build Coastguard Worker         // additional values defined per subclass
38*ec779b8eSAndroid Build Coastguard Worker     Command     mCommand = INITIAL;       // current command
39*ec779b8eSAndroid Build Coastguard Worker     int32_t*    mColdFutexAddr = nullptr; // for COLD_IDLE only, pointer to the associated futex
40*ec779b8eSAndroid Build Coastguard Worker     unsigned    mColdGen = 0;             // increment when COLD_IDLE is requested
41*ec779b8eSAndroid Build Coastguard Worker                                           // so it's only performed once
42*ec779b8eSAndroid Build Coastguard Worker 
43*ec779b8eSAndroid Build Coastguard Worker     // This might be a one-time configuration rather than per-state
44*ec779b8eSAndroid Build Coastguard Worker     FastThreadDumpState* mDumpState = nullptr; // if non-NULL, then update dump state periodically
45*ec779b8eSAndroid Build Coastguard Worker     NBLog::Writer* mNBLogWriter = nullptr; // non-blocking logger
46*ec779b8eSAndroid Build Coastguard Worker 
47*ec779b8eSAndroid Build Coastguard Worker     // returns NULL if command belongs to a subclass
48*ec779b8eSAndroid Build Coastguard Worker     static const char *commandToString(Command command);
49*ec779b8eSAndroid Build Coastguard Worker };  // struct FastThreadState
50*ec779b8eSAndroid Build Coastguard Worker 
51*ec779b8eSAndroid Build Coastguard Worker // No virtuals.
52*ec779b8eSAndroid Build Coastguard Worker static_assert(!std::is_polymorphic_v<FastThreadState>);
53*ec779b8eSAndroid Build Coastguard Worker 
54*ec779b8eSAndroid Build Coastguard Worker }  // namespace android
55