zalewa avatar zalewa committed efc2604

- Fixed: The refresh code refactor introduced a cross-threading warning message
on Windows. The message was related to timers and indicated that the problem
might cause further errors.

Comments (0)

Files changed (1)

src/core/refresher.cpp

 	public:
 		MasterClientInfo(MasterClient* pMaster, RefreshingThread* pParent)
 		{
+			pParentThread = pParent;
+			pLastChallengeTimer = NULL;
 			pReceiver = new MasterClientSignalProxy(pMaster);
 			connect(pReceiver, SIGNAL( listUpdated(MasterClient*) ), pParent, SLOT( masterFinishedRefreshing(MasterClient*) ) );
 
 			numOfChallengesSent = 0;
-
-			timeLastChallengeSent.setSingleShot(true);
-			timeLastChallengeSent.setInterval(MASTER_SERVER_TIMEOUT_DELAY);
-			connect(&timeLastChallengeSent, SIGNAL(timeout()), pParent, SLOT(attemptTimeoutMasters()));
 		}
 		~MasterClientInfo()
 		{
 			delete pReceiver;
+			if (pLastChallengeTimer != NULL)
+			{
+				delete pLastChallengeTimer;
+			}
+		}
+		
+		void						fireLastChallengeSentTimer()
+		{
+			// This was previously done with an object of QTimer
+			// instead of a pointer.
+			// Unfortunately on Windows it produced a cross-threading
+			// warning messages saying that timer cannot be started
+			// from a different thread.
+			if (pLastChallengeTimer == NULL)
+			{
+				pLastChallengeTimer = new QTimer();
+			}
+									
+			pLastChallengeTimer->setSingleShot(true);
+			pLastChallengeTimer->setInterval(MASTER_SERVER_TIMEOUT_DELAY);
+			connect(pLastChallengeTimer, SIGNAL(timeout()), 
+				pParentThread, SLOT(attemptTimeoutMasters()));
+		}
+		
+		bool						isLastChallengeTimerActive() const
+		{
+			if (pLastChallengeTimer == NULL)
+			{
+				return false;
+			}
+		
+			return pLastChallengeTimer->isActive();
 		}
 
 		int							numOfChallengesSent;
-		QTimer						timeLastChallengeSent;
 
 	protected:
 		MasterClientSignalProxy*	pReceiver;
+		RefreshingThread*			pParentThread;
+		QTimer*						pLastChallengeTimer;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 	{
 		MasterClientInfo* pMasterInfo = it.value();
 
-		if (!pMasterInfo->timeLastChallengeSent.isActive())
+		if (!pMasterInfo->isLastChallengeTimerActive())
 		{
 			MasterClient* pMaster = it.key();
 			pMaster->timeoutRefresh();
 
 		MasterClientInfo* pMasterInfo = d->registeredMasters[pMaster];
 		++pMasterInfo->numOfChallengesSent;
-		pMasterInfo->timeLastChallengeSent.start();
+		pMasterInfo->fireLastChallengeSentTimer();
 
 		pMaster->refresh();
 		d->unchallengedMasters.remove(pMaster);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.