00001 00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #include "commandQueue.h" 00019 00020 #include "messagePump.h" 00021 00022 namespace eq 00023 { 00024 CommandQueue::CommandQueue() 00025 : _messagePump( 0 ) 00026 { 00027 } 00028 00029 CommandQueue::~CommandQueue() 00030 { 00031 EQASSERT( !_messagePump ); 00032 delete _messagePump; 00033 _messagePump = 0; 00034 } 00035 00036 void CommandQueue::push(net::Command& inCommand) 00037 { 00038 net::CommandQueue::push(inCommand); 00039 if( _messagePump ) 00040 _messagePump->postWakeup(); 00041 } 00042 00043 void CommandQueue::pushFront(net::Command& inCommand) 00044 { 00045 net::CommandQueue::pushFront(inCommand); 00046 if( _messagePump ) 00047 _messagePump->postWakeup(); 00048 } 00049 00050 void CommandQueue::wakeup() 00051 { 00052 net::CommandQueue::wakeup(); 00053 if( _messagePump ) 00054 _messagePump->postWakeup(); 00055 } 00056 00057 net::Command* CommandQueue::pop() 00058 { 00059 while( true ) 00060 { 00061 if( _messagePump ) 00062 _messagePump->dispatchAll(); // non-blocking 00063 00064 // Poll for a command 00065 if( !isEmpty( )) 00066 return net::CommandQueue::pop(); 00067 00068 if( _messagePump ) 00069 _messagePump->dispatchOne(); // blocking - push will send wakeup 00070 else 00071 return net::CommandQueue::pop(); 00072 } 00073 } 00074 00075 net::Command* CommandQueue::tryPop() 00076 { 00077 if( _messagePump ) 00078 _messagePump->dispatchAll(); // non-blocking 00079 00080 return net::CommandQueue::tryPop(); 00081 } 00082 00083 void CommandQueue::flush() 00084 { 00085 if( _messagePump ) 00086 _messagePump->dispatchDone(); 00087 00088 net::CommandQueue::flush(); 00089 } 00090 00091 }
0.9.1 by
1.6.1