Hello,

As I said this morning, the Timer class is the cause of the infamous thread_resource_error exception (see ticket #1416): when I reproduced the bug in gdb, I found out that the timer responsible for saving the user profile had 360 threads in it.

This patch fixes the problem by only using one thread in the timer. I have been using it for a while now without problem on my Linux box. I am going to test it on MacOSX and Windows too, but I would really appreciate if you could review the patch.

Aurélien
Index: libs/owutil/thread/Timer.h
===================================================================
--- libs/owutil/thread/Timer.h	(révision 11026)
+++ libs/owutil/thread/Timer.h	(copie de travail)
@@ -73,12 +73,11 @@
 
 private:
 
-	/** List of private threads. */
-	List<PrivateThread *> _threadList;
+	PrivateThread* _thread;
 
-	void timeoutEventHandler(PrivateThread & thread);
+	void timeoutEventHandler();
 
-	void lastTimeoutEventHandler(PrivateThread & thread);
+	void lastTimeoutEventHandler();
 };
 
 #endif	//OWTIMER_H
Index: libs/owutil/thread/src/Timer.cpp
===================================================================
--- libs/owutil/thread/src/Timer.cpp	(révision 11026)
+++ libs/owutil/thread/src/Timer.cpp	(copie de travail)
@@ -138,38 +138,34 @@
 }
 
 Timer::Timer() {
+	_thread = new PrivateThread();
+	_thread->timeoutEvent += boost::bind(&Timer::timeoutEventHandler, this);
+	_thread->lastTimeoutEvent += boost::bind(&Timer::lastTimeoutEventHandler, this);
 }
 
 Timer::~Timer() {
 	stop();
-	for (register unsigned i = 0; i != _threadList.size(); i++) {
-		OWSAFE_DELETE(_threadList[i]);
-	}
-	_threadList.clear();
+	OWSAFE_DELETE(_thread);
 }
 
 void Timer::start(unsigned firstTime, unsigned timeout, unsigned nbShots) {
-	PrivateThread * thread = new PrivateThread();
-	thread->timeoutEvent += boost::bind(&Timer::timeoutEventHandler, this, _1);
-	thread->lastTimeoutEvent += boost::bind(&Timer::lastTimeoutEventHandler, this, _1);
-	thread->start(firstTime, timeout, nbShots);
-	_threadList += thread;
+	_thread->stop();
+	_thread->join();
+	_thread->start(firstTime, timeout, nbShots);
 }
 
 void Timer::stop() {
-	for (register unsigned i = 0; i != _threadList.size(); i++) {
-		_threadList[i]->stop();
-	}
+	_thread->stop();
 }
 
-void Timer::timeoutEventHandler(PrivateThread & thread) {
-	if (!thread.isStopped()) {
+void Timer::timeoutEventHandler() {
+	if (!_thread->isStopped()) {
 		timeoutEvent(*this);
 	}
 }
 
-void Timer::lastTimeoutEventHandler(PrivateThread & thread) {
-	if (!thread.isStopped()) {
+void Timer::lastTimeoutEventHandler() {
+	if (!_thread->isStopped()) {
 		lastTimeoutEvent(*this);
 	}
 }
_______________________________________________
Wengophone-devel mailing list
[email protected]
http://dev.openwengo.com/mailman/listinfo/wengophone-devel

Reply via email to