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

Commit cef47bb3 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: start cleaning up LogReaderThread

1) We can use real member functions with std::thread and
   std::function, so use those instead of the 'me' pointer.
2) Don't expose member variables directly.
3) Rename and document member variables, since all of their references
   are being touched anyway.

Test: logging unit tests
Change-Id: I9a357a3ea8691433d58687c95356b984b83e9c36
parent 320f5968
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -277,7 +277,7 @@ int LogAudit::logPrint(const char* fmt, ...) {
                  : LOGGER_ENTRY_MAX_PAYLOAD;
    size_t message_len = str_len + sizeof(android_log_event_string_t);

    log_mask_t notify = 0;
    unsigned int notify = 0;

    if (events) {  // begin scope for event buffer
        uint32_t buffer[(message_len + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
+12 −13
Original line number Diff line number Diff line
@@ -584,9 +584,9 @@ void LogBuffer::kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows
        // A misbehaving or slow reader has its connection
        // dropped if we hit too much memory pressure.
        android::prdebug("Kicking blocked reader, pid %d, from LogBuffer::kickMe()\n",
                         me->mClient->getPid());
                         me->client()->getPid());
        me->release_Locked();
    } else if (me->mTimeout.tv_sec || me->mTimeout.tv_nsec) {
    } else if (me->timeout().tv_sec || me->timeout().tv_nsec) {
        // Allow a blocked WRAP timeout reader to
        // trigger and start reporting the log data.
        me->triggerReader_Locked();
@@ -594,7 +594,7 @@ void LogBuffer::kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows
        // tell slow reader to skip entries to catch up
        android::prdebug(
                "Skipping %lu entries from slow reader, pid %d, from LogBuffer::kickMe()\n",
                pruneRows, me->mClient->getPid());
                pruneRows, me->client()->getPid());
        me->triggerSkip_Locked(id, pruneRows);
    }
}
@@ -657,10 +657,9 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
    LastLogTimes::iterator times = mTimes.begin();
    while (times != mTimes.end()) {
        LogReaderThread* entry = times->get();
        if (entry->isWatching(id) &&
            (!oldest || (oldest->mStart > entry->mStart) ||
             ((oldest->mStart == entry->mStart) &&
              (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec)))) {
        if (entry->IsWatching(id) && (!oldest || oldest->start() > entry->start() ||
                                      (oldest->start() == entry->start() &&
                                       (entry->timeout().tv_sec || entry->timeout().tv_nsec)))) {
            oldest = entry;
        }
        times++;
@@ -681,7 +680,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
                continue;
            }

            if (oldest && oldest->mStart <= element->getSequence()) {
            if (oldest && oldest->start() <= element->getSequence()) {
                busy = true;
                kickMe(oldest, id, pruneRows);
                break;
@@ -772,7 +771,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
        while (it != mLogElements.end()) {
            LogBufferElement* element = *it;

            if (oldest && oldest->mStart <= element->getSequence()) {
            if (oldest && oldest->start() <= element->getSequence()) {
                busy = true;
                // Do not let chatty eliding trigger any reader mitigation
                break;
@@ -914,7 +913,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
            continue;
        }

        if (oldest && oldest->mStart <= element->getSequence()) {
        if (oldest && oldest->start() <= element->getSequence()) {
            busy = true;
            if (!whitelist) kickMe(oldest, id, pruneRows);
            break;
@@ -942,7 +941,7 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
                continue;
            }

            if (oldest && oldest->mStart <= element->getSequence()) {
            if (oldest && oldest->start() <= element->getSequence()) {
                busy = true;
                kickMe(oldest, id, pruneRows);
                break;
@@ -981,10 +980,10 @@ bool LogBuffer::clear(log_id_t id, uid_t uid) {
                while (times != mTimes.end()) {
                    LogReaderThread* entry = times->get();
                    // Killer punch
                    if (entry->isWatching(id)) {
                    if (entry->IsWatching(id)) {
                        android::prdebug(
                                "Kicking blocked reader, pid %d, from LogBuffer::clear()\n",
                                entry->mClient->getPid());
                                entry->client()->getPid());
                        entry->release_Locked();
                    }
                    times++;
+1 −1
Original line number Diff line number Diff line
@@ -819,7 +819,7 @@ int LogKlog::log(const char* buf, ssize_t len) {

    // notify readers
    if (rc > 0) {
        reader->notifyNewLog(static_cast<log_mask_t>(1 << LOG_ID_KERNEL));
        reader->notifyNewLog(static_cast<unsigned int>(1 << LOG_ID_KERNEL));
    }

    return rc;
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
    int res = logbuf->log(logId, header->realtime, cred->uid, cred->pid, header->tid, msg,
                          ((size_t)n <= UINT16_MAX) ? (uint16_t)n : UINT16_MAX);
    if (res > 0) {
        reader->notifyNewLog(static_cast<log_mask_t>(1 << logId));
        reader->notifyNewLog(static_cast<unsigned int>(1 << logId));
    }

    return true;
+5 −5
Original line number Diff line number Diff line
@@ -39,15 +39,15 @@ LogReader::LogReader(LogBuffer* logbuf)

// When we are notified a new log entry is available, inform
// listening sockets who are watching this entry's log id.
void LogReader::notifyNewLog(log_mask_t log_mask) {
void LogReader::notifyNewLog(unsigned int log_mask) {
    LastLogTimes& times = mLogbuf.mTimes;

    LogReaderThread::wrlock();
    for (const auto& entry : times) {
        if (!entry->isWatchingMultiple(log_mask)) {
        if (!entry->IsWatchingMultiple(log_mask)) {
            continue;
        }
        if (entry->mTimeout.tv_sec || entry->mTimeout.tv_nsec) {
        if (entry->timeout().tv_sec || entry->timeout().tv_nsec) {
            continue;
        }
        entry->triggerReader_Locked();
@@ -76,7 +76,7 @@ bool LogReader::onDataAvailable(SocketClient* cli) {
    // send another.
    LogReaderThread::wrlock();
    for (const auto& entry : mLogbuf.mTimes) {
        if (entry->mClient == cli) {
        if (entry->client() == cli) {
            entry->release_Locked();
            LogReaderThread::unlock();
            return false;
@@ -227,7 +227,7 @@ void LogReader::doSocketDelete(SocketClient* cli) {
    LastLogTimes::iterator it = times.begin();
    while (it != times.end()) {
        LogReaderThread* entry = it->get();
        if (entry->mClient == cli) {
        if (entry->client() == cli) {
            entry->release_Locked();
            break;
        }
Loading