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>
This commit is contained in:
parent
d2cc73874c
commit
14bc764de0
6 changed files with 0 additions and 317 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue