linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #01802
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2214: Various small changes
Merge authors:
Jacek Sieka (arnetheduck)
------------------------------------------------------------
revno: 2214 [merge]
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: trunk
timestamp: Sat 2010-08-28 11:19:45 +0800
message:
Various small changes
modified:
SConstruct
dcpp/AdcHub.cpp
dcpp/AdcHub.h
dcpp/Client.cpp
dcpp/Client.h
dcpp/ClientManager.cpp
dcpp/ClientManager.h
dcpp/ConnectionManager.cpp
dcpp/ConnectionManager.h
dcpp/CriticalSection.h
dcpp/DownloadManager.cpp
dcpp/DownloadManager.h
dcpp/FinishedManager.cpp
dcpp/HashManager.cpp
dcpp/HashManager.h
dcpp/NmdcHub.cpp
dcpp/NmdcHub.h
dcpp/QueueManager.cpp
dcpp/QueueManager.h
dcpp/ShareManager.cpp
dcpp/ShareManager.h
dcpp/Socket.cpp
dcpp/Speaker.h
dcpp/ThrottleManager.cpp
dcpp/ThrottleManager.h
dcpp/TimerManager.cpp
dcpp/TimerManager.h
dcpp/UploadManager.cpp
dcpp/UploadManager.h
dcpp/WindowManager.cpp
win32/HashProgressDlg.cpp
win32/HashProgressDlg.h
win32/StatsFrame.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'SConstruct'
--- SConstruct 2010-07-10 14:36:48 +0000
+++ SConstruct 2010-08-26 05:46:32 +0000
@@ -52,13 +52,13 @@
}
msvc_defs = {
- 'common' : ['_REENTRANT'],
+ 'common' : ['_REENTRANT', 'BOOST_USE_WINDOWS_H'],
'debug' : ['_DEBUG', '_HAS_ITERATOR_DEBUGGING=0', '_SECURE_SCL=0'],
'release' : ['NDEBUG']
}
gcc_defs = {
- 'common' : ['_REENTRANT'],
+ 'common' : ['_REENTRANT', 'BOOST_USE_WINDOWS_H'],
'debug' : ['_DEBUG'],
'release' : ['NDEBUG']
}
=== modified file 'dcpp/AdcHub.cpp'
--- dcpp/AdcHub.cpp 2010-06-30 14:40:00 +0000
+++ dcpp/AdcHub.cpp 2010-08-27 13:47:33 +0000
@@ -951,7 +951,7 @@
Client::on(f, aLine);
}
-void AdcHub::on(Second s, uint32_t aTick) throw() {
+void AdcHub::on(Second s, uint64_t aTick) throw() {
Client::on(s, aTick);
if(state == STATE_NORMAL && (aTick > (getLastActivity() + 120*1000))) {
send("\n", 1);
=== modified file 'dcpp/AdcHub.h'
--- dcpp/AdcHub.h 2010-07-10 14:36:48 +0000
+++ dcpp/AdcHub.h 2010-08-27 13:47:33 +0000
@@ -123,7 +123,7 @@
virtual void on(Line, const string& aLine) throw();
virtual void on(Failed, const string& aLine) throw();
- virtual void on(Second, uint32_t aTick) throw();
+ virtual void on(Second, uint64_t aTick) throw();
};
=== modified file 'dcpp/Client.cpp'
--- dcpp/Client.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/Client.cpp 2010-08-27 13:47:33 +0000
@@ -202,7 +202,7 @@
updateActivity();
}
-void Client::on(Second, uint32_t aTick) throw() {
+void Client::on(Second, uint64_t aTick) throw() {
if(state == STATE_DISCONNECTED && getAutoReconnect() && (aTick > (getLastActivity() + getReconnDelay() * 1000)) ) {
// Try to reconnect...
connect();
=== modified file 'dcpp/Client.h'
--- dcpp/Client.h 2010-06-30 14:40:00 +0000
+++ dcpp/Client.h 2010-08-27 13:47:33 +0000
@@ -143,7 +143,7 @@
virtual string checkNick(const string& nick) = 0;
// TimerManagerListener
- virtual void on(Second, uint32_t aTick) throw();
+ virtual void on(Second, uint64_t aTick) throw();
// BufferedSocketListener
virtual void on(Connecting) throw() { fire(ClientListener::Connecting(), this); }
virtual void on(Connected) throw();
=== modified file 'dcpp/ClientManager.cpp'
--- dcpp/ClientManager.cpp 2010-07-06 15:07:11 +0000
+++ dcpp/ClientManager.cpp 2010-08-27 13:47:33 +0000
@@ -517,7 +517,7 @@
}
}
-void ClientManager::on(TimerManagerListener::Minute, uint32_t /* aTick */) throw() {
+void ClientManager::on(TimerManagerListener::Minute, uint64_t /* aTick */) throw() {
Lock l(cs);
// Collect some garbage...
=== modified file 'dcpp/ClientManager.h'
--- dcpp/ClientManager.h 2010-06-30 14:40:00 +0000
+++ dcpp/ClientManager.h 2010-08-27 13:47:33 +0000
@@ -102,8 +102,8 @@
bool isActive() { return SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_FIREWALL_PASSIVE; }
- void lock() throw() { cs.enter(); }
- void unlock() throw() { cs.leave(); }
+ void lock() throw() { cs.lock(); }
+ void unlock() throw() { cs.unlock(); }
Client::List& getClients() { return clients; }
@@ -179,7 +179,7 @@
int aFileType, const string& aString) throw();
virtual void on(AdcSearch, Client* c, const AdcCommand& adc, const CID& from) throw();
// TimerManagerListener
- virtual void on(TimerManagerListener::Minute, uint32_t aTick) throw();
+ virtual void on(TimerManagerListener::Minute, uint64_t aTick) throw();
};
} // namespace dcpp
=== modified file 'dcpp/ConnectionManager.cpp'
--- dcpp/ConnectionManager.cpp 2010-08-23 16:04:27 +0000
+++ dcpp/ConnectionManager.cpp 2010-08-27 13:47:33 +0000
@@ -138,7 +138,7 @@
userConnections.erase(remove(userConnections.begin(), userConnections.end(), aConn), userConnections.end());
}
-void ConnectionManager::on(TimerManagerListener::Second, uint32_t aTick) throw() {
+void ConnectionManager::on(TimerManagerListener::Second, uint64_t aTick) throw() {
UserList passiveUsers;
ConnectionQueueItem::List removed;
@@ -214,7 +214,7 @@
}
}
-void ConnectionManager::on(TimerManagerListener::Minute, uint32_t aTick) throw() {
+void ConnectionManager::on(TimerManagerListener::Minute, uint64_t aTick) throw() {
Lock l(cs);
for(UserConnectionList::iterator j = userConnections.begin(); j != userConnections.end(); ++j) {
=== modified file 'dcpp/ConnectionManager.h'
--- dcpp/ConnectionManager.h 2010-06-12 17:59:19 +0000
+++ dcpp/ConnectionManager.h 2010-08-27 13:47:33 +0000
@@ -192,8 +192,8 @@
virtual void on(AdcCommand::STA, UserConnection*, const AdcCommand&) throw();
// TimerManagerListener
- virtual void on(TimerManagerListener::Second, uint32_t aTick) throw();
- virtual void on(TimerManagerListener::Minute, uint32_t aTick) throw();
+ virtual void on(TimerManagerListener::Second, uint64_t aTick) throw();
+ virtual void on(TimerManagerListener::Minute, uint64_t aTick) throw();
};
=== modified file 'dcpp/CriticalSection.h'
--- dcpp/CriticalSection.h 2010-04-23 18:32:11 +0000
+++ dcpp/CriticalSection.h 2010-08-26 05:46:32 +0000
@@ -16,108 +16,19 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(CRITICAL_SECTION_H)
-#define CRITICAL_SECTION_H
+#ifndef DCPLUSPLUS_DCPP_CRITICAL_SECTION_H
+#define DCPLUSPLUS_DCPP_CRITICAL_SECTION_H
-#include "Thread.h"
+#include <boost/thread/recursive_mutex.hpp>
namespace dcpp {
-class CriticalSection
-{
-#ifdef _WIN32
-public:
- void enter() throw() {
- EnterCriticalSection(&cs);
- dcdrun(counter++);
- }
- void leave() throw() {
- dcassert(--counter >= 0);
- LeaveCriticalSection(&cs);
- }
- CriticalSection() throw() {
- dcdrun(counter = 0;);
- InitializeCriticalSection(&cs);
- }
- ~CriticalSection() throw() {
- dcassert(counter==0);
- DeleteCriticalSection(&cs);
- }
-private:
- dcdrun(long counter);
- CRITICAL_SECTION cs;
-#else
-public:
- CriticalSection() throw() {
- pthread_mutexattr_init(&ma);
- pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&mtx, &ma);
- }
- ~CriticalSection() throw() {
- pthread_mutex_destroy(&mtx);
- pthread_mutexattr_destroy(&ma);
- }
- void enter() throw() { pthread_mutex_lock(&mtx); }
- void leave() throw() { pthread_mutex_unlock(&mtx); }
- pthread_mutex_t& getMutex() { return mtx; }
-private:
- pthread_mutex_t mtx;
- pthread_mutexattr_t ma;
-#endif
- CriticalSection(const CriticalSection&);
- CriticalSection& operator=(const CriticalSection&);
-};
-
-/**
- * A fast, non-recursive and unfair implementation of the Critical Section.
- * It is meant to be used in situations where the risk for lock conflict is very low,
- * i e locks that are held for a very short time. The lock is _not_ recursive, i e if
- * the same thread will try to grab the lock it'll hang in a never-ending loop. The lock
- * is not fair, i e the first to try to enter a locked lock is not guaranteed to be the
- * first to get it when it's freed...
- */
-class FastCriticalSection {
-public:
-#ifdef _WIN32
- FastCriticalSection() : state(0) { }
-
- void enter() {
- while(Thread::safeExchange(state, 1) == 1) {
- Thread::sleep(1);
- }
- }
- void leave() {
- Thread::safeDec(state);
- }
-private:
- volatile long state;
-
-#else
- // We have to use a pthread (nonrecursive) mutex, didn't find any test_and_set on linux...
- FastCriticalSection() {
- static pthread_mutex_t fastmtx = PTHREAD_MUTEX_INITIALIZER;
- mtx = fastmtx;
- }
- ~FastCriticalSection() { pthread_mutex_destroy(&mtx); }
- void enter() { pthread_mutex_lock(&mtx); }
- void leave() { pthread_mutex_unlock(&mtx); }
-private:
- pthread_mutex_t mtx;
-#endif
-};
-
-template<class T>
-class LockBase {
-public:
- LockBase(T& aCs) throw() : cs(aCs) { cs.enter(); }
- ~LockBase() throw() { cs.leave(); }
-private:
- LockBase& operator=(const LockBase&);
- T& cs;
-};
-typedef LockBase<CriticalSection> Lock;
-typedef LockBase<FastCriticalSection> FastLock;
+// TODO: At some point (probably when c++0x support is solid enough), remove these old names
+typedef boost::recursive_mutex CriticalSection;
+typedef boost::detail::spinlock FastCriticalSection;
+typedef boost::lock_guard<boost::recursive_mutex> Lock;
+typedef boost::lock_guard<boost::detail::spinlock> FastLock;
} // namespace dcpp
-#endif // !defined(CRITICAL_SECTION_H)
+#endif // DCPLUSPLUS_DCPP_CRITICAL_SECTION_H
=== modified file 'dcpp/DownloadManager.cpp'
--- dcpp/DownloadManager.cpp 2010-06-12 17:59:19 +0000
+++ dcpp/DownloadManager.cpp 2010-08-27 13:47:33 +0000
@@ -60,7 +60,7 @@
}
}
-void DownloadManager::on(TimerManagerListener::Second, uint32_t aTick) throw() {
+void DownloadManager::on(TimerManagerListener::Second, uint64_t aTick) throw() {
typedef vector<pair<string, UserPtr> > TargetList;
TargetList dropTargets;
@@ -84,8 +84,8 @@
if((uint32_t)(aTick / 1000) % SETTING(AUTODROP_INTERVAL) == 0) {
for(DownloadList::iterator i = downloads.begin(); i != downloads.end(); ++i) {
Download* d = *i;
- uint64_t timeElapsed = GET_TICK() - d->getStart();
- uint64_t timeInactive = GET_TICK() - d->getUserConnection().getLastActivity();
+ uint64_t timeElapsed = aTick - d->getStart();
+ uint64_t timeInactive = aTick - d->getUserConnection().getLastActivity();
uint64_t bytesDownloaded = d->getPos();
bool timeElapsedOk = timeElapsed >= (uint32_t)SETTING(AUTODROP_ELAPSED) * 1000;
bool timeInactiveOk = timeInactive <= (uint32_t)SETTING(AUTODROP_INACTIVITY) * 1000;
=== modified file 'dcpp/DownloadManager.h'
--- dcpp/DownloadManager.h 2010-06-12 17:59:19 +0000
+++ dcpp/DownloadManager.h 2010-08-27 13:47:33 +0000
@@ -98,7 +98,7 @@
virtual void on(AdcCommand::STA, UserConnection*, const AdcCommand&) throw();
// TimerManagerListener
- virtual void on(TimerManagerListener::Second, uint32_t aTick) throw();
+ virtual void on(TimerManagerListener::Second, uint64_t aTick) throw();
};
} // namespace dcpp
=== modified file 'dcpp/FinishedManager.cpp'
--- dcpp/FinishedManager.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/FinishedManager.cpp 2010-08-27 13:47:33 +0000
@@ -45,7 +45,7 @@
}
void FinishedManager::lockLists() {
- cs.enter();
+ cs.lock();
}
const FinishedManager::MapByFile& FinishedManager::getMapByFile(bool upload) const {
@@ -57,7 +57,7 @@
}
void FinishedManager::unLockLists() {
- cs.leave();
+ cs.unlock();
}
void FinishedManager::remove(bool upload, const string& file) {
@@ -111,7 +111,7 @@
string file = t->getPath();
const HintedUser& user = t->getHintedUser();
- int64_t milliSeconds = GET_TICK() - t->getStart();
+ uint64_t milliSeconds = GET_TICK() - t->getStart();
time_t time = GET_TIME();
int64_t size = 0;
=== modified file 'dcpp/HashManager.cpp'
--- dcpp/HashManager.cpp 2010-04-18 04:32:43 +0000
+++ dcpp/HashManager.cpp 2010-08-27 13:47:33 +0000
@@ -556,7 +556,7 @@
bool ok = false;
- uint32_t lastRead = GET_TICK();
+ uint64_t lastRead = GET_TICK();
if (!::ReadFile(h, hbuf, BUF_SIZE, &hn, &over)) {
if (GetLastError() == ERROR_HANDLE_EOF) {
hn = 0;
@@ -580,10 +580,10 @@
// Start a new overlapped read
ResetEvent(over.hEvent);
if (SETTING(MAX_HASH_SPEED) > 0) {
- uint32_t now = GET_TICK();
- uint32_t minTime = hn * 1000LL / (SETTING(MAX_HASH_SPEED) * 1024LL * 1024LL);
+ uint64_t now = GET_TICK();
+ uint64_t minTime = hn * 1000LL / (SETTING(MAX_HASH_SPEED) * 1024LL * 1024LL);
if (lastRead + minTime > now) {
- uint32_t diff = now - lastRead;
+ uint64_t diff = now - lastRead;
Thread::sleep(minTime - diff);
}
lastRead = lastRead + minTime;
@@ -797,7 +797,7 @@
try {
File f(fname, File::READ, File::OPEN);
int64_t bs = max(TigerTree::calcBlockSize(f.getSize(), 10), MIN_BLOCK_SIZE);
- uint32_t start = GET_TICK();
+ uint64_t start = GET_TICK();
uint32_t timestamp = f.getLastModified();
TigerTree slowTTH(bs);
TigerTree* tth = &slowTTH;
@@ -818,13 +818,13 @@
#endif
tth = &slowTTH;
crc32 = CRC32Filter();
- uint32_t lastRead = GET_TICK();
+ uint64_t lastRead = GET_TICK();
do {
size_t bufSize = BUF_SIZE;
if(SETTING(MAX_HASH_SPEED)> 0) {
- uint32_t now = GET_TICK();
- uint32_t minTime = n * 1000LL / (SETTING(MAX_HASH_SPEED) * 1024LL * 1024LL);
+ uint64_t now = GET_TICK();
+ uint64_t minTime = n * 1000LL / (SETTING(MAX_HASH_SPEED) * 1024LL * 1024LL);
if(lastRead + minTime> now) {
Thread::sleep(minTime - (now - lastRead));
}
@@ -851,7 +851,7 @@
f.close();
tth->finalize();
- uint32_t end = GET_TICK();
+ uint64_t end = GET_TICK();
int64_t speed = 0;
if(end> start) {
speed = size * _LL(1000) / (end - start);
=== modified file 'dcpp/HashManager.h'
--- dcpp/HashManager.h 2010-02-11 21:44:13 +0000
+++ dcpp/HashManager.h 2010-08-27 13:47:33 +0000
@@ -235,7 +235,7 @@
store.rebuild();
}
- virtual void on(TimerManagerListener::Minute, uint32_t) throw() {
+ virtual void on(TimerManagerListener::Minute, uint64_t) throw() {
Lock l(cs);
store.save();
}
=== modified file 'dcpp/NmdcHub.cpp'
--- dcpp/NmdcHub.cpp 2010-06-30 14:40:00 +0000
+++ dcpp/NmdcHub.cpp 2010-08-27 13:47:33 +0000
@@ -968,7 +968,7 @@
Client::on(Failed(), aLine);
}
-void NmdcHub::on(Second, uint32_t aTick) throw() {
+void NmdcHub::on(Second, uint64_t aTick) throw() {
Client::on(Second(), aTick);
if(state == STATE_NORMAL && (aTick > (getLastActivity() + 120*1000)) ) {
@@ -976,7 +976,7 @@
}
}
-void NmdcHub::on(Minute, uint32_t aTick) throw() {
+void NmdcHub::on(Minute, uint64_t aTick) throw() {
if(aTick > (lastProtectedIPsUpdate + 24*3600*1000)) {
protectedIPs.clear();
=== modified file 'dcpp/NmdcHub.h'
--- dcpp/NmdcHub.h 2010-06-30 14:40:00 +0000
+++ dcpp/NmdcHub.h 2010-08-27 13:47:33 +0000
@@ -83,7 +83,7 @@
FloodMap seekers;
FloodMap flooders;
- uint32_t lastProtectedIPsUpdate;
+ uint64_t lastProtectedIPsUpdate;
StringList protectedIPs;
NmdcHub(const string& aHubURL);
@@ -120,8 +120,8 @@
virtual string checkNick(const string& aNick);
// TimerManagerListener
- virtual void on(Second, uint32_t aTick) throw();
- virtual void on(Minute, uint32_t aTick) throw();
+ virtual void on(Second, uint64_t aTick) throw();
+ virtual void on(Minute, uint64_t aTick) throw();
virtual void on(Connected) throw();
virtual void on(Line, const string& l) throw();
=== modified file 'dcpp/QueueManager.cpp'
--- dcpp/QueueManager.cpp 2010-07-10 14:36:48 +0000
+++ dcpp/QueueManager.cpp 2010-08-27 13:47:33 +0000
@@ -519,7 +519,7 @@
return false;
}
-void QueueManager::on(TimerManagerListener::Minute, uint32_t aTick) throw() {
+void QueueManager::on(TimerManagerListener::Minute, uint64_t aTick) throw() {
string fn;
string searchString;
bool online = false;
@@ -1701,7 +1701,7 @@
}
}
-void QueueManager::on(TimerManagerListener::Second, uint32_t aTick) throw() {
+void QueueManager::on(TimerManagerListener::Second, uint64_t aTick) throw() {
if(dirty && ((lastSave + 10000) < aTick)) {
saveQueue();
}
=== modified file 'dcpp/QueueManager.h'
--- dcpp/QueueManager.h 2010-02-11 21:44:13 +0000
+++ dcpp/QueueManager.h 2010-08-27 13:47:33 +0000
@@ -102,8 +102,8 @@
void setPriority(const string& aTarget, QueueItem::Priority p) throw();
void getTargets(const TTHValue& tth, StringList& sl);
- QueueItem::StringMap& lockQueue() throw() { cs.enter(); return fileQueue.getQueue(); } ;
- void unlockQueue() throw() { cs.leave(); }
+ QueueItem::StringMap& lockQueue() throw() { cs.lock(); return fileQueue.getQueue(); } ;
+ void unlockQueue() throw() { cs.unlock(); }
Download* getDownload(UserConnection& aSource, bool supportsTrees) throw();
void putDownload(Download* aDownload, bool finished) throw();
@@ -237,7 +237,7 @@
/** The queue needs to be saved */
bool dirty;
/** Next search */
- uint32_t nextSearch;
+ uint64_t nextSearch;
/** File lists not to delete */
StringList protectedFileLists;
/** Sanity check for the target filename */
@@ -258,8 +258,8 @@
string getListPath(const HintedUser& user);
// TimerManagerListener
- virtual void on(TimerManagerListener::Second, uint32_t aTick) throw();
- virtual void on(TimerManagerListener::Minute, uint32_t aTick) throw();
+ virtual void on(TimerManagerListener::Second, uint64_t aTick) throw();
+ virtual void on(TimerManagerListener::Minute, uint64_t aTick) throw();
// SearchManagerListener
virtual void on(SearchManagerListener::SR, const SearchResultPtr&) throw();
=== modified file 'dcpp/ShareManager.cpp'
--- dcpp/ShareManager.cpp 2010-07-10 14:36:48 +0000
+++ dcpp/ShareManager.cpp 2010-08-27 13:47:33 +0000
@@ -1392,7 +1392,7 @@
}
}
-void ShareManager::on(TimerManagerListener::Minute, uint32_t tick) throw() {
+void ShareManager::on(TimerManagerListener::Minute, uint64_t tick) throw() {
if(SETTING(AUTO_REFRESH_TIME) > 0) {
if(lastFullUpdate + SETTING(AUTO_REFRESH_TIME) * 60 * 1000 <= tick) {
refresh(true, true);
=== modified file 'dcpp/ShareManager.h'
--- dcpp/ShareManager.h 2010-07-10 14:36:48 +0000
+++ dcpp/ShareManager.h 2010-08-27 13:47:33 +0000
@@ -309,7 +309,7 @@
}
// TimerManagerListener
- virtual void on(TimerManagerListener::Minute, uint32_t tick) throw();
+ virtual void on(TimerManagerListener::Minute, uint64_t tick) throw();
void load(SimpleXML& aXml);
void save(SimpleXML& aXml);
=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp 2010-07-10 15:49:05 +0000
+++ dcpp/Socket.cpp 2010-08-27 13:47:33 +0000
@@ -152,7 +152,7 @@
}
namespace {
- inline uint32_t timeLeft(uint32_t start, uint32_t timeout) {
+ inline uint64_t timeLeft(uint64_t start, uint64_t timeout) {
if(timeout == 0) {
return 0;
}
=== modified file 'dcpp/Speaker.h'
--- dcpp/Speaker.h 2010-07-10 16:37:01 +0000
+++ dcpp/Speaker.h 2010-08-27 14:57:49 +0000
@@ -31,68 +31,12 @@
Speaker() throw() { }
virtual ~Speaker() throw() { }
- /// @todo simplify when we have variadic templates
-
- template<typename T0>
- void fire(T0&& type) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type));
- }
- }
-
- template<typename T0, typename T1>
- void fire(T0&& type, T1&& p1) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1));
- }
- }
-
- template<typename T0, typename T1, typename T2>
- void fire(T0&& type, T1&& p1, T2&& p2) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1), forward<T2>(p2));
- }
- }
-
- template<typename T0, typename T1, typename T2, typename T3>
- void fire(T0&& type, T1&& p1, T2&& p2, T3&& p3) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1), forward<T2>(p2), forward<T3>(p3));
- }
- }
-
- template<typename T0, typename T1, typename T2, typename T3, typename T4>
- void fire(T0&& type, T1&& p1, T2&& p2, T3&& p3, T4&& p4) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1), forward<T2>(p2), forward<T3>(p3), forward<T4>(p4));
- }
- }
-
- template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
- void fire(T0&& type, T1&& p1, T2&& p2, T3&& p3, T4&& p4, T5&& p5) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1), forward<T2>(p2), forward<T3>(p3), forward<T4>(p4), forward<T5>(p5));
- }
- }
-
- template<typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
- void fire(T0&& type, T1&& p1, T2&& p2, T3&& p3, T4&& p4, T5&& p5, T6&& p6) throw() {
- Lock l(listenerCS);
- tmp = listeners;
- for(auto i = tmp.begin(); i != tmp.end(); ++i) {
- (*i)->on(forward<T0>(type), forward<T1>(p1), forward<T2>(p2), forward<T3>(p3), forward<T4>(p4), forward<T5>(p5), forward<T6>(p6));
+ template<typename... T>
+ void fire(T&&... type) throw() {
+ Lock l(listenerCS);
+ tmp = listeners;
+ for(auto i = tmp.begin(); i != tmp.end(); ++i) {
+ (*i)->on(forward<T>(type)...);
}
}
=== modified file 'dcpp/ThrottleManager.cpp'
--- dcpp/ThrottleManager.cpp 2010-02-25 18:56:41 +0000
+++ dcpp/ThrottleManager.cpp 2010-08-27 13:47:33 +0000
@@ -178,13 +178,13 @@
void ThrottleManager::shutdown() {
Lock l(stateCS);
if (activeWaiter != -1) {
- waitCS[activeWaiter].leave();
+ waitCS[activeWaiter].unlock();
activeWaiter = -1;
}
}
// TimerManagerListener
-void ThrottleManager::on(TimerManagerListener::Second, uint32_t /* aTick */) throw()
+void ThrottleManager::on(TimerManagerListener::Second, uint64_t /* aTick */) throw()
{
int newSlots = SettingsManager::getInstance()->get(getCurSetting(SettingsManager::SLOTS));
if(newSlots != SETTING(SLOTS)) {
@@ -197,7 +197,7 @@
if (activeWaiter == -1)
// This will create slight weirdness for the read/write calls between
// here and the first activeWaiter-toggle below.
- waitCS[activeWaiter = 0].enter();
+ waitCS[activeWaiter = 0].lock();
}
int downLimit = getDownLimit();
@@ -227,9 +227,9 @@
Lock l(stateCS);
dcassert(activeWaiter == 0 || activeWaiter == 1);
- waitCS[1-activeWaiter].enter();
+ waitCS[1-activeWaiter].lock();
Thread::safeExchange(activeWaiter, 1-activeWaiter);
- waitCS[1-activeWaiter].leave();
+ waitCS[1-activeWaiter].unlock();
}
}
=== modified file 'dcpp/ThrottleManager.h'
--- dcpp/ThrottleManager.h 2010-01-09 10:11:57 +0000
+++ dcpp/ThrottleManager.h 2010-08-27 13:47:33 +0000
@@ -80,8 +80,8 @@
void waitToken();
// TimerManagerListener
- void on(TimerManagerListener::Second, uint32_t /* aTick */) throw();
+ void on(TimerManagerListener::Second, uint64_t /* aTick */) throw();
};
} // namespace dcpp
-#endif // _THROTTLEMANAGER_H
\ No newline at end of file
+#endif // _THROTTLEMANAGER_H
=== modified file 'dcpp/TimerManager.cpp'
--- dcpp/TimerManager.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/TimerManager.cpp 2010-08-27 13:47:33 +0000
@@ -21,52 +21,54 @@
#include "TimerManager.h"
+#include <boost/date_time/posix_time/ptime.hpp>
+
namespace dcpp {
-#ifdef _WIN32
-DWORD TimerManager::lastTick = 0;
-uint32_t TimerManager::cycles = 0;
-FastCriticalSection TimerManager::cs;
-#else
-timeval TimerManager::tv;
-#endif
+using namespace boost::posix_time;
+
+TimerManager::TimerManager() {
+ // This mutex will be unlocked only upon shutdown
+ mtx.lock();
+}
+
+TimerManager::~TimerManager() throw() {
+ dcassert(listeners.size() == 0);
+}
+
+void TimerManager::shutdown() {
+ mtx.unlock();
+ join();
+}
int TimerManager::run() {
int nextMin = 0;
- uint64_t x = getTick();
- uint64_t nextTick = x + 1000;
-
- while(!s.wait(nextTick > x ? nextTick - x : 0)) {
- uint32_t z = getTick();
- nextTick = z + 1000;
- fire(TimerManagerListener::Second(), z);
+ ptime now = microsec_clock::universal_time();
+ ptime nextSecond = now + seconds(1);
+
+ while(!mtx.timed_lock(nextSecond)) {
+ uint64_t t = getTick();
+ now = microsec_clock::universal_time();
+ nextSecond += seconds(1);
+ if(nextSecond < now) {
+ nextSecond = now;
+ }
+
+ fire(TimerManagerListener::Second(), t);
if(nextMin++ >= 60) {
- fire(TimerManagerListener::Minute(), z);
+ fire(TimerManagerListener::Minute(), t);
nextMin = 0;
}
- x = getTick();
}
+ dcdebug("TimerManager done\n");
return 0;
}
uint64_t TimerManager::getTick() {
-#ifdef _WIN32
- FastLock l(cs);
-
- DWORD tick = ::GetTickCount();
- if(tick < lastTick) {
- cycles++;
- }
- lastTick = tick;
- return static_cast<uint64_t>(cycles) * (static_cast<uint64_t>(std::numeric_limits<DWORD>::max()) + 1) + tick;
-#else
- timeval tv2;
- gettimeofday(&tv2, NULL);
- /// @todo check conversions to use uint64_t fully
- return static_cast<uint64_t>(((tv2.tv_sec - tv.tv_sec) * 1000 ) + ( (tv2.tv_usec - tv.tv_usec) / 1000));
-#endif
+ static ptime start = microsec_clock::universal_time();
+ return (microsec_clock::universal_time() - start).total_milliseconds();
}
} // namespace dcpp
=== modified file 'dcpp/TimerManager.h'
--- dcpp/TimerManager.h 2010-02-11 21:44:13 +0000
+++ dcpp/TimerManager.h 2010-08-27 13:47:33 +0000
@@ -16,14 +16,15 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#if !defined(TIMER_MANAGER_H)
-#define TIMER_MANAGER_H
+#ifndef DCPLUSPLUS_DCPP_TIMER_MANAGER_H
+#define DCPLUSPLUS_DCPP_TIMER_MANAGER_H
#include "Thread.h"
-#include "Semaphore.h"
#include "Speaker.h"
#include "Singleton.h"
+#include <boost/thread/mutex.hpp>
+
#ifndef _WIN32
#include <sys/time.h>
#endif
@@ -38,46 +39,25 @@
typedef X<0> Second;
typedef X<1> Minute;
- // We expect everyone to implement this...
- virtual void on(Second, uint32_t) throw() { }
- virtual void on(Minute, uint32_t) throw() { }
+ virtual void on(Second, uint64_t) throw() { }
+ virtual void on(Minute, uint64_t) throw() { }
};
class TimerManager : public Speaker<TimerManagerListener>, public Singleton<TimerManager>, public Thread
{
public:
- void shutdown() {
- s.signal();
- join();
- }
+ void shutdown();
static time_t getTime() { return (time_t)time(NULL); }
static uint64_t getTick();
private:
-
- Semaphore s;
-
friend class Singleton<TimerManager>;
- TimerManager() {
-#ifndef _WIN32
- gettimeofday(&tv, NULL);
-#endif
- }
+ boost::timed_mutex mtx;
- virtual ~TimerManager() throw() {
- dcassert(listeners.empty());
- shutdown();
- }
+ TimerManager();
+ virtual ~TimerManager() throw();
virtual int run();
-
-#ifdef _WIN32
- static DWORD lastTick;
- static uint32_t cycles;
- static FastCriticalSection cs;
-#else
- static timeval tv;
-#endif
};
#define GET_TICK() TimerManager::getTick()
@@ -85,4 +65,4 @@
} // namespace dcpp
-#endif // !defined(TIMER_MANAGER_H)
+#endif // DCPLUSPLUS_DCPP_TIMER_MANAGER_H
=== modified file 'dcpp/UploadManager.cpp'
--- dcpp/UploadManager.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/UploadManager.cpp 2010-08-27 13:47:33 +0000
@@ -414,7 +414,7 @@
}
}
-void UploadManager::on(TimerManagerListener::Minute, uint32_t /* aTick */) throw() {
+void UploadManager::on(TimerManagerListener::Minute, uint64_t /* aTick */) throw() {
UserList disconnects;
{
Lock l(cs);
@@ -488,7 +488,7 @@
}
// TimerManagerListener
-void UploadManager::on(TimerManagerListener::Second, uint32_t) throw() {
+void UploadManager::on(TimerManagerListener::Second, uint64_t) throw() {
Lock l(cs);
UploadList ticks;
=== modified file 'dcpp/UploadManager.h'
--- dcpp/UploadManager.h 2010-02-11 21:44:13 +0000
+++ dcpp/UploadManager.h 2010-08-27 13:47:33 +0000
@@ -101,8 +101,8 @@
virtual void on(ClientManagerListener::UserDisconnected, const UserPtr& aUser) throw();
// TimerManagerListener
- virtual void on(Second, uint32_t aTick) throw();
- virtual void on(Minute, uint32_t aTick) throw();
+ virtual void on(Second, uint64_t aTick) throw();
+ virtual void on(Minute, uint64_t aTick) throw();
// UserConnectionListener
virtual void on(BytesSent, UserConnection*, size_t, size_t) throw();
=== modified file 'dcpp/WindowManager.cpp'
--- dcpp/WindowManager.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/WindowManager.cpp 2010-08-26 05:46:32 +0000
@@ -54,11 +54,11 @@
}
void WindowManager::lock() {
- cs.enter();
+ cs.lock();
}
void WindowManager::unlock() {
- cs.leave();
+ cs.unlock();
}
void WindowManager::add(const string& id, const StringMap& params) {
=== modified file 'win32/HashProgressDlg.cpp'
--- win32/HashProgressDlg.cpp 2010-07-10 14:36:48 +0000
+++ win32/HashProgressDlg.cpp 2010-08-27 13:47:33 +0000
@@ -107,7 +107,7 @@
string path;
int64_t bytes = 0;
size_t files = 0;
- uint32_t tick = GET_TICK();
+ uint64_t tick = GET_TICK();
HashManager::getInstance()->getStats(path, bytes, files);
if(bytes > startBytes)
=== modified file 'win32/HashProgressDlg.h'
--- win32/HashProgressDlg.h 2010-02-11 21:44:13 +0000
+++ win32/HashProgressDlg.h 2010-08-27 13:47:33 +0000
@@ -38,7 +38,7 @@
bool autoClose;
int64_t startBytes;
size_t startFiles;
- uint32_t startTime;
+ uint64_t startTime;
bool handleInitDialog();
=== modified file 'win32/StatsFrame.cpp'
--- win32/StatsFrame.cpp 2010-07-10 14:36:48 +0000
+++ win32/StatsFrame.cpp 2010-08-27 13:47:33 +0000
@@ -136,13 +136,13 @@
}
bool StatsFrame::eachSecond() {
- uint32_t tick = GET_TICK();
- uint32_t tdiff = tick - lastTick;
+ uint64_t tick = GET_TICK();
+ uint64_t tdiff = tick - lastTick;
if(tdiff == 0)
return true;
- uint32_t scrollms = (tdiff + scrollTick)*PIX_PER_SEC;
- uint32_t scroll = scrollms / 1000;
+ uint64_t scrollms = (tdiff + scrollTick)*PIX_PER_SEC;
+ uint64_t scroll = scrollms / 1000;
if(scroll == 0)
return true;