drm_hwcomposer: refactor Worker
Make use of standard library mutex and conditions which simplifies use
of condition variables and benefits from things like scoped locking.
Also add tests to make sure it runs as expected.
Change-Id: Iaf92e17e1f6757dce490eddee61f84cb1f953b0c
diff --git a/vsyncworker.cpp b/vsyncworker.cpp
index cc9c96b..3ad16fe 100644
--- a/vsyncworker.cpp
+++ b/vsyncworker.cpp
@@ -48,41 +48,19 @@
return InitWorker();
}
-int VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) {
- int ret = Lock();
- if (ret) {
- ALOGE("Failed to lock vsync worker lock %d\n", ret);
- return ret;
- }
-
+void VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) {
+ Lock();
callback_ = callback;
-
- ret = Unlock();
- if (ret) {
- ALOGE("Failed to unlock vsync worker lock %d\n", ret);
- return ret;
- }
- return 0;
+ Unlock();
}
-int VSyncWorker::VSyncControl(bool enabled) {
- int ret = Lock();
- if (ret) {
- ALOGE("Failed to lock vsync worker lock %d\n", ret);
- return ret;
- }
-
+void VSyncWorker::VSyncControl(bool enabled) {
+ Lock();
enabled_ = enabled;
last_timestamp_ = -1;
- int signal_ret = SignalLocked();
+ Unlock();
- ret = Unlock();
- if (ret) {
- ALOGE("Failed to unlock vsync worker lock %d\n", ret);
- return ret;
- }
-
- return signal_ret;
+ Signal();
}
/*
@@ -135,12 +113,9 @@
}
void VSyncWorker::Routine() {
- int ret = Lock();
- if (ret) {
- ALOGE("Failed to lock worker %d", ret);
- return;
- }
+ int ret;
+ Lock();
if (!enabled_) {
ret = WaitForSignalOrExitLocked();
if (ret == -EINTR) {
@@ -151,11 +126,7 @@
bool enabled = enabled_;
int display = display_;
std::shared_ptr<VsyncCallback> callback(callback_);
-
- ret = Unlock();
- if (ret) {
- ALOGE("Failed to unlock worker %d", ret);
- }
+ Unlock();
if (!enabled)
return;