Fixed problem in the CFile write_safe concept
[amule.git] / src / UploadBandwidthThrottler.h
blob812e324cab11048120a8383175d6d2847ef87ea5
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2005-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef UPLOADBANDWIDTHTHROTTLER_H
27 #define UPLOADBANDWIDTHTHROTTLER_H
30 #include <wx/thread.h>
32 #include <deque>
34 #include "Types.h"
36 class ThrottledControlSocket;
37 class ThrottledFileSocket;
39 class UploadBandwidthThrottler : public wxThread
41 public:
42 UploadBandwidthThrottler();
43 ~UploadBandwidthThrottler();
45 uint64 GetNumberOfSentBytesSinceLastCallAndReset();
46 uint64 GetNumberOfSentBytesOverheadSinceLastCallAndReset();
48 void AddToStandardList(uint32 index, ThrottledFileSocket* socket);
49 bool RemoveFromStandardList(ThrottledFileSocket* socket);
51 void QueueForSendingControlPacket(ThrottledControlSocket* socket, bool hasSent = false);
52 void RemoveFromAllQueues(ThrottledControlSocket* socket);
53 void RemoveFromAllQueues(ThrottledFileSocket* socket);
55 void EndThread();
56 private:
57 void DoRemoveFromAllQueues(ThrottledControlSocket* socket);
58 bool RemoveFromStandardListNoLock(ThrottledFileSocket* socket);
60 void* Entry();
62 bool m_doRun;
65 wxMutex m_sendLocker;
66 wxMutex m_tempQueueLocker;
68 typedef std::deque<ThrottledControlSocket*> SocketQueue;
70 // a queue for all the sockets that want to have Send() called on them.
71 SocketQueue m_ControlQueue_list;
72 // a queue for all the sockets that want to have Send() called on them.
73 SocketQueue m_ControlQueueFirst_list;
74 // sockets that wants to enter m_ControlQueue_list
75 SocketQueue m_TempControlQueue_list;
76 // sockets that wants to enter m_ControlQueue_list and has been able to send before
77 SocketQueue m_TempControlQueueFirst_list;
80 typedef std::deque<ThrottledFileSocket*> FileSocketQueue;
81 // sockets that have upload slots. Ordered so the most prioritized socket is first
82 FileSocketQueue m_StandardOrder_list;
84 uint64 m_SentBytesSinceLastCall;
85 uint64 m_SentBytesSinceLastCallOverhead;
89 #endif
90 // File_checked_for_headers