//class CSemaphore
//{
	var SemArray = new Array();

	function CSemaphore()
	{
		try
		{
			this.Sem = null;
			this.sem_init = declared_sem_init;
			this.sem_wait = declared_sem_wait;
			this.sem_post = declared_sem_post;
			this.sem_getvalue = declared_sem_getvalue;
			this.log = xajax_logStringToFile;
		}
		catch(e) {}
	}
	
	function declared_sem_init(sem_value)
	{
		try
		{
			this.Sem = sem_value;
		}
		catch(e) {this.log("CSemaphore::sem_init\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
	function declared_sem_wait(function_call)
	{
		try
		{
			if(this.Sem <= 0)
			{
				var thisObj = this;
				window.setTimeout(function() { thisObj.sem_wait(function_call) }, 100);
			}
			else
			{
				this.Sem--;
				
				if(function_call != null)
					window.setTimeout(function_call(), 100);
			}
		}
		catch(e)
		{
			if(e.message != "useless setTimeout call (missing quotes around argument?)" && e.message != "Ungültiges Argument.")
				this.log("CSemaphore::sem_wait\n" + e.message, "logging/JSExceptionLog.txt");
		}
	}
	
	function declared_sem_post()
	{
		try
		{
			this.Sem++;
		}
		catch(e) {this.log("CSemaphore::sem_post\n" + e.message, "logging/JSExceptionLog.txt");}
	}
	
	function declared_sem_getvalue()
	{
		try
		{
			return this.Sem;
		}
		catch(e) {this.log("CSemaphore::sem_getvalue\n" + e.message, "logging/JSExceptionLog.txt");}
	}
//};
