// Copyright (c) 2023 NVIDIA CORPORATION.  All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include "../include/omni/graph/test/ConcurrencyState.h"

#include <OgnTestSerialDatabase.h>

// This is the implementation of the OGN node defined in OgnTestSerial.ogn

namespace omni
{
namespace graph
{
namespace test
{

class OgnTestSerial
{
public:
    static bool compute(OgnTestSerialDatabase& db)
    {
        db.outputs.result() = false;

        // Use a race condition finder to confirm that there is no collision between serial and/or isolated
        // tasks. If we crash in here, that means ParallelScheduler is not respecting scheduling constraints.
        omni::graph::exec::unstable::RaceConditionFinder::Scope detectIssues(getConcurrencyState().raceConditionFinder);

        // Sleep for a while (simulate expensive compute and give time for potential race conditions
        // to arise).
        std::this_thread::sleep_for(std::chrono::milliseconds(100));

        db.outputs.result() = true;

        return true;
    }
};

REGISTER_OGN_NODE()

} // test
} // namespace graph
} // namespace omni
