| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| Andy Hung | f0859f3 | 2023-05-25 16:28:04 -0700 | [diff] [blame] | 17 | #pragma once |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 18 | |
| Andy Hung | f0859f3 | 2023-05-25 16:28:04 -0700 | [diff] [blame] | 19 | #include <type_traits> |
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 20 | #include "Configuration.h" |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| Glenn Kasten | 8589ce7 | 2017-09-08 17:03:42 -0700 | [diff] [blame] | 22 | #include <media/nblog/NBLog.h> |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 26 | struct FastThreadDumpState; |
| 27 | |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 28 | // Represents a single state of a FastThread |
| 29 | struct FastThreadState { |
| Andy Hung | f0859f3 | 2023-05-25 16:28:04 -0700 | [diff] [blame] | 30 | using Command = uint32_t; |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 31 | static const Command |
| 32 | INITIAL = 0, // used only for the initial state |
| 33 | HOT_IDLE = 1, // do nothing |
| 34 | COLD_IDLE = 2, // wait for the futex |
| 35 | IDLE = 3, // either HOT_IDLE or COLD_IDLE |
| 36 | EXIT = 4; // exit from thread |
| 37 | // additional values defined per subclass |
| Andy Hung | 0530237 | 2023-05-26 16:24:28 -0700 | [diff] [blame] | 38 | Command mCommand = INITIAL; // current command |
| 39 | int32_t* mColdFutexAddr = nullptr; // for COLD_IDLE only, pointer to the associated futex |
| 40 | unsigned mColdGen = 0; // increment when COLD_IDLE is requested |
| 41 | // so it's only performed once |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 42 | |
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 43 | // This might be a one-time configuration rather than per-state |
| Andy Hung | 0530237 | 2023-05-26 16:24:28 -0700 | [diff] [blame] | 44 | FastThreadDumpState* mDumpState = nullptr; // if non-NULL, then update dump state periodically |
| 45 | NBLog::Writer* mNBLogWriter = nullptr; // non-blocking logger |
| Glenn Kasten | 2234002 | 2014-04-07 12:04:41 -0700 | [diff] [blame] | 46 | |
| Glenn Kasten | d702a56 | 2015-03-02 15:51:38 -0800 | [diff] [blame] | 47 | // returns NULL if command belongs to a subclass |
| 48 | static const char *commandToString(Command command); |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 49 | }; // struct FastThreadState |
| 50 | |
| Andy Hung | f0859f3 | 2023-05-25 16:28:04 -0700 | [diff] [blame] | 51 | // No virtuals. |
| 52 | static_assert(!std::is_polymorphic_v<FastThreadState>); |
| Glenn Kasten | a18f644 | 2014-03-18 17:17:04 -0700 | [diff] [blame] | 53 | |
| Andy Hung | f0859f3 | 2023-05-25 16:28:04 -0700 | [diff] [blame] | 54 | } // namespace android |