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
--- AmThread.h.orig 2010-04-14 15:04:11.000000000 +0200
+++ AmThread.h 2010-04-14 15:03:55.000000000 +0200
@@ -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,33 @@
}
pthread_mutex_unlock(&m);
}
+
+ /** Waits for the condition to be true or a timeout. */
+ bool wait_for_to(const struct timeval& tv)
+ {
+ struct timeval now;
+ struct timespec timeout;
+ int retcode;
+ bool ret;
+ pthread_mutex_lock(&m);
+ gettimeofday(&now, NULL);
+ timeout.tv_sec = now.tv_sec + tv.tv_sec;
+ timeout.tv_nsec = (now.tv_usec + tv.tv_usec) * 1000;
+ retcode = 0;
+ while(!t && retcode != ETIMEDOUT){
+ retcode = pthread_cond_timedwait(&cond,&m, &timeout);
+ }
+ if(ETIMEDOUT == retcode)
+ {
+ ret = false;
+ }
+ else
+ {
+ ret = true;
+ }
+ pthread_mutex_unlock(&m);
+ return ret;
+ }
};
/**
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev