#include "CLucene/StdHeader.h"
#include "CLucene/LuceneThreads.h"

CL_NS_DEF(util)
//if _LUCENE_DONTIMPLEMENT_THREADMUTEX is defined, then you must implement
//this class in the client application. The mutex can then
//be better customised to the host application.
#if !defined(_LUCENE_DONTIMPLEMENT_THREADMUTEX) && !defined(_CL_DISABLE_MULTITHREADING)
mutex::mutex() { 
	object=0; 
}
mutex::~mutex() {  }
void mutex::lock() {
	while ( object != 0 )
		_sleep(1);

	object = (void*)1; //wait till unlocked, then lock
}
void mutex::unlock() {
	# ifdef _DEBUG
		if ( object == (void*)1 ){
			object = 0;
		} else
			_THROWA( "Mutex wasn't locked");
	# else
		object = 0;
	# endif // _DEBUG
}
#endif

CL_NS_END

