Delete cuttlefish_thread.h
This is no longer used.
Test: launch_cvd
Change-Id: I324c09e31e6d0e38c8319662ba4e2578506ffde8
diff --git a/common/libs/threads/Android.bp b/common/libs/threads/Android.bp
deleted file mode 100644
index 97b4be8..0000000
--- a/common/libs/threads/Android.bp
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// Copyright (C) 2017 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.
-
-cc_test_host {
- name: "cuttlefish_thread_test",
- srcs: [
- "cuttlefish_thread_test.cpp",
- ],
- shared_libs: [
- "cuttlefish_time",
- "libbase",
- ],
- static_libs: [
- "libgtest_host",
- ],
- cpp_std: "c++17",
- defaults: ["cuttlefish_host_only"],
- test_suites: ["general-tests"],
-}
diff --git a/common/libs/threads/TEST_MAPPING b/common/libs/threads/TEST_MAPPING
deleted file mode 100644
index 87f7884..0000000
--- a/common/libs/threads/TEST_MAPPING
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "presubmit": [
- {
- "name": "cuttlefish_thread_test",
- "host": true
- }
- ]
-}
diff --git a/common/libs/threads/cuttlefish_thread.h b/common/libs/threads/cuttlefish_thread.h
deleted file mode 100644
index 54e5ceb..0000000
--- a/common/libs/threads/cuttlefish_thread.h
+++ /dev/null
@@ -1,169 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 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.
- */
-
-// Concurreny classess for cuttlefish.
-//
-// These more or less mimic the interface of the C++ classes:
-// Mutex is similar to std::mutex
-// ConditionVariable is similar to std::condition_variable
-// LockGuard is similar to std::lock_guard
-//
-// There are some extensions:
-// ScopedThread creates a Thread and joins it when the class is destroyed
-// This comes in handy during unit tests. It should be used cautiously, if
-// at all, in production code because thread creation isn't free.
-
-#include <stdint.h>
-#include <pthread.h>
-#include "common/libs/time/monotonic_time.h"
-
-namespace cvd {
-
-class Mutex {
- friend class ConditionVariable;
-
- public:
- Mutex() {
- pthread_mutex_init(&mutex_, NULL);
- }
-
- ~Mutex() {
- pthread_mutex_destroy(&mutex_);
- }
-
- void Lock() {
- pthread_mutex_lock(&mutex_);
- }
-
- void Unlock() {
- pthread_mutex_unlock(&mutex_);
- }
-
- // TODO(ghartman): Add TryLock if and only if there's a good use case.
-
- protected:
-
- pthread_mutex_t* GetMutex() {
- return &mutex_;
- }
-
- pthread_mutex_t mutex_;
-
- private:
- Mutex(const Mutex&);
- Mutex& operator= (const Mutex&);
-};
-
-class ConditionVariable {
- public:
- explicit ConditionVariable(Mutex* mutex) : mutex_(mutex) {
- pthread_condattr_t attr;
- pthread_condattr_init(&attr);
- pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
- pthread_cond_init(&cond_, &attr);
- pthread_condattr_destroy(&attr);
- }
-
- ~ConditionVariable() {
- pthread_cond_destroy(&cond_);
- }
-
- int NotifyOne() {
- return pthread_cond_signal(&cond_);
- }
-
- int NotifyAll() {
- return pthread_cond_broadcast(&cond_);
- }
-
- int Wait() {
- return pthread_cond_wait(&cond_, mutex_->GetMutex());
- }
-
- int WaitUntil(const cvd::time::MonotonicTimePoint& tp) {
- struct timespec ts;
- tp.ToTimespec(&ts);
- return pthread_cond_timedwait(&cond_, mutex_->GetMutex(), &ts);
- }
-
- protected:
- Mutex* mutex_;
- pthread_cond_t cond_;
-
- private:
- ConditionVariable(const ConditionVariable&);
- ConditionVariable& operator= (const ConditionVariable&);
-};
-
-template <typename M> class LockGuard {
- public:
- explicit LockGuard(M& mutex) : mutex_(mutex) {
- mutex_.Lock();
- }
-
- ~LockGuard() {
- mutex_.Unlock();
- }
-
- private:
- M& mutex_;
-
- LockGuard(const LockGuard&);
- LockGuard& operator= (const LockGuard&);
-};
-
-// Use only in cases where the mutex can't be upgraded to a Mutex.
-template<> class LockGuard<pthread_mutex_t> {
- public:
- explicit LockGuard(pthread_mutex_t& mutex) : mutex_(mutex), unlock_(false) {
- unlock_ = (pthread_mutex_lock(&mutex_) == 0);
- }
-
- ~LockGuard() {
- if (unlock_) {
- pthread_mutex_unlock(&mutex_);
- }
- }
-
- private:
- pthread_mutex_t& mutex_;
- bool unlock_;
-
- LockGuard(const LockGuard&);
- LockGuard& operator= (const LockGuard&);
-};
-
-class ScopedThread {
- public:
- ScopedThread(void* (*start)(void*), void* arg) {
- pthread_create(&thread_, NULL, start, arg);
- }
-
- ~ScopedThread() {
- void* value;
- pthread_join(thread_, &value);
- }
-
- protected:
- pthread_t thread_;
-
- private:
- ScopedThread(const ScopedThread&);
- ScopedThread& operator= (const ScopedThread&);
-};
-
-} // namespace cvd
diff --git a/common/libs/threads/cuttlefish_thread_test.cpp b/common/libs/threads/cuttlefish_thread_test.cpp
deleted file mode 100644
index 5989e9b..0000000
--- a/common/libs/threads/cuttlefish_thread_test.cpp
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (C) 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.
- */
-#include "common/libs/threads/cuttlefish_thread.h"
-
-#include <gtest/gtest.h>
-
-#include <android-base/logging.h>
-#include "common/libs/threads/thunkers.h"
-#include "common/libs/time/monotonic_time.h"
-
-using cvd::ConditionVariable;
-using cvd::Mutex;
-using cvd::ScopedThread;
-using cvd::time::MonotonicTimePoint;
-using cvd::time::Milliseconds;
-
-static const int FINISHED = 100;
-
-static void SleepUntil(const MonotonicTimePoint& in) {
- struct timespec ts;
- in.ToTimespec(&ts);
-#ifdef CLOCK_MONOTONIC_RAW
- // WARNING:
- // While we do have CLOCK_MONOTONIC_RAW, we can't depend on it until:
- // - ALL places relying on MonotonicTimePoint are fixed,
- // - pthread supports pthread_timewait_monotonic.
- // - CLOCK_MONOTONIC_RAW is re-enabled in monotonic_time.h.
- //
- // This is currently observable as a LEGITIMATE problem while running
- // this test. DO NOT revert this to CLOCK_MONOTONIC_RAW until this is
- // fixed everywhere AND this test passes.
- clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
-#else
- clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
-#endif
-}
-
-class MutexTest {
- public:
- MutexTest() : busy_(NULL), stage_(0) {}
-
- void Run() {
- {
- ScopedThread thread_a(cvd::thunk<void, &MutexTest::FastThread>, this);
- ScopedThread thread_b(cvd::thunk<void, &MutexTest::SlowThread>, this);
- }
- LOG(INFO) << "MutexTest: completed at stage "
- << stage_
- << ", result: "
- << ((stage_ == FINISHED) ? "PASSED" : "FAILED");
- }
-
-protected:
- void* FastThread() {
- mutex_.Lock();
- CHECK(busy_ == NULL);
- busy_ = "FastThread";
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- stage_ = 1;
- busy_ = NULL;
- mutex_.Unlock();
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(10));
- mutex_.Lock();
- CHECK(busy_ == NULL);
- busy_ = "FastThread";
- CHECK(stage_ == 2);
- stage_ = FINISHED;
- busy_ = NULL;
- mutex_.Unlock();
- return NULL;
- }
-
- void* SlowThread() {
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(50));
- mutex_.Lock();
- CHECK(busy_== NULL);
- busy_ = "SlowThread";
- CHECK(stage_ == 1);
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- stage_ = 2;
- busy_ = NULL;
- mutex_.Unlock();
- return NULL;
- }
-
- Mutex mutex_;
- const char* busy_;
- int stage_;
-};
-
-class NotifyOneTest {
- public:
- NotifyOneTest() : cond_(&mutex_), signalled_(0) {}
-
- void Run() {
- {
- ScopedThread thread_s(
- cvd::thunk<void, &NotifyOneTest::SignalThread>, this);
- ScopedThread thread_w1(
- cvd::thunk<void, &NotifyOneTest::WaitThread>, this);
- ScopedThread thread_w2(
- cvd::thunk<void, &NotifyOneTest::WaitThread>, this);
- }
- LOG(INFO) << "NotifyOneTest: completed, signalled "
- << signalled_
- << ", result: "
- << ((signalled_ == 2) ? "PASSED" : "FAILED");
- }
-
-protected:
- void* SignalThread() {
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- mutex_.Lock();
- cond_.NotifyOne();
- mutex_.Unlock();
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- mutex_.Lock();
- CHECK(signalled_== 1);
- cond_.NotifyOne();
- mutex_.Unlock();
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- mutex_.Lock();
- CHECK(signalled_ == 2);
- mutex_.Unlock();
- return NULL;
- }
-
- void* WaitThread() {
- mutex_.Lock();
- cond_.Wait();
- signalled_++;
- mutex_.Unlock();
- return NULL;
- }
-
- Mutex mutex_;
- ConditionVariable cond_;
- int signalled_;
-};
-
-class NotifyAllTest {
- public:
- NotifyAllTest() : cond_(&mutex_), signalled_(0) {}
-
- void Run() {
- {
- ScopedThread thread_s(
- cvd::thunk<void, &NotifyAllTest::SignalThread>, this);
- ScopedThread thread_w1(
- cvd::thunk<void, &NotifyAllTest::WaitThread>, this);
- ScopedThread thread_w2(
- cvd::thunk<void, &NotifyAllTest::WaitThread>, this);
- }
- printf("NotifyAllTest: completed, signalled %d (%s)\n",
- signalled_, (signalled_ == 2) ? "PASSED" : "FAILED");
- }
-
-protected:
- void* SignalThread() {
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- mutex_.Lock();
- cond_.NotifyAll();
- mutex_.Unlock();
- SleepUntil(MonotonicTimePoint::Now() + Milliseconds(100));
- mutex_.Lock();
- CHECK(signalled_ == 2);
- mutex_.Unlock();
- return NULL;
- }
-
- void* WaitThread() {
- mutex_.Lock();
- cond_.Wait();
- signalled_++;
- mutex_.Unlock();
- return NULL;
- }
-
- Mutex mutex_;
- ConditionVariable cond_;
- int signalled_;
-};
-
-class WaitUntilTest {
- public:
- WaitUntilTest() : cond_(&mutex_), stage_(0) {}
-
- bool Run() {
- start_ = MonotonicTimePoint::Now();
- {
- ScopedThread thread_s(
- cvd::thunk<void, &WaitUntilTest::SignalThread>, this);
- ScopedThread thread_w2(
- cvd::thunk<void, &WaitUntilTest::WaitThread>, this);
- }
- printf("WaitUntilTest: completed, stage %d (%s)\n",
- stage_, (stage_ == FINISHED) ? "PASSED" : "FAILED");
- return stage_ == FINISHED;
- }
-
-protected:
- void* SignalThread() {
- SleepUntil(start_ + Milliseconds(200));
- mutex_.Lock();
- CHECK(stage_ == 2);
- cond_.NotifyOne();
- stage_ = 3;
- mutex_.Unlock();
- return NULL;
- }
-
- void* WaitThread() {
- mutex_.Lock();
- CHECK(stage_ == 0);
- stage_ = 1;
- cond_.WaitUntil(start_ + Milliseconds(50));
- MonotonicTimePoint current(MonotonicTimePoint::Now());
- CHECK(Milliseconds(current - start_).count() >= 50);
- CHECK(Milliseconds(current - start_).count() <= 100);
- stage_ = 2;
- cond_.WaitUntil(start_ + Milliseconds(1000));
- current = MonotonicTimePoint::Now();
- CHECK(Milliseconds(current - start_).count() <= 500);
- CHECK(stage_ == 3);
- stage_ = FINISHED;
- mutex_.Unlock();
- return NULL;
- }
-
- Mutex mutex_;
- ConditionVariable cond_;
- int stage_;
- MonotonicTimePoint start_;
-};
-
-TEST(ThreadTest, Mutex) {
- MutexTest mt;
- mt.Run();
- NotifyOneTest nt1;
- nt1.Run();
- NotifyAllTest nta;
- nta.Run();
- WaitUntilTest wu;
- bool success = wu.Run();
- EXPECT_TRUE(success);
-}
diff --git a/common/libs/threads/thunkers.h b/common/libs/threads/thunkers.h
deleted file mode 100644
index bb97174..0000000
--- a/common/libs/threads/thunkers.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 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.
- */
-#ifndef CUTTLEFISH_COMMON_COMMON_LIBS_THREADS_THUNKERS_H_
-#define CUTTLEFISH_COMMON_COMMON_LIBS_THREADS_THUNKERS_H_
-
-namespace cvd {
-namespace internal {
-
-template <typename HalType, typename F>
-struct ThunkerImpl;
-
-template <typename HalType, typename Impl, typename R, typename... Args>
-struct ThunkerImpl<HalType, R (Impl::*)(Args...)> {
- template <R (Impl::*MemFn)(Args...)>
- static R call(HalType* in, Args... args) {
- return (reinterpret_cast<Impl*>(in)->*MemFn)(args...);
- }
-};
-
-template <typename HalType, typename Impl, typename R, typename... Args>
-struct ThunkerImpl<HalType, R (Impl::*)(Args...) const> {
- template <R (Impl::*MemFn)(Args...) const>
- static R call(const HalType* in, Args... args) {
- return (reinterpret_cast<const Impl*>(in)->*MemFn)(args...);
- }
-};
-
-template <typename HalType, auto MemFunc>
-struct Thunker {
- static constexpr auto call =
- ThunkerImpl<HalType, decltype(MemFunc)>::template call<MemFunc>;
-};
-
-} // namespace internal
-
-template <typename HalType, auto MemFunc>
-constexpr auto thunk = internal::Thunker<HalType, MemFunc>::call;
-
-} // namespace cvd
-
-#endif
diff --git a/host_package.mk b/host_package.mk
index 8c1d134..945784c 100644
--- a/host_package.mk
+++ b/host_package.mk
@@ -51,7 +51,6 @@
webRTC \
cvd_host_tests := \
- cuttlefish_thread_test \
monotonic_time_test \
cuttlefish_net_tests \