This commit adds an extern sequence number 'timewarp_seq' in timeval,
so that threads other than main thread can wait on this sequence number
and be waken up when time is warped.

Signed-off-by: Alex Wang <al...@nicira.com>
---
 lib/timeval.c |    8 ++++++++
 lib/timeval.h |    3 +++
 2 files changed, 11 insertions(+)

diff --git a/lib/timeval.c b/lib/timeval.c
index 223ed30..07b3e05 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -33,6 +33,7 @@
 #include "hmap.h"
 #include "ovs-thread.h"
 #include "signals.h"
+#include "seq.h"
 #include "unixctl.h"
 #include "util.h"
 #include "vlog.h"
@@ -57,6 +58,10 @@ static struct clock wall_clock;      /* CLOCK_REALTIME. */
 /* The monotonic time at which the time module was initialized. */
 static long long int boot_time;
 
+/* Reference to the seq struct.  Threads other than main thread can
+ * wait on timewarp_seq and be wakenup when time is warped. */
+struct seq *timewarp_seq;
+
 /* Monotonic time in milliseconds at which to die with SIGALRM (if not
  * LLONG_MAX). */
 static long long int deadline = LLONG_MAX;
@@ -79,6 +84,7 @@ init_clock(struct clock *c, clockid_t id)
     ovs_mutex_init(&c->mutex);
     atomic_init(&c->slow_path, false);
     xclock_gettime(c->id, &c->cache);
+    timewarp_seq = seq_create();
 }
 
 static void
@@ -509,6 +515,8 @@ timeval_warp_cb(struct unixctl_conn *conn,
     ovs_mutex_lock(&monotonic_clock.mutex);
     atomic_store(&monotonic_clock.slow_path, true);
     timespec_add(&monotonic_clock.warp, &monotonic_clock.warp, &ts);
+    /* Changes 'timewarp_seq' to wakeup all waiting thread. */
+    seq_change(timewarp_seq);
     ovs_mutex_unlock(&monotonic_clock.mutex);
 
     unixctl_command_reply(conn, "warped");
diff --git a/lib/timeval.h b/lib/timeval.h
index 99b3af0..9f8e917 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -27,6 +27,7 @@ extern "C" {
 
 struct ds;
 struct pollfd;
+struct seq;
 struct timespec;
 struct timeval;
 
@@ -45,6 +46,8 @@ struct tm_msec {
   int msec;
 };
 
+extern struct seq *timewarp_seq;
+
 time_t time_now(void);
 time_t time_wall(void);
 long long int time_msec(void);
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to