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

Commit 06e0fced authored by Tom Cherry's avatar Tom Cherry
Browse files

liblog: have writers handle their own state

Remove the transport available and open functions since the writers
are able to manage their own state.  Remove the initialization dance
with write_to_log, since it is unneeded once this is removed as well.

Remove the global lock around the close() functions as correct locking
has been added to the writers in a previous change.

Test: logging works, liblog-unit-tests
Change-Id: If7fa11e773763d0b5fcb2e696ad1c88ff4a4cfdf
parent 2a6811b4
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
liblog_sources = [
    "log_event_list.cpp",
    "log_event_write.cpp",
    "logger_lock.cpp",
    "logger_name.cpp",
    "logger_read.cpp",
    "logger_write.cpp",
+0 −4
Original line number Diff line number Diff line
@@ -52,10 +52,6 @@ static void FakeClose();
static int FakeWrite(log_id_t log_id, struct timespec* ts, struct iovec* vec, size_t nr);

struct android_log_transport_write fakeLoggerWrite = {
    .name = "fake",
    .logMask = 0,
    .available = [](log_id_t) { return 0; },
    .open = [] { return 0; },
    .close = FakeClose,
    .write = FakeWrite,
};
+0 −4
Original line number Diff line number Diff line
@@ -45,10 +45,6 @@ static int LogdWrite(log_id_t logId, struct timespec* ts, struct iovec* vec, siz
static void LogdClose();

struct android_log_transport_write logdLoggerWrite = {
    .name = "logd",
    .logMask = 0,
    .available = [](log_id_t) { return 0; },
    .open = [] { return 0; },
    .close = LogdClose,
    .write = LogdWrite,
};
+0 −17
Original line number Diff line number Diff line
@@ -26,20 +26,7 @@

__BEGIN_DECLS

/* Union, sock or fd of zero is not allowed unless static initialized */
union android_log_context_union {
  void* priv;
  atomic_int sock;
  atomic_int fd;
};

struct android_log_transport_write {
  const char* name;                  /* human name to describe the transport */
  unsigned logMask;                  /* mask cache of available() success */
  union android_log_context_union context; /* Initialized by static allocation */

  int (*available)(log_id_t logId); /* Does not cause resources to be taken */
  int (*open)();   /* can be called multiple times, reusing current resources */
  void (*close)(); /* free up resources */
  /* write log to transport, returns number of bytes propagated, or -errno */
  int (*write)(log_id_t logId, struct timespec* ts, struct iovec* vec,
@@ -83,8 +70,4 @@ static inline uid_t __android_log_uid() {
}
#endif

void __android_log_lock();
int __android_log_trylock();
void __android_log_unlock();

__END_DECLS

liblog/logger_lock.cpp

deleted100644 → 0
+0 −53
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007-2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Some OS specific dribs and drabs (locking etc).
 */

#if !defined(_WIN32)
#include <pthread.h>
#endif

#include "logger.h"

#if !defined(_WIN32)
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif

void __android_log_lock() {
#if !defined(_WIN32)
  /*
   * If we trigger a signal handler in the middle of locked activity and the
   * signal handler logs a message, we could get into a deadlock state.
   */
  pthread_mutex_lock(&log_init_lock);
#endif
}

int __android_log_trylock() {
#if !defined(_WIN32)
  return pthread_mutex_trylock(&log_init_lock);
#else
  return 0;
#endif
}

void __android_log_unlock() {
#if !defined(_WIN32)
  pthread_mutex_unlock(&log_init_lock);
#endif
}
Loading