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

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

libbinder: compile some Linux code conditionally

Binder.cpp and Parcel.cpp contain some Linux-specific code
that deals with scheduling and task priorities. This disables
those headers and methods on non-Linux OSes.

Bug: 224644083
Test: m
Change-Id: I5edf60a16ccb2d1abbc669f80b397238622112fe
parent 1519b984
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -32,9 +32,12 @@
#include <utils/misc.h>
#include <utils/misc.h>


#include <inttypes.h>
#include <inttypes.h>
#include <linux/sched.h>
#include <stdio.h>
#include <stdio.h>


#ifdef __linux__
#include <linux/sched.h>
#endif

#include "RpcState.h"
#include "RpcState.h"


namespace android {
namespace android {
@@ -234,11 +237,13 @@ class BBinder::Extras
{
{
public:
public:
    // unlocked objects
    // unlocked objects
    bool mRequestingSid = false;
    bool mInheritRt = false;
    sp<IBinder> mExtension;
    sp<IBinder> mExtension;
#ifdef __linux__
    int mPolicy = SCHED_NORMAL;
    int mPolicy = SCHED_NORMAL;
    int mPriority = 0;
    int mPriority = 0;
#endif
    bool mRequestingSid = false;
    bool mInheritRt = false;


    // for below objects
    // for below objects
    Mutex mLock;
    Mutex mLock;
@@ -407,6 +412,7 @@ sp<IBinder> BBinder::getExtension() {
    return e->mExtension;
    return e->mExtension;
}
}


#ifdef __linux__
void BBinder::setMinSchedulerPolicy(int policy, int priority) {
void BBinder::setMinSchedulerPolicy(int policy, int priority) {
    LOG_ALWAYS_FATAL_IF(mParceled,
    LOG_ALWAYS_FATAL_IF(mParceled,
                        "setMinSchedulerPolicy() should not be called after a binder object "
                        "setMinSchedulerPolicy() should not be called after a binder object "
@@ -451,6 +457,7 @@ int BBinder::getMinSchedulerPriority() {
    if (e == nullptr) return 0;
    if (e == nullptr) return 0;
    return e->mPriority;
    return e->mPriority;
}
}
#endif // __linux__


bool BBinder::isInheritRt() {
bool BBinder::isInheritRt() {
    Extras* e = mExtras.load(std::memory_order_acquire);
    Extras* e = mExtras.load(std::memory_order_acquire);
@@ -478,7 +485,12 @@ void BBinder::setInheritRt(bool inheritRt) {
}
}


pid_t BBinder::getDebugPid() {
pid_t BBinder::getDebugPid() {
#ifdef __linux__
    return getpid();
    return getpid();
#else
    // TODO: handle other OSes
    return 0;
#endif // __linux__
}
}


void BBinder::setExtension(const sp<IBinder>& extension) {
void BBinder::setExtension(const sp<IBinder>& extension) {