drm_hwcomposer: Remove utils/worker from the project

utils/worker is no longer used and can be removed.

Change-Id: I5fc9bd2b3b8b0375622ee2446044d3b893756b30
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/.ci/Makefile b/.ci/Makefile
index 34ca915..de5196b 100644
--- a/.ci/Makefile
+++ b/.ci/Makefile
@@ -27,8 +27,6 @@
     hwc2_device/DrmHwcTwo.h:COARSE                      \
     hwc2_device/HwcDisplay.cpp:COARSE                   \
     hwc2_device/HwcDisplay.h:COARSE                     \
-    tests/worker_test.cpp:COARSE                        \
-    utils/Worker.h:COARSE                               \
     utils/UniqueFd.h:FINE                               \
     utils/log.h:FINE                                    \
     utils/properties.h:FINE                             \
diff --git a/Android.bp b/Android.bp
index 92e2bc3..3ad060c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -19,25 +19,6 @@
 }
 
 // =====================
-// libdrmhwc_utils.a
-// =====================
-cc_library_static {
-    name: "libdrmhwc_utils",
-
-    srcs: ["utils/Worker.cpp"],
-
-    header_libs: ["drm_hwcomposer_headers"],
-
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-
-    vendor: true,
-
-}
-
-// =====================
 // hwcomposer.drm.so
 // =====================
 cc_defaults {
@@ -54,7 +35,6 @@
         "libutils",
     ],
 
-    static_libs: ["libdrmhwc_utils"],
     header_libs: ["drm_hwcomposer_headers"],
 
     cflags: [
diff --git a/tests/Android.bp b/tests/Android.bp
index e3dc13b..a3c9dd2 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -19,20 +19,6 @@
     ],
 }
 
-cc_test {
-    name: "hwc-drm-tests",
-
-    srcs: ["worker_test.cpp"],
-
-    vendor: true,
-    header_libs: [
-        "drm_hwcomposer_headers",
-        "libhardware_headers",
-    ],
-    static_libs: ["libdrmhwc_utils"],
-    shared_libs: ["hwcomposer.drm"],
-}
-
 // Tool for listening and dumping uevents
 cc_test {
     name: "hwc-drm-uevent-print",
diff --git a/tests/worker_test.cpp b/tests/worker_test.cpp
deleted file mode 100644
index ac0c5fc..0000000
--- a/tests/worker_test.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#include "utils/Worker.h"
-
-#include <gtest/gtest.h>
-#include <hardware/hardware.h>
-
-#include <chrono>
-
-using android::Worker;
-
-struct TestWorker : public Worker {
-  TestWorker() : Worker("test-worker", HAL_PRIORITY_URGENT_DISPLAY){};
-
-  int Init() {
-    return InitWorker();
-  }
-
-  void Routine() override {
-    Lock();
-    if (!enabled_) {
-      auto ret = WaitForSignalOrExitLocked();
-      if (ret == -EINTR) {
-        Unlock();
-        return;
-      }
-      // should only reached here if it was enabled
-      if (!enabled_)
-        printf("Shouldn't reach here while disabled %d %d\n", value, ret);
-    }
-    value++;
-    Unlock();
-  }
-
-  void Control(bool enable) {
-    bool changed = false;
-    Lock();
-    if (enabled_ != enable) {
-      enabled_ = enable;
-      changed = true;
-    }
-    Unlock();
-
-    if (enable && changed)
-      Signal();
-  }
-
-  // NOLINTNEXTLINE: should not be public
-  int value{};
-
- private:
-  bool enabled_{};
-};
-
-struct WorkerTest : public testing::Test {
-  TestWorker worker;
-
-  void SetUp() override {
-    worker.Init();
-  }
-
-  void small_delay() {
-    std::this_thread::sleep_for(std::chrono::milliseconds(20));
-  }
-};
-
-// NOLINTNEXTLINE: required by gtest macros
-TEST_F(WorkerTest, TestWorker) {
-  // already isInitialized so should succeed
-  ASSERT_TRUE(worker.initialized());
-
-  int val = worker.value;
-  small_delay();
-
-  // value shouldn't change when isInitialized
-  ASSERT_EQ(val, worker.value);
-
-  worker.Control(true);
-  small_delay();
-
-  // while locked, value shouldn't be changing
-  worker.Lock();
-  val = worker.value;
-  small_delay();
-  ASSERT_EQ(val, worker.value);
-  worker.Unlock();
-
-  small_delay();
-  // value should be different now
-  ASSERT_NE(val, worker.value);
-
-  worker.Control(false);
-  worker.Lock();
-  val = worker.value;
-  worker.Unlock();
-  small_delay();
-
-  // value should be same
-  ASSERT_EQ(val, worker.value);
-
-  worker.Exit();
-  ASSERT_FALSE(worker.initialized());
-}
-
-// NOLINTNEXTLINE: required by gtest macros
-TEST_F(WorkerTest, ExitWhileRunning) {
-  worker.Control(true);
-
-  std::this_thread::sleep_for(std::chrono::milliseconds(50));
-  worker.Exit();
-}
diff --git a/utils/Worker.cpp b/utils/Worker.cpp
deleted file mode 100644
index e1c7aee..0000000
--- a/utils/Worker.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2015-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 "Worker.h"
-
-#include <sys/prctl.h>
-#include <sys/resource.h>
-
-namespace android {
-
-Worker::Worker(const char *name, int priority)
-    : name_(name), priority_(priority), exit_(false), initialized_(false) {
-}
-
-Worker::~Worker() {
-  Exit();
-}
-
-int Worker::InitWorker() {
-  const std::lock_guard<std::mutex> lk(mutex_);
-  if (initialized())
-    return -EALREADY;
-
-  thread_ = std::make_unique<std::thread>(&Worker::InternalRoutine, this);
-  initialized_ = true;
-  exit_ = false;
-
-  return 0;
-}
-
-void Worker::Exit() {
-  std::unique_lock<std::mutex> lk(mutex_);
-  exit_ = true;
-  if (initialized()) {
-    lk.unlock();
-    cond_.notify_all();
-    thread_->join();
-    initialized_ = false;
-  }
-}
-
-int Worker::WaitForSignalOrExitLocked(int64_t max_nanoseconds) {
-  int ret = 0;
-  if (should_exit())
-    return -EINTR;
-
-  std::unique_lock<std::mutex> lk(mutex_, std::adopt_lock);
-  if (max_nanoseconds < 0) {
-    cond_.wait(lk);
-  } else if (std::cv_status::timeout ==
-             cond_.wait_for(lk, std::chrono::nanoseconds(max_nanoseconds))) {
-    ret = -ETIMEDOUT;
-  }
-
-  // exit takes precedence on timeout
-  if (should_exit())
-    ret = -EINTR;
-
-  // release leaves mutex locked when going out of scope
-  lk.release();
-
-  return ret;
-}
-
-void Worker::InternalRoutine() {
-  setpriority(PRIO_PROCESS, 0, priority_);
-  prctl(PR_SET_NAME, name_.c_str());
-
-  std::unique_lock<std::mutex> lk(mutex_, std::defer_lock);
-
-  while (true) {
-    lk.lock();
-    if (should_exit())
-      return;
-    lk.unlock();
-
-    Routine();
-  }
-}
-}  // namespace android
diff --git a/utils/Worker.h b/utils/Worker.h
deleted file mode 100644
index b524d37..0000000
--- a/utils/Worker.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2015-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.
- */
-
-#pragma once
-
-#include <condition_variable>
-#include <cstdint>
-#include <cstdlib>
-#include <mutex>
-#include <string>
-#include <thread>
-
-namespace android {
-
-class Worker {
- public:
-  void Lock() {
-    mutex_.lock();
-  }
-  void Unlock() {
-    mutex_.unlock();
-  }
-
-  void Signal() {
-    cond_.notify_all();
-  }
-  void Exit();
-
-  bool initialized() const {
-    return initialized_;
-  }
-
-  virtual ~Worker();
-
- protected:
-  Worker(const char *name, int priority);
-
-  int InitWorker();
-  virtual void Routine() = 0;
-
-  /*
-   * Must be called with the lock acquired. max_nanoseconds may be negative to
-   * indicate infinite timeout, otherwise it indicates the maximum time span to
-   * wait for a signal before returning.
-   * Returns -EINTR if interrupted by exit request, or -ETIMEDOUT if timed out
-   */
-  int WaitForSignalOrExitLocked(int64_t max_nanoseconds = -1);
-
-  bool should_exit() const {
-    return exit_;
-  }
-
-  std::mutex mutex_;
-  std::condition_variable cond_;
-
- private:
-  void InternalRoutine();
-
-  std::string name_;
-  int priority_;
-
-  std::unique_ptr<std::thread> thread_;
-  bool exit_;
-  bool initialized_;
-};
-}  // namespace android