Przeglądaj źródła

timer-list: Add functions for get and set interval

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Jan Friesse 5 lat temu
rodzic
commit
0360d14b49
3 zmienionych plików z 51 dodań i 0 usunięć
  1. 15 0
      qdevices/test-timer-list.c
  2. 30 0
      qdevices/timer-list.c
  3. 6 0
      qdevices/timer-list.h

+ 15 - 0
qdevices/test-timer-list.c

@@ -154,6 +154,19 @@ check_timer_list_basics(void)
 	assert(timer_list_time_to_expire(&tlist) == PR_INTERVAL_NO_TIMEOUT);
 	assert(timer_list_time_to_expire(&tlist) == PR_INTERVAL_NO_TIMEOUT);
 	assert(timer_list_time_to_expire_ms(&tlist) == ~((uint32_t)0));
 	assert(timer_list_time_to_expire_ms(&tlist) == ~((uint32_t)0));
 
 
+	/*
+	 * Check changing of interval
+	 */
+	timer_list_fn1_called = 0;
+	tlist_entry = timer_list_add(&tlist, LONG_TIMEOUT, timer_list_fn1, &timer_list_fn1_called, timer_list_fn1);
+	assert(tlist_entry != NULL);
+	assert(timer_list_entry_set_interval(&tlist, tlist_entry, SHORT_TIMEOUT) == 0);
+	(void)poll(NULL, 0, SHORT_TIMEOUT);
+	assert(timer_list_time_to_expire(&tlist) == 0);
+	assert(timer_list_time_to_expire_ms(&tlist) == 0);
+	timer_list_expire(&tlist);
+	assert(timer_list_fn1_called == 1);
+
 	/*
 	/*
 	 * Test speed and more entries
 	 * Test speed and more entries
 	 */
 	 */
@@ -224,6 +237,7 @@ check_timer_heap(void)
 	assert(timer_list_debug_is_valid_heap(&tlist));
 	assert(timer_list_debug_is_valid_heap(&tlist));
 	assert(tlist.size == i + 1);
 	assert(tlist.size == i + 1);
 	assert(tlist.entries[0] == tlist_entry_small);
 	assert(tlist.entries[0] == tlist_entry_small);
+	assert(timer_list_entry_get_interval(tlist_entry_small) == SHORT_TIMEOUT);
 
 
 	/*
 	/*
 	 * Remove all items
 	 * Remove all items
@@ -233,6 +247,7 @@ check_timer_heap(void)
 
 
 		assert(timer_list_debug_is_valid_heap(&tlist));
 		assert(timer_list_debug_is_valid_heap(&tlist));
 		assert(tlist.entries[0] == tlist_entry_small);
 		assert(tlist.entries[0] == tlist_entry_small);
+		assert(timer_list_entry_get_interval(tlist_entry[i]) == LONG_TIMEOUT * (i + 1));
 	}
 	}
 
 
 	/*
 	/*

+ 30 - 0
qdevices/timer-list.c

@@ -461,3 +461,33 @@ timer_list_free(struct timer_list *tlist)
 
 
 	timer_list_init(tlist);
 	timer_list_init(tlist);
 }
 }
+
+PRUint32
+timer_list_entry_get_interval(const struct timer_list_entry *entry)
+{
+
+	return (entry->interval);
+}
+
+int
+timer_list_entry_set_interval(struct timer_list *tlist, struct timer_list_entry *entry,
+    PRUint32 interval)
+{
+
+	if (interval < 1 || interval > TIMER_LIST_MAX_INTERVAL) {
+		return (-1);
+	}
+
+	if (!entry->is_active) {
+		return (-1);
+	}
+
+	timer_list_heap_delete(tlist, entry);
+
+	entry->interval = interval;
+	entry->epoch = PR_IntervalNow();
+
+	timer_list_insert_into_list(tlist, entry);
+
+	return (0);
+}

+ 6 - 0
qdevices/timer-list.h

@@ -94,6 +94,12 @@ extern void				 timer_list_free(struct timer_list *tlist);
 
 
 extern int				 timer_list_debug_is_valid_heap(struct timer_list *tlist);
 extern int				 timer_list_debug_is_valid_heap(struct timer_list *tlist);
 
 
+extern PRUint32				 timer_list_entry_get_interval(
+    const struct timer_list_entry *entry);
+
+extern int				 timer_list_entry_set_interval(
+    struct timer_list *tlist, struct timer_list_entry *entry, PRUint32 interval);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif