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

Commit ab75e271 authored by Matthew Sedam's avatar Matthew Sedam
Browse files

RpcThreads.h: Remove certain header dependencies when single-threaded

This CL removes the dependency on <condition_variable> and
<mutex> in RpcThreads.h when BINDER_RPC_SINGLE_THREADED is defined.
This is one of the changes meant to make libbinder more embedded
friendly.

Bug: 413090516
Flag: EXEMPT bugfix
Test: m libbinder libbinder_rpc_single_threaded
Change-Id: Iff555edf883b327b548bc734ad4ca9295a16b66d
parent a9836bdb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -340,7 +340,7 @@ bool RpcServer::shutdown() {
    }

    while (mJoinThreadRunning || !mConnectingThreads.empty() || !mSessions.empty()) {
        if (std::cv_status::timeout == mShutdownCv.wait_for(_l, std::chrono::seconds(1))) {
        if (mShutdownCv.wait_for(_l, std::chrono::seconds(1)) == RpcCvStatus::timeout) {
            ALOGE("Waiting for RpcServer to shut down (1s w/o progress). Join thread running: %d, "
                  "Connecting threads: "
                  "%zu, Sessions: %zu. Is your server deadlocked?",
+1 −1
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ void RpcSession::WaitForShutdownListener::onSessionIncomingThreadEnded() {
void RpcSession::WaitForShutdownListener::waitForShutdown(RpcMutexUniqueLock& lock,
                                                          const sp<RpcSession>& session) {
    while (mShutdownCount < session->mConnections.mMaxIncoming) {
        if (std::cv_status::timeout == mCv.wait_for(lock, std::chrono::seconds(1))) {
        if (mCv.wait_for(lock, std::chrono::seconds(1)) == RpcCvStatus::timeout) {
            ALOGE("Waiting for RpcSession to shut down (1s w/o progress): %zu incoming connections "
                  "still %zu/%zu fully shutdown.",
                  session->mConnections.mIncoming.size(), mShutdownCount.load(),
+13 −3
Original line number Diff line number Diff line
@@ -17,17 +17,26 @@

#include <pthread.h>

#include <condition_variable>
#include <functional>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>

#ifndef BINDER_RPC_SINGLE_THREADED
#include <condition_variable>
#include <mutex>
#include <thread>
#endif // BINDER_RPC_SINGLE_THREADED

#include <binder/Common.h>

namespace android {

#ifdef BINDER_RPC_SINGLE_THREADED

enum class LIBBINDER_EXPORTED RpcCvStatus { no_timeout, timeout };

class LIBBINDER_EXPORTED RpcMutex {
public:
    void lock() {}
@@ -58,8 +67,8 @@ public:
    }

    template <typename Duration>
    std::cv_status wait_for(RpcMutexUniqueLock&, const Duration&) {
        return std::cv_status::no_timeout;
    RpcCvStatus wait_for(RpcMutexUniqueLock&, const Duration&) {
        return RpcCvStatus::no_timeout;
    }

    template <typename Duration, typename Predicate>
@@ -132,6 +141,7 @@ using RpcMutexLockGuard = std::lock_guard<std::mutex>;
using RpcConditionVariable = std::condition_variable;
using RpcMaybeThread = std::thread;
namespace rpc_this_thread = std::this_thread;
using RpcCvStatus = std::cv_status;

static inline void rpcJoinIfSingleThreaded(RpcMaybeThread&) {}
#endif // BINDER_RPC_SINGLE_THREADED