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

Commit 2983d271 authored by Josh Gao's avatar Josh Gao Committed by Gerrit Code Review
Browse files

Merge "adb: enable -Wthread-safety on linux/darwin."

parents e1e3e203 68f679c3
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -17,11 +17,15 @@ ADB_COMMON_CFLAGS := \
    -Wvla \
    -Wvla \
    -DADB_REVISION='"$(adb_version)"' \
    -DADB_REVISION='"$(adb_version)"' \


ADB_COMMON_linux_CFLAGS := \
ADB_COMMON_posix_CFLAGS := \
    -Wexit-time-destructors \
    -Wexit-time-destructors \
    -Wthread-safety

ADB_COMMON_linux_CFLAGS := \
    $(ADB_COMMON_posix_CFLAGS) \


ADB_COMMON_darwin_CFLAGS := \
ADB_COMMON_darwin_CFLAGS := \
    -Wexit-time-destructors \
    $(ADB_COMMON_posix_CFLAGS) \


# Define windows.h and tchar.h Unicode preprocessor symbols so that
# Define windows.h and tchar.h Unicode preprocessor symbols so that
# CreateFile(), _tfopen(), etc. map to versions that take wchar_t*, breaking the
# CreateFile(), _tfopen(), etc. map to versions that take wchar_t*, breaking the
+0 −49
Original line number Original line Diff line number Diff line
@@ -201,55 +201,6 @@ TEST_F(sysdeps_poll, fd_count) {
    }
    }
}
}


TEST(sysdeps_mutex, mutex_smoke) {
    static std::atomic<bool> finished(false);
    static std::mutex &m = *new std::mutex();
    m.lock();
    ASSERT_FALSE(m.try_lock());
    std::thread thread([]() {
        ASSERT_FALSE(m.try_lock());
        m.lock();
        finished.store(true);
        std::this_thread::sleep_for(200ms);
        m.unlock();
    });

    ASSERT_FALSE(finished.load());
    std::this_thread::sleep_for(100ms);
    ASSERT_FALSE(finished.load());
    m.unlock();
    std::this_thread::sleep_for(100ms);
    m.lock();
    ASSERT_TRUE(finished.load());
    m.unlock();

    thread.join();
}

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

    m.lock();
    ASSERT_TRUE(m.try_lock());
    m.unlock();

    std::thread thread([]() {
        ASSERT_FALSE(m.try_lock());
        m.lock();
        std::this_thread::sleep_for(500ms);
        m.unlock();
    });

    std::this_thread::sleep_for(100ms);
    m.unlock();
    std::this_thread::sleep_for(100ms);
    ASSERT_FALSE(m.try_lock());
    m.lock();
    m.unlock();

    thread.join();
}

TEST(sysdeps_condition_variable, smoke) {
TEST(sysdeps_condition_variable, smoke) {
    static std::mutex &m = *new std::mutex;
    static std::mutex &m = *new std::mutex;
    static std::condition_variable &cond = *new std::condition_variable;
    static std::condition_variable &cond = *new std::condition_variable;