no need to lock twice on siblings

This commit is contained in:
itsmattkc
2019-09-13 12:47:59 +10:00
parent 5ab622ba81
commit c48787cdab
5 changed files with 41 additions and 36 deletions
-2
View File
@@ -113,8 +113,6 @@ void MediaInput::Hash(QCryptographicHash *hash, NodeOutput *from, const rational
int64_t timestamp = decoder_->GetTimestampFromTime(time);
qDebug() << "Hashed timestamp" << timestamp;
QByteArray pts_bytes;
pts_bytes.resize(sizeof(int64_t));
memcpy(pts_bytes.data(), &timestamp, sizeof(int64_t));
+8 -12
View File
@@ -136,11 +136,11 @@ rational Node::LastProcessedTime()
{
rational t;
lock_.lock();
Lock();
t = last_processed_time_;
lock_.unlock();
Unlock();
return t;
}
@@ -149,11 +149,11 @@ NodeOutput *Node::LastProcessedOutput()
{
NodeOutput* o;
lock_.lock();
Lock();
o = last_processed_parameter_;
lock_.unlock();
Unlock();
return o;
}
@@ -217,17 +217,13 @@ void GetDependenciesInternal(Node* n, QList<Node*>& list, bool traverse) {
foreach (NodeParam* p, params) {
if (p->type() == NodeParam::kInput) {
QVector<NodeEdgePtr> param_edges = p->edges();
Node* connected = static_cast<NodeInput*>(p)->get_connected_node();
foreach (NodeEdgePtr edge, param_edges) {
Node* connected_node = edge->output()->parent();
if (!list.contains(connected_node)) {
list.append(connected_node);
}
if (connected != nullptr && !list.contains(connected)) {
list.append(connected);
if (traverse) {
GetDependenciesInternal(connected_node, list, traverse);
GetDependenciesInternal(connected, list, traverse);
}
}
}
+2 -2
View File
@@ -368,7 +368,7 @@ void RendererProcessor::CacheNext()
qDebug() << "Caching" << cache_frame.toDouble();
threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true);
threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true, false);
caching_ = true;
}
@@ -460,7 +460,7 @@ void RendererProcessor::ThreadRequestSibling(NodeDependency dep)
{
// Try to queue another thread to run this dep in advance
for (int i=1;i<threads_.size();i++) {
if (threads_.at(i)->Queue(dep, false)) {
if (threads_.at(i)->Queue(dep, false, true)) {
return;
}
}
@@ -36,7 +36,7 @@ RendererProcessThread::RendererProcessThread(RendererProcessor* parent,
}
bool RendererProcessThread::Queue(const NodeDependency& dep, bool wait)
bool RendererProcessThread::Queue(const NodeDependency& dep, bool wait, bool sibling)
{
if (wait) {
// Wait for thread to be available
@@ -47,6 +47,7 @@ bool RendererProcessThread::Queue(const NodeDependency& dep, bool wait)
// We can now change params without the other thread using them
path_ = dep;
sibling_ = sibling;
// Prepare to wait for thread to respond
caller_mutex_.lock();
@@ -92,22 +93,28 @@ void RendererProcessThread::ProcessLoop()
NodeOutput* output_to_process = path_.node();
Node* node_to_process = output_to_process->parent();
node_to_process->Lock();
QList<Node*> all_deps = node_to_process->GetDependencies();
foreach (Node* dep, all_deps) {
dep->Lock();
}
// Check hash
QCryptographicHash hasher(QCryptographicHash::Sha1);
node_to_process->Hash(&hasher, output_to_process, path_.time());
hash_ = hasher.result();
texture_ = nullptr;
bool has_hash = parent_->HasHash(hash_);
bool can_cache = false;
QList<Node*> all_deps;
bool has_hash = false;
bool can_cache = true;
if (!sibling_) {
node_to_process->Lock();
all_deps = node_to_process->GetDependencies();
foreach (Node* dep, all_deps) {
dep->Lock();
}
// Check hash
QCryptographicHash hasher(QCryptographicHash::Sha1);
node_to_process->Hash(&hasher, output_to_process, path_.time());
hash_ = hasher.result();
has_hash = parent_->HasHash(hash_);
can_cache = false;
}
if (!has_hash){
@@ -129,11 +136,13 @@ void RendererProcessThread::ProcessLoop()
}
}
foreach (Node* dep, all_deps) {
dep->Unlock();
}
if (!sibling_) {
foreach (Node* dep, all_deps) {
dep->Unlock();
}
node_to_process->Unlock();
node_to_process->Unlock();
}
if (can_cache) {
// We cached this frame, signal that it will need to be downloaded to disk
@@ -36,7 +36,7 @@ public:
const olive::PixelFormat& format,
const olive::RenderMode& mode);
bool Queue(const NodeDependency &dep, bool wait);
bool Queue(const NodeDependency &dep, bool wait, bool sibling);
public slots:
virtual void Cancel() override;
@@ -62,6 +62,8 @@ private:
QAtomicInt cancelled_;
bool sibling_;
};
using RendererProcessThreadPtr = std::shared_ptr<RendererProcessThread>;