Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e922b232 authored by Andrei Homescu's avatar Andrei Homescu
Browse files

libbinder: use base::GetThreadId instead of gettid

RpcSession uses gettid() to identify the current thread
which is less portable than GetThreadId().

Test: atest binderRpcTest
Bug: 224644083
Change-Id: I0d6020ef41af85c20bb58b89598812f2e790a38b
parent c24c8791
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -43,10 +43,6 @@
#include "RpcWireFormat.h"
#include "Utils.h"

#ifdef __GLIBC__
extern "C" pid_t gettid();
#endif

#ifndef __ANDROID_RECOVERY__
#include <android_runtime/vm.h>
#include <jni.h>
@@ -693,7 +689,7 @@ status_t RpcSession::addOutgoingConnection(std::unique_ptr<RpcTransport> rpcTran
    {
        std::lock_guard<std::mutex> _l(mMutex);
        connection->rpcTransport = std::move(rpcTransport);
        connection->exclusiveTid = gettid();
        connection->exclusiveTid = base::GetThreadId();
        mConnections.mOutgoing.push_back(connection);
    }

@@ -750,7 +746,7 @@ sp<RpcSession::RpcConnection> RpcSession::assignIncomingConnectionToThisThread(

    sp<RpcConnection> session = sp<RpcConnection>::make();
    session->rpcTransport = std::move(rpcTransport);
    session->exclusiveTid = gettid();
    session->exclusiveTid = base::GetThreadId();

    mConnections.mIncoming.push_back(session);
    mConnections.mMaxIncoming = mConnections.mIncoming.size();
@@ -786,7 +782,7 @@ status_t RpcSession::ExclusiveConnection::find(const sp<RpcSession>& session, Co
    connection->mConnection = nullptr;
    connection->mReentrant = false;

    pid_t tid = gettid();
    uint64_t tid = base::GetThreadId();
    std::unique_lock<std::mutex> _l(session->mMutex);

    session->mConnections.mWaitingThreads++;
@@ -873,7 +869,7 @@ status_t RpcSession::ExclusiveConnection::find(const sp<RpcSession>& session, Co
    return OK;
}

void RpcSession::ExclusiveConnection::findConnection(pid_t tid, sp<RpcConnection>* exclusive,
void RpcSession::ExclusiveConnection::findConnection(uint64_t tid, sp<RpcConnection>* exclusive,
                                                     sp<RpcConnection>* available,
                                                     std::vector<sp<RpcConnection>>& sockets,
                                                     size_t socketsIndexHint) {
+3 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
#pragma once

#include <android-base/threads.h>
#include <android-base/unique_fd.h>
#include <binder/IBinder.h>
#include <binder/RpcTransport.h>
@@ -211,7 +212,7 @@ private:

        // whether this or another thread is currently using this fd to make
        // or receive transactions.
        std::optional<pid_t> exclusiveTid;
        std::optional<uint64_t> exclusiveTid;

        bool allowNested = false;
    };
@@ -276,7 +277,7 @@ private:
        const sp<RpcConnection>& get() { return mConnection; }

    private:
        static void findConnection(pid_t tid, sp<RpcConnection>* exclusive,
        static void findConnection(uint64_t tid, sp<RpcConnection>* exclusive,
                                   sp<RpcConnection>* available,
                                   std::vector<sp<RpcConnection>>& sockets,
                                   size_t socketsIndexHint);