//----------------------------------------------------------------------
// Copyright (C) 2006-2007 Electronic Arts    
//----------------------------------------------------------------------

#ifndef JOB_UTIL_SERIAL_FOR_EACH_H
#define JOB_UTIL_SERIAL_FOR_EACH_H

#include "EABase/eabase.h"

//----------------------------------------------------------------------
#if ! defined EA_PLATFORM_PS3_SPU
    #include "job_util/parallel_for_each.h"

namespace EA { 
    namespace Jobs {

//----------------------------------------------------------------------
class SerialForEach
{
public:
    EA_FORCE_INLINE SerialForEach(JobScheduler& jobScheduler, const EntryPoint& entryPoint, const ForEachDesc& forEachDesc) :
        mParallelForEach(jobScheduler, entryPoint, forEachDesc, 1, FOR_EACH_DIVISION_EVEN)
    {}

    EA_FORCE_INLINE SerialForEach() :
        mParallelForEach()
    {}

    EA_FORCE_INLINE void SetJobScheduler(JobScheduler & jobScheduler) { mParallelForEach.SetJobScheduler(jobScheduler); }
    EA_FORCE_INLINE JobScheduler & GetJobScheduler() const { return mParallelForEach.GetJobScheduler(); }

    EA_FORCE_INLINE void SetEntryPoint(EntryPoint const& entryPoint) { mParallelForEach.SetEntryPoint(entryPoint); }
    EA_FORCE_INLINE EntryPoint GetEntryPoint() const { return mParallelForEach.GetEntryPoint(); }

    EA_FORCE_INLINE void SetDesc(ForEachDesc const & forEachDesc) { mParallelForEach.SetDesc(forEachDesc); }
    EA_FORCE_INLINE void SetDescUnmanaged(ForEachDesc * forEachDesc) { mParallelForEach.SetDescUnmanaged(forEachDesc); }

    EA_FORCE_INLINE void SetParam2(uintptr_t p) { mParallelForEach.SetParam2(p); }
    EA_FORCE_INLINE uintptr_t GetParam2() const { return mParallelForEach.GetParam2(); }

    EA_FORCE_INLINE void SetParam3(uintptr_t p) { mParallelForEach.SetParam3(p); }
    EA_FORCE_INLINE uintptr_t GetParam3() const { return mParallelForEach.GetParam3(); }

    EA_FORCE_INLINE void SetAllowSleepOn(bool b) { mParallelForEach.SetAllowSleepOn(b); }
    EA_FORCE_INLINE bool GetAllowSleepOn() const { return mParallelForEach.GetAllowSleepOn(); }

    EA_FORCE_INLINE void Run() { mParallelForEach.Run(); }
    EA_FORCE_INLINE void AddJobInstances() { mParallelForEach.AddJobInstances(); }

    EA_FORCE_INLINE void WaitOn(WaitOnCallback* waitOnCallback = 0, void* callbackContext = 0, int sleepInMs = -1) const
    {
        mParallelForEach.WaitOn(waitOnCallback, callbackContext, sleepInMs);
    }
    EA_FORCE_INLINE void SleepOn() const { mParallelForEach.SleepOn(); }
    EA_FORCE_INLINE bool IsDone() const { return mParallelForEach.IsDone(); }

    EA_FORCE_INLINE JobInstanceHandle GetBeginJobInstanceHandle() const { return mParallelForEach.GetBeginJobInstanceHandle(); }
    EA_FORCE_INLINE JobInstanceHandle GetEndJobInstanceHandle() const { return mParallelForEach.GetEndJobInstanceHandle(); }

private:
    ParallelForEach mParallelForEach;

    SerialForEach& operator = (const SerialForEach&);
    SerialForEach(const SerialForEach&);
};

}}

#endif

#endif
