Robert,
I changed your patch a bit: could you please tell me if the new version
is ok for you?
Thanks,
Raphael.
On 15.04.10 11:45, Raphael Coeffic wrote:
Hi Robert,
Thanks for the patch!
As you pointed out, waiting in an event handler does block the event
queue, which seems obvious. This also means that waiting in an event
handler is not really the way it should be implemented, except for
very few things.
Moreover, Stefan has made some plans to use a threadpool for the
session event loop, instead of having one thread per session. This
increases the performances dramatically when running signaling only
applications. The drawback is that the event loop becomes even more
sensible, as blocking in an event handler will also prevent other
sessions from being processed.
So the crucial question is: how long do you wait there? If it is more
than a few 10s of milliseconds, you might run into troubles once we
have introduced the session threadpool.
With a little bit more explaination, we might be able to discuss a
more asynchronous / scalable solution to your issue.
Cheers
Raphael.
On 14.04.10 15:09, Robert Szokovacs wrote:
Hi,
I started using AmCondition and noticed it didn't wrap
pthread_cond_timedwait(). As I couldn't use UserTimer because I wait in
onInvite() so the timeout events don't get delivered, I added the
functionality to AmCondition. Patch attached.
br
Szo
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev
Index: AmThread.h
===================================================================
--- AmThread.h (revision 1778)
+++ AmThread.h (working copy)
@@ -29,6 +29,9 @@
#define _AmThread_h_
#include <pthread.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
#include <queue>
@@ -151,6 +154,29 @@
}
pthread_mutex_unlock(&m);
}
+
+ /** Waits for the condition to be true or a timeout. */
+ bool wait_for_to(unsigned long usec)
+ {
+ struct timeval now;
+ struct timespec timeout;
+ int retcode = 0;
+ bool ret = false;
+
+ gettimeofday(&now, NULL);
+ timeout.tv_sec = now.tv_sec;
+ timeout.tv_nsec = (now.tv_usec + usec) * 1000;
+
+ pthread_mutex_lock(&m);
+ while(!t && !retcode){
+ retcode = pthread_cond_timedwait(&cond,&m, &timeout);
+ }
+
+ if(t) ret = true;
+ pthread_mutex_unlock(&m);
+
+ return ret;
+ }
};
/**
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev