#ifndef __KERNEL_DISPATCHER_H
#define __KERNEL_DISPATCHER_H

#include <sys/types.h>
#include <cpp/Uncopyable.h>
#include <List.h>
#include <Kernel/Spinlock.h>
#include <Kernel/Thread.h>

namespace OS {
namespace Kernel {

class Dispatcher : private Uncopyable {
public:
	Dispatcher();
	Dispatcher(bool initialSignal);
	~Dispatcher();

	status_t Wait(Thread *t, bool unsignalAfter = false, time_t timeout = INFINITE_TIME);
	status_t WaitOn(bool unsignalAfter = false, time_t timeout = INFINITE_TIME) { 
		return Wait(Thread::GetCurrent(), unsignalAfter, timeout); 
	}
	void Pulse(bool signalIfEmpty = false);
	void Signal();
	void Unsignal();

	int Count() { return mQueue.Count(); }

private:
	bool mSignalled;
	Spinlock mLock;
	List<Thread> mQueue;
};

}} // namespace OS::Kernel

#endif

