Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Need a suggestion about mouse processing inside threads
Re: Need a suggestion about mouse processing inside threads [message #34819 is a reply to message #34817] Tue, 13 December 2011 18:00 Go to previous messageGo to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Just to explain a bit more my thoughts....

Managing code (class ThreadQueue, which is a direct parent of UppCadDocument:)

// wait for next event and process it
// returns false if shutting down
bool ThreadQueue::WaitAndProcessEvent(void)
{
	// test again if shutting down
	if(Thread::IsShutdownThreads() || exiting)
		return false;
	
	// wait for events
	semaphore.Wait();
	
	// test again if shutting down
	if(Thread::IsShutdownThreads() || exiting)
		return false;
	
	Callback c;
	
	// pops next event
	INTERLOCKED_(mutex) {
		ASSERT(!queue.IsEmpty());
		c = queue.Head();
		queue.DropHead();
	}
	
	// runs the callback
	c.Execute();
	
	// test again if shutting down
	if(Thread::IsShutdownThreads() || exiting)
		return false;
	
	return true;
}

// sends an evento to this thread
void ThreadQueue::SendEvent(Callback c)
{
	INTERLOCKED_(mutex) {
		queue.AddTail(c);
		semaphore.Release();
	}
}



Document loop :

// document command loop
void UppCadDocument::commandLoop(void)
{
	while(WaitAndProcessEvent())
	{
		if(commandLine.HasCommand())
		{
			String cmd = commandLine.GetCommand();
			if(cmd != "<ESC>" && cmd != "")
				SendCommand(cmd);
		}
	}
}


And, for example, a view mouse event handling :

///////////////////////////////////////////////////////////////////////////////////////////////
// middle up - resets pan/3dorbit behaviour
void UppCadView::MiddleUp(Point p, dword keyflags)
{
	SendViewEvent2(uppCadDocument. MiddleUp0, p, keyFlags);
}

void UppCadView::MiddleUp0(Point p, dword keyflags)
{
	isPanning = false;
	PanStartPoint.SetNull();
	
	isRotating = false;
	
} // END UppCadView::MiddleUp()


(SendViewEvent2 is a macro calling uppCadDocument::SendEvent() with correct parameters)
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Multi-Thread Critial Section Problem
Next Topic: Htmls / HtamlTag class and table generation
Goto Forum:
  


Current Time: Thu May 09 09:31:29 CEST 2024

Total time taken to generate the page: 0.01529 seconds