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

Commit 0e09f088 authored by Josh Gao's avatar Josh Gao Committed by android-build-merger
Browse files

Merge changes Ifed3b97a,I09aacb94,I9afedd7b am: 7d3f0066

am: 4e4f25c6

Change-Id: I27c3065babebdc13f4c11b7830071df0c6cba878
parents b7ce3641 4e4f25c6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -213,6 +213,7 @@ cc_test_host {
cc_benchmark {
    name: "adb_benchmark",
    defaults: ["adb_defaults"],
    host_supported: true,

    srcs: ["transport_benchmark.cpp"],
    target: {
@@ -226,6 +227,9 @@ cc_benchmark {
                "libadb_host",
            ],
        },
        darwin: {
            enabled: false,
        }
    },

    static_libs: [
+2 −0
Original line number Diff line number Diff line
@@ -183,8 +183,10 @@ ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::SameThread);
ADB_CONNECTION_BENCHMARK(BM_Connection_Echo, ThreadPolicy::MainThread);

int main(int argc, char** argv) {
#if defined(__BIONIC__)
    // Set M_DECAY_TIME so that our allocations aren't immediately purged on free.
    mallopt(M_DECAY_TIME, 1);
#endif

    android::base::SetMinimumLogSeverity(android::base::WARNING);
    adb_trace_init(argv);
+15 −17
Original line number Diff line number Diff line
@@ -85,18 +85,9 @@ struct NonblockingFdConnection : public Connection {
            if (pfds[0].revents) {
                if ((pfds[0].revents & POLLOUT)) {
                    std::lock_guard<std::mutex> lock(this->write_mutex_);
                    WriteResult result = DispatchWrites();
                    switch (result) {
                        case WriteResult::Error:
                    if (DispatchWrites() == WriteResult::Error) {
                        *error = "write failed";
                        return;

                        case WriteResult::Completed:
                            writable_ = true;
                            break;

                        case WriteResult::TryAgain:
                            break;
                    }
                }

@@ -179,13 +170,14 @@ struct NonblockingFdConnection : public Connection {

    WriteResult DispatchWrites() REQUIRES(write_mutex_) {
        CHECK(!write_buffer_.empty());
        if (!writable_) {
            return WriteResult::TryAgain;
        }

        auto iovs = write_buffer_.iovecs();
        ssize_t rc = adb_writev(fd_.get(), iovs.data(), iovs.size());
        if (rc == -1) {
            if (errno == EAGAIN || errno == EWOULDBLOCK) {
                writable_ = false;
                return WriteResult::TryAgain;
            }

            return WriteResult::Error;
        } else if (rc == 0) {
            errno = 0;
@@ -194,6 +186,7 @@ struct NonblockingFdConnection : public Connection {

        // TODO: Implement a more efficient drop_front?
        write_buffer_.take_front(rc);
        writable_ = write_buffer_.empty();
        if (write_buffer_.empty()) {
            return WriteResult::Completed;
        }
@@ -211,7 +204,12 @@ struct NonblockingFdConnection : public Connection {
        if (!packet->payload.empty()) {
            write_buffer_.append(std::make_unique<IOVector::block_type>(std::move(packet->payload)));
        }
        return DispatchWrites() != WriteResult::Error;

        WriteResult result = DispatchWrites();
        if (result == WriteResult::TryAgain) {
            WakeThread();
        }
        return result != WriteResult::Error;
    }

    std::thread thread_;
+4 −1
Original line number Diff line number Diff line
@@ -108,7 +108,10 @@ struct Block {
        CHECK_EQ(0ULL, capacity_);
        CHECK_EQ(0ULL, size_);
        if (size != 0) {
            data_ = std::make_unique<char[]>(size);
            // This isn't std::make_unique because that's equivalent to `new char[size]()`, which
            // value-initializes the array instead of leaving it uninitialized. As an optimization,
            // call new without parentheses to avoid this costly initialization.
            data_.reset(new char[size]);
            capacity_ = size;
            size_ = size;
        }