net/commandQueue.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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( (command = _commands.tryPop( )) )
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 return _commands.tryPop();
00080 }
00081
00082 Command* CommandQueue::back() const
00083 {
00084 return _commands.back();
00085 }
00086 }
00087 }
00088