diff options
| author | Jayant Chowdhary <jchowdhary@google.com> | 2018-10-02 20:14:37 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-02 20:14:37 +0000 |
| commit | ef712c3344a7a1c36698326488163c74ef5491be (patch) | |
| tree | ca9d51c0edd565f17a85ea9e25edb14de0dfebff | |
| parent | 2efc5dd7db360701430590055551f286d51e4229 (diff) | |
| parent | 985fc89c0c528426cd26025de91dfd5a3531e824 (diff) | |
| download | platform_system_libhwbinder-master-cuttlefish-testing-release.tar.gz platform_system_libhwbinder-master-cuttlefish-testing-release.tar.bz2 platform_system_libhwbinder-master-cuttlefish-testing-release.zip | |
Merge "Reland: "IPCThreadState: Add a public method to probe is a hwbinder called is being served.""android-o-mr1-iot-release-smart-display-r3android-o-mr1-iot-release-1.0.5oreo-mr1-1.2-iot-releasemaster-cuttlefish-testing-release
| -rw-r--r-- | Android.bp | 4 | ||||
| -rw-r--r-- | IPCThreadState.cpp | 11 | ||||
| -rw-r--r-- | include/hwbinder/IPCThreadState.h | 30 |
3 files changed, 44 insertions, 1 deletions
@@ -23,6 +23,7 @@ cc_defaults { "liblog", "libcutils", "libutils", + "libbinderthreadstate", ], export_shared_lib_headers: [ "libbase", @@ -71,7 +72,7 @@ cc_library { defaults: [ "libhwbinder_defaults", "hwbinder_pgo", - "hwbinder_lto" + "hwbinder_lto", ], } @@ -95,6 +96,7 @@ cc_defaults { enable_profile_use: true, }, } + // Provide lto property to build hwbinder with LTO cc_defaults { name: "hwbinder_lto", diff --git a/IPCThreadState.cpp b/IPCThreadState.cpp index b275a7e..d97ad12 100644 --- a/IPCThreadState.cpp +++ b/IPCThreadState.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "hw-IPCThreadState" #include <hwbinder/IPCThreadState.h> +#include <binderthreadstate/IPCThreadStateBase.h> #include <hwbinder/Binder.h> #include <hwbinder/BpHwBinder.h> @@ -764,6 +765,7 @@ IPCThreadState::IPCThreadState() // TODO(b/67742352): remove this variable from the class (void)mMyThreadId; + mIPCThreadStateBase = IPCThreadStateBase::self(); } IPCThreadState::~IPCThreadState() @@ -1114,6 +1116,9 @@ status_t IPCThreadState::executeCommand(int32_t cmd) "Not enough command data for brTRANSACTION"); if (result != NO_ERROR) break; + // Record the fact that we're in a hwbinder call + mIPCThreadStateBase->pushCurrentState( + IPCThreadStateBase::CallState::HWBINDER); Parcel buffer; buffer.ipcSetDataReference( reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer), @@ -1177,6 +1182,7 @@ status_t IPCThreadState::executeCommand(int32_t cmd) error = mContextObject->transact(tr.code, buffer, &reply, tr.flags, reply_callback); } + mIPCThreadStateBase->popCurrentState(); if ((tr.flags & TF_ONE_WAY) == 0) { if (!reply_sent) { // Should have been a reply but there wasn't, so there @@ -1249,6 +1255,11 @@ status_t IPCThreadState::executeCommand(int32_t cmd) return result; } +bool IPCThreadState::isServingCall() const +{ + return mIPCThreadStateBase->getCurrentBinderCallState() == IPCThreadStateBase::CallState::HWBINDER; +} + void IPCThreadState::threadDestructor(void *st) { IPCThreadState* const self = static_cast<IPCThreadState*>(st); diff --git a/include/hwbinder/IPCThreadState.h b/include/hwbinder/IPCThreadState.h index 28ae470..f2112c0 100644 --- a/include/hwbinder/IPCThreadState.h +++ b/include/hwbinder/IPCThreadState.h @@ -30,6 +30,9 @@ typedef int uid_t; // --------------------------------------------------------------------------- namespace android { + +class IPCThreadStateBase; + namespace hardware { class IPCThreadState @@ -95,6 +98,32 @@ public: bool isLooperThread(); bool isOnlyBinderThread(); + // Is this thread currently serving a hwbinder call. This method + // returns true if while traversing backwards from the function call + // stack for this thread, we encounter a function serving a hwbinder + // call before encountering a binder call / hitting the end of the + // call stack. + // Eg: If thread T1 went through the following call pattern + // 1) T1 receives and executes binder call B1. + // 2) While handling B1, T1 makes hwbinder call H1. + // 3) The handler of H1, calls into T1 with a callback H2. + // If isServingCall() is called during B1 before 3), this method + // will return false, else true. + // + // ---- + // | H2 | ---> While callback H2 is being handled during 3). + // ---- + // | B1 | ---> While B1 is being handled, hwbinder call H1 made. + // ---- + // Fig: Thread Call stack while handling H2. + // + // This is since after 3), while traversing the thread call stack, + // we hit a hwbinder call before a binder call / end of stack. + // This method may be typically used to determine whether to use + // hardware::IPCThreadState methods or IPCThreadState methods to + // infer information about thread state. + bool isServingCall() const; + // Tasks which are done on the binder thread after the thread returns to the // threadpool. void addPostCommandTask(const std::function<void(void)>& task); @@ -144,6 +173,7 @@ public: bool mIsPollingThread; std::vector<std::function<void(void)>> mPostCommandTasks; + IPCThreadStateBase *mIPCThreadStateBase; }; }; // namespace hardware |
