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();
}
}