Author: rco
Date: 2010-04-16 11:09:09 +0200 (Fri, 16 Apr 2010)
New Revision: 1799
Modified:
trunk/core/AmThread.h
Log:
- adds wrapper for pthread_cond_timedwait(). Thx to Robert Szokovacs for the
original patch.
Modified: trunk/core/AmThread.h
===================================================================
--- trunk/core/AmThread.h 2010-04-16 09:07:03 UTC (rev 1798)
+++ trunk/core/AmThread.h 2010-04-16 09:09:09 UTC (rev 1799)
@@ -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