/*
  Copyright (c) 2008-2012  John Lee (j.y.lee@yeah.net)
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

  * Neither the name of the copyright holders nor the names of
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __LIGHTWEIGHT_OBJECT_ORENTED_KERNEL_H
#error "Include <look.h> instead of this file."
#else	// __LIGHTWEIGHT_OBJECT_ORENTED_KERNEL_H

#ifndef __LOOK_RR_INTERFACE
#define __LOOK_RR_INTERFACE

#pragma interface

#ifndef LOOK_SCHEDULING
#define LOOK_SCHEDULING	rr
#define LOOK_SCHEDULING_RR
#endif	// LOOK_SCHEDULING

#define LOOK_SCHEDULING_ROUNDROBIN

#include <co>

namespace look {
	namespace rr {
		using co::flag_t;

		class task_t : public co::task_t {
		protected:
			__INLINE task_t();
		};

		class sched_t : public co::sched_t {
		public:
			__INLINE sched_t(uintptr_t timeslice);
			uintptr_t set_timeslice(uintptr_t timeslice);
			__INLINE task_t& get_current_task();

#ifndef __DOXYGEN__
		protected:					// virtual
			void on_signal(void* addr, uintptr_t signal);
			base::task_t* dispatch();

		protected:
			timer_t timer;
			uintptr_t timeslice;
#endif	// __DOXYGEN__

		};
	}
}
#else	// __LOOK_RR_INTERFACE
#ifndef __LOOK_RR_INLINE
#define __LOOK_RR_INLINE

#include <co>

__INLINE look::rr::task_t::task_t()
{
}

__INLINE look::rr::sched_t::sched_t(uintptr_t timeslice)
: timer(*this)
{
	this->timeslice = timeslice;
}

__INLINE look::rr::task_t& look::rr::sched_t::get_current_task()
{
	return static_cast<task_t&>(co::sched_t::get_current_task());
}
#endif	// __LOOK_RR_INLINE
#endif	// __LOOK_RR_INTERFACE
#endif	// __LIGHTWEIGHT_OBJECT_ORENTED_KERNEL_H
