• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

SendToThread.cpp

Go to the documentation of this file.
00001 #include "SendToThread.h"
00002 #ifdef USE_THREADED_SEND
00003 #include "RakThread.h"
00004 #include "CCRakNetUDT.h"
00005 #include "InternalPacket.h"
00006 #include "GetTime.h"
00007 
00008 int SendToThread::refCount=0;
00009 DataStructures::ThreadsafeAllocatingQueue<SendToThread::SendToThreadBlock> SendToThread::objectQueue;
00010 ThreadPool<SendToThread::SendToThreadBlock*,SendToThread::SendToThreadBlock*> SendToThread::threadPool;
00011 
00012 SendToThread::SendToThreadBlock* SendToWorkerThread(SendToThread::SendToThreadBlock* input, bool *returnOutput, void* perThreadData)
00013 {
00014         (void) perThreadData;
00015         *returnOutput=false;
00016         RakNetTimeUS *mostRecentTime=(RakNetTimeUS *)input->data;
00017         *mostRecentTime=RakNet::GetTimeUS();
00018         SocketLayer::Instance()->SendTo(input->s, input->data, input->dataWriteOffset, input->binaryAddress, input->port, input->remotePortRakNetWasStartedOn_PS3);
00019         SendToThread::objectQueue.Push(input);
00020         return 0;
00021 }
00022 SendToThread::SendToThread()
00023 {
00024 }
00025 SendToThread::~SendToThread()
00026 {
00027 
00028 }
00029 void SendToThread::AddRef(void)
00030 {
00031         if (++refCount==1)
00032         {
00033                 threadPool.StartThreads(1,0);
00034         }
00035 }
00036 void SendToThread::Deref(void)
00037 {
00038         if (refCount>0)
00039         {
00040                 if (--refCount==0)
00041                 {
00042                         threadPool.StopThreads();
00043                         RakAssert(threadPool.NumThreadsWorking()==0);
00044 
00045                         unsigned i;
00046                         SendToThreadBlock* info;
00047                         for (i=0; i < threadPool.InputSize(); i++)
00048                         {
00049                                 info = threadPool.GetInputAtIndex(i);
00050                                 objectQueue.Push(info);
00051                         }
00052                         threadPool.ClearInput();
00053                         objectQueue.Clear(__FILE__, __LINE__);
00054                 }
00055         }
00056 }
00057 SendToThread::SendToThreadBlock* SendToThread::AllocateBlock(void)
00058 {
00059         return objectQueue.PopOrAllocate();
00060 }
00061 void SendToThread::ProcessBlock(SendToThread::SendToThreadBlock* threadedSend)
00062 {
00063         RakAssert(threadedSend->dataWriteOffset>0 && threadedSend->dataWriteOffset<=MAXIMUM_MTU_SIZE-UDP_HEADER_SIZE);
00064         threadPool.AddInput(SendToWorkerThread,threadedSend);
00065 }
00066 #endif

Generated on Thu Sep 30 2010 01:27:28 for RakNet by  doxygen 1.7.1