SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SendToThread.cpp
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 #include "slikenet/SendToThread.h"
17 #ifdef USE_THREADED_SEND
18 #include "slikenet/thread.h"
19 #include "slikenet/InternalPacket.h"
20 #include "slikenet/GetTime.h"
21
22 #if USE_SLIDING_WINDOW_CONGESTION_CONTROL!=1
23 #include "slikenet/CCRakNetUDT.h"
24 #else
25 #include "slikenet/CCRakNetSlidingWindow.h"
26 #endif
27
28 using namespace SLNet;
29
30 int SendToThread::refCount=0;
31 DataStructures::ThreadsafeAllocatingQueue<SendToThread::SendToThreadBlock> SendToThread::objectQueue;
32 ThreadPool<SendToThread::SendToThreadBlock*,SendToThread::SendToThreadBlock*> SendToThread::threadPool;
33
34 SendToThread::SendToThreadBlock* SendToWorkerThread(SendToThread::SendToThreadBlock* input, bool *returnOutput, void* perThreadData)
35 {
36 (void) perThreadData;
37 *returnOutput=false;
38 // SLNet::TimeUS *mostRecentTime=(SLNet::TimeUS *)input->data;
39 // *mostRecentTime=SLNet::GetTimeUS();
40 SocketLayer::SendTo(input->s, input->data, input->dataWriteOffset, input->systemAddress, _FILE_AND_LINE_);
41 SendToThread::objectQueue.Push(input);
42 return 0;
43 }
44 SendToThread::SendToThread()
45 {
46 }
47 SendToThread::~SendToThread()
48 {
49
50 }
51 void SendToThread::AddRef(void)
52 {
53 if (++refCount==1)
54 {
55 threadPool.StartThreads(1,0);
56 }
57 }
58 void SendToThread::Deref(void)
59 {
60 if (refCount>0)
61 {
62 if (--refCount==0)
63 {
64 threadPool.StopThreads();
65 RakAssert(threadPool.NumThreadsWorking()==0);
66
67 unsigned i;
68 SendToThreadBlock* info;
69 for (i=0; i < threadPool.InputSize(); i++)
70 {
71 info = threadPool.GetInputAtIndex(i);
72 objectQueue.Push(info);
73 }
74 threadPool.ClearInput();
75 objectQueue.Clear(_FILE_AND_LINE_);
76 }
77 }
78 }
79 SendToThread::SendToThreadBlock* SendToThread::AllocateBlock(void)
80 {
81 SendToThread::SendToThreadBlock *b;
82 b=objectQueue.Pop();
83 if (b==0)
84 b=objectQueue.Allocate(_FILE_AND_LINE_);
85 return b;
86 }
87 void SendToThread::ProcessBlock(SendToThread::SendToThreadBlock* threadedSend)
88 {
89 RakAssert(threadedSend->dataWriteOffset>0 && threadedSend->dataWriteOffset<=MAXIMUM_MTU_SIZE-UDP_HEADER_SIZE);
90 threadPool.AddInput(SendToWorkerThread,threadedSend);
91 }
92 #endif