net/commandQueue.cpp

00001 
00002 /* Copyright (c) 2005-2010, 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 <pthread.h>
00019 #include "commandQueue.h"
00020 
00021 #include "command.h"
00022 #include "node.h"
00023 #include "packets.h"
00024 
00025 using namespace std;
00026 
00027 namespace eq
00028 {
00029 namespace net
00030 {
00031 CommandQueue::CommandQueue()
00032 {
00033 }
00034 
00035 CommandQueue::~CommandQueue()
00036 {
00037     flush();
00038 }
00039 
00040 void CommandQueue::flush()
00041 {
00042     if( !isEmpty( ))
00043         EQWARN << "Flushing non-empty command queue" << endl;
00044 
00045     Command* command( 0 );
00046     while( _commands.tryPop( command ))
00047     {
00048         EQWARN << *command << endl;
00049         EQASSERT( command );
00050         command->release();
00051     }
00052 }
00053 
00054 void CommandQueue::push( Command& command )
00055 {
00056     EQASSERT( command.isValid( ));
00057     
00058     command.retain();
00059     _commands.push( &command );
00060 }
00061 
00062 void CommandQueue::pushFront( Command& command )
00063 {
00064     EQASSERT( command.isValid( ));
00065     
00066     command.retain();
00067     _commands.pushFront( &command );
00068 }
00069 
00070 Command* CommandQueue::pop()
00071 {
00072     CHECK_THREAD( _thread );
00073     return _commands.pop();
00074 }
00075 
00076 Command* CommandQueue::tryPop()
00077 {
00078     CHECK_THREAD( _thread );
00079     Command* command = 0;
00080     _commands.tryPop( command );
00081     return command;
00082 }
00083 
00084 }
00085 }
00086 
Generated on Sat Feb 6 12:59:47 2010 for Equalizer 0.9.1 by  doxygen 1.6.1