#include "pxr/exec/vdf/executorInterface.h"
#include "pxr/exec/vdf/executorInvalidator.h"
#include "pxr/exec/vdf/executorObserver.h"
#include "pxr/exec/vdf/schedule.h"
#include "pxr/base/trace/trace.h"
PXR_NAMESPACE_OPEN_SCOPE
VdfExecutorInterface::VdfExecutorInterface() :
_stats(NULL),
_executorInvalidationTimestamp(0),
_parentExecutor(NULL),
_interruptionFlag(NULL)
{
}
VdfExecutorInterface::VdfExecutorInterface(
const VdfExecutorInterface *parentExecutor) :
VdfExecutorInterface()
{
SetParentExecutor(parentExecutor);
}
VdfExecutorInterface::~VdfExecutorInterface()
{
std::lock_guard<std::recursive_mutex> lock(_observersLock);
_Observers::iterator it = _observers.begin();
while(it != _observers.end()) {
_Observers::iterator prev = it;
++it;
(*prev)->_OnExecutorDelete(this);
}
}
void
VdfExecutorInterface::Run(
const VdfSchedule &schedule,
VdfExecutorErrorLogger *errorLogger)
{
_Run(schedule, schedule.GetRequest(), errorLogger);
}
void
VdfExecutorInterface::Run(
const VdfSchedule &schedule,
const VdfRequest &request,
VdfExecutorErrorLogger *errorLogger)
{
_Run(schedule, request, errorLogger);
}
void
VdfExecutorInterface::RegisterObserver(
const VdfExecutorObserver *observer) const
{
TRACE_FUNCTION();
std::lock_guard<std::recursive_mutex> lock(_observersLock);
if (TF_VERIFY(_observers.count(observer) <= 0)) {
_observers.insert(observer);
}
}
void
VdfExecutorInterface::UnregisterObserver(
const VdfExecutorObserver *observer) const
{
TRACE_FUNCTION();
std::lock_guard<std::recursive_mutex> lock(_observersLock);
if (TF_VERIFY(_observers.count(observer) > 0)) {
_observers.erase(observer);
}
}
void
VdfExecutorInterface::SetParentExecutor(
const VdfExecutorInterface *parentExecutor)
{
_parentExecutor = parentExecutor;
if (parentExecutor && !GetExecutionStats()) {
SetExecutionStats(parentExecutor->GetExecutionStats());
}
}
void
VdfExecutorInterface::InvalidateValues(
const VdfMaskedOutputVector &invalidationRequest)
{
if (IsEmpty()) {
return;
}
TRACE_FUNCTION();
VdfMaskedOutputVector processedInvalidationRequest;
const bool didPreProcess =
_PreProcessInvalidation(
invalidationRequest,
&processedInvalidationRequest);
if (didPreProcess && processedInvalidationRequest.empty()) {
return;
}
_UpdateInvalidationTimestamp();
if (!_invalidator) {
_invalidator.reset(new VdfExecutorInvalidator(this));
}
_invalidator->Invalidate(didPreProcess
? processedInvalidationRequest
: invalidationRequest);
}
void
VdfExecutorInterface::InvalidateTopologicalState()
{
TRACE_FUNCTION();
if (_invalidator) {
_invalidator->Reset();
}
}
void
VdfExecutorInterface::ClearData()
{
TRACE_FUNCTION();
{
std::lock_guard<std::recursive_mutex> lock(_observersLock);
_Observers::iterator it = _observers.begin();
while(it != _observers.end()) {
_Observers::iterator prev = it;
++it;
(*prev)->_OnExecutorClearData(this);
}
}
_ClearData();
}
void
VdfExecutorInterface::_ClearData()
{
}
void
VdfExecutorInterface::ClearDataForOutput(
const VdfId outputId,
const VdfId nodeId)
{
_ClearDataForOutput(outputId, nodeId);
}
void
VdfExecutorInterface::_ClearDataForOutput(
const VdfId outputId,
const VdfId nodeId)
{
}
PXR_NAMESPACE_CLOSE_SCOPE