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

Commit 7e4d1db9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "adb: kill adb_mutex_t, adb_cond_t."

parents 7875407b 0cd3ae1c
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <unistd.h>

#include <algorithm>
#include <mutex>
#include <vector>

#include <android-base/logging.h>
@@ -47,8 +48,6 @@
#include <pwd.h>
#endif

ADB_MUTEX_DEFINE(basename_lock);
ADB_MUTEX_DEFINE(dirname_lock);

#if defined(_WIN32)
constexpr char kNullFileName[] = "NUL";
@@ -102,13 +101,15 @@ std::string escape_arg(const std::string& s) {
}

std::string adb_basename(const std::string& path) {
  static std::mutex& basename_lock = *new std::mutex();

  // Copy path because basename may modify the string passed in.
  std::string result(path);

  // Use lock because basename() may write to a process global and return a
  // pointer to that. Note that this locking strategy only works if all other
  // callers to dirname in the process also grab this same lock.
  adb_mutex_lock(&basename_lock);
  // callers to basename in the process also grab this same lock.
  std::lock_guard<std::mutex> lock(basename_lock);

  // Note that if std::string uses copy-on-write strings, &str[0] will cause
  // the copy to be made, so there is no chance of us accidentally writing to
@@ -119,19 +120,19 @@ std::string adb_basename(const std::string& path) {
  // before leaving the lock.
  result.assign(name);

  adb_mutex_unlock(&basename_lock);

  return result;
}

std::string adb_dirname(const std::string& path) {
  static std::mutex& dirname_lock = *new std::mutex();

  // Copy path because dirname may modify the string passed in.
  std::string result(path);

  // Use lock because dirname() may write to a process global and return a
  // pointer to that. Note that this locking strategy only works if all other
  // callers to dirname in the process also grab this same lock.
  adb_mutex_lock(&dirname_lock);
  std::lock_guard<std::mutex> lock(dirname_lock);

  // Note that if std::string uses copy-on-write strings, &str[0] will cause
  // the copy to be made, so there is no chance of us accidentally writing to
@@ -142,8 +143,6 @@ std::string adb_dirname(const std::string& path) {
  // before leaving the lock.
  result.assign(parent);

  adb_mutex_unlock(&dirname_lock);

  return result;
}

+0 −1
Original line number Diff line number Diff line
@@ -170,7 +170,6 @@ int adb_server_main(int is_daemon, const std::string& socket_spec, int ack_reply
}

int main(int argc, char** argv) {
    adb_sysdeps_init();
    adb_trace_init(argv);
    return adb_commandline(argc - 1, const_cast<const char**>(argv + 1));
}

adb/mutex_list.h

deleted100644 → 0
+0 −17
Original line number Diff line number Diff line
/* the list of mutexes used by adb */
/* #ifndef __MUTEX_LIST_H
 * Do not use an include-guard. This file is included once to declare the locks
 * and once in win32 to actually do the runtime initialization.
 */
#ifndef ADB_MUTEX
#error ADB_MUTEX not defined when including this file
#endif
ADB_MUTEX(basename_lock)
ADB_MUTEX(dirname_lock)
ADB_MUTEX(transport_lock)
#if ADB_HOST
ADB_MUTEX(local_transports_lock)
#endif
ADB_MUTEX(usb_lock)

#undef ADB_MUTEX
+0 −46
Original line number Diff line number Diff line
@@ -97,27 +97,6 @@ static __inline__ bool adb_is_separator(char c) {
    return c == '\\' || c == '/';
}

typedef CRITICAL_SECTION          adb_mutex_t;

#define  ADB_MUTEX_DEFINE(x)     adb_mutex_t   x

/* declare all mutexes */
/* For win32, adb_sysdeps_init() will do the mutex runtime initialization. */
#define  ADB_MUTEX(x)   extern adb_mutex_t  x;
#include "mutex_list.h"

extern void  adb_sysdeps_init(void);

static __inline__ void adb_mutex_lock( adb_mutex_t*  lock )
{
    EnterCriticalSection( lock );
}

static __inline__ void  adb_mutex_unlock( adb_mutex_t*  lock )
{
    LeaveCriticalSection( lock );
}

typedef void (*adb_thread_func_t)(void* arg);
typedef HANDLE adb_thread_t;

@@ -476,27 +455,6 @@ static __inline__ bool adb_is_separator(char c) {
    return c == '/';
}

typedef  pthread_mutex_t          adb_mutex_t;

#define  ADB_MUTEX_INITIALIZER    PTHREAD_MUTEX_INITIALIZER
#define  adb_mutex_init           pthread_mutex_init
#define  adb_mutex_lock           pthread_mutex_lock
#define  adb_mutex_unlock         pthread_mutex_unlock
#define  adb_mutex_destroy        pthread_mutex_destroy

#define  ADB_MUTEX_DEFINE(m)      adb_mutex_t   m = PTHREAD_MUTEX_INITIALIZER

#define  adb_cond_t               pthread_cond_t
#define  adb_cond_init            pthread_cond_init
#define  adb_cond_wait            pthread_cond_wait
#define  adb_cond_broadcast       pthread_cond_broadcast
#define  adb_cond_signal          pthread_cond_signal
#define  adb_cond_destroy         pthread_cond_destroy

/* declare all mutexes */
#define  ADB_MUTEX(x)   extern adb_mutex_t  x;
#include "mutex_list.h"

static __inline__ void  close_on_exec(int  fd)
{
    fcntl( fd, F_SETFD, FD_CLOEXEC );
@@ -818,10 +776,6 @@ static __inline__ int adb_mkdir(const std::string& path, int mode)
#undef   mkdir
#define  mkdir  ___xxx_mkdir

static __inline__ void  adb_sysdeps_init(void)
{
}

static __inline__ int adb_is_absolute_host_path(const char* path) {
    return path[0] == '/';
}
+0 −11
Original line number Diff line number Diff line
@@ -269,17 +269,6 @@ TEST(sysdeps_mutex, mutex_smoke) {
    m.unlock();
}

// Our implementation on Windows aborts on double lock.
#if defined(_WIN32)
TEST(sysdeps_mutex, mutex_reentrant_lock) {
    std::mutex &m = *new std::mutex();

    m.lock();
    ASSERT_FALSE(m.try_lock());
    EXPECT_DEATH(m.lock(), "non-recursive mutex locked reentrantly");
}
#endif

TEST(sysdeps_mutex, recursive_mutex_smoke) {
    static std::recursive_mutex &m = *new std::recursive_mutex();

Loading