diff options
author | Martin Hundebøll <martin@hundeboll.net> | 2011-12-08 07:32:41 -0500 |
---|---|---|
committer | Marek Lindner <lindner_marek@yahoo.de> | 2012-02-16 13:50:19 -0500 |
commit | a04ccd5970ec11f0b320971051435d86d3233c92 (patch) | |
tree | a57eaf54189eea3f63a30ee89a9be4e19513342e | |
parent | c51f9c09fabc96f23e449b5e39b1fc4e2cabcd85 (diff) |
batman-adv: Move is_out_of_time() to main.h for general use
Both translation tables and network coding use timeouts to do house
keeping, so we might as well share the function used to compare a
timestamp+timeout with current time.
For readability and simplicity, the function is renamed to
has_timed_out() and uses time_is_before_jiffies() instead of
time_after().
Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
-rw-r--r-- | net/batman-adv/main.h | 11 | ||||
-rw-r--r-- | net/batman-adv/translation-table.c | 32 |
2 files changed, 23 insertions, 20 deletions
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h index 86354e06eb48..f9c659b3f3a9 100644 --- a/net/batman-adv/main.h +++ b/net/batman-adv/main.h | |||
@@ -202,6 +202,17 @@ static inline int compare_eth(const void *data1, const void *data2) | |||
202 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | 202 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
203 | } | 203 | } |
204 | 204 | ||
205 | /** | ||
206 | * has_timed_out - compares current time (jiffies) and timestamp + timeout | ||
207 | * @timestamp: base value to compare with (in jiffies) | ||
208 | * @timeout: added to base value before comparing (in milliseconds) | ||
209 | * | ||
210 | * Returns true if current time is after timestamp + timeout | ||
211 | */ | ||
212 | static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout) | ||
213 | { | ||
214 | return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout)); | ||
215 | } | ||
205 | 216 | ||
206 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) | 217 | #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) |
207 | 218 | ||
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index bc518fca0b69..a84e80409f9b 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, | |||
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | static bool is_out_of_time(unsigned long starting_time, unsigned long timeout) | ||
112 | { | ||
113 | unsigned long deadline; | ||
114 | deadline = starting_time + msecs_to_jiffies(timeout); | ||
115 | |||
116 | return time_after(jiffies, deadline); | ||
117 | } | ||
118 | |||
119 | static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) | 111 | static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) |
120 | { | 112 | { |
121 | if (atomic_dec_and_test(&tt_local_entry->common.refcount)) | 113 | if (atomic_dec_and_test(&tt_local_entry->common.refcount)) |
@@ -420,8 +412,8 @@ static void tt_local_purge(struct bat_priv *bat_priv) | |||
420 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) | 412 | if (tt_local_entry->common.flags & TT_CLIENT_PENDING) |
421 | continue; | 413 | continue; |
422 | 414 | ||
423 | if (!is_out_of_time(tt_local_entry->last_seen, | 415 | if (!has_timed_out(tt_local_entry->last_seen, |
424 | TT_LOCAL_TIMEOUT * 1000)) | 416 | TT_LOCAL_TIMEOUT * 1000)) |
425 | continue; | 417 | continue; |
426 | 418 | ||
427 | tt_local_set_pending(bat_priv, tt_local_entry, | 419 | tt_local_set_pending(bat_priv, tt_local_entry, |
@@ -758,8 +750,8 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) | |||
758 | common); | 750 | common); |
759 | if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) | 751 | if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) |
760 | continue; | 752 | continue; |
761 | if (!is_out_of_time(tt_global_entry->roam_at, | 753 | if (!has_timed_out(tt_global_entry->roam_at, |
762 | TT_CLIENT_ROAM_TIMEOUT * 1000)) | 754 | TT_CLIENT_ROAM_TIMEOUT * 1000)) |
763 | continue; | 755 | continue; |
764 | 756 | ||
765 | bat_dbg(DBG_TT, bat_priv, "Deleting global " | 757 | bat_dbg(DBG_TT, bat_priv, "Deleting global " |
@@ -978,8 +970,8 @@ static void tt_req_purge(struct bat_priv *bat_priv) | |||
978 | 970 | ||
979 | spin_lock_bh(&bat_priv->tt_req_list_lock); | 971 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
980 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { | 972 | list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { |
981 | if (is_out_of_time(node->issued_at, | 973 | if (has_timed_out(node->issued_at, |
982 | TT_REQUEST_TIMEOUT * 1000)) { | 974 | TT_REQUEST_TIMEOUT * 1000)) { |
983 | list_del(&node->list); | 975 | list_del(&node->list); |
984 | kfree(node); | 976 | kfree(node); |
985 | } | 977 | } |
@@ -997,8 +989,8 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv, | |||
997 | spin_lock_bh(&bat_priv->tt_req_list_lock); | 989 | spin_lock_bh(&bat_priv->tt_req_list_lock); |
998 | list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { | 990 | list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { |
999 | if (compare_eth(tt_req_node_tmp, orig_node) && | 991 | if (compare_eth(tt_req_node_tmp, orig_node) && |
1000 | !is_out_of_time(tt_req_node_tmp->issued_at, | 992 | !has_timed_out(tt_req_node_tmp->issued_at, |
1001 | TT_REQUEST_TIMEOUT * 1000)) | 993 | TT_REQUEST_TIMEOUT * 1000)) |
1002 | goto unlock; | 994 | goto unlock; |
1003 | } | 995 | } |
1004 | 996 | ||
@@ -1591,8 +1583,8 @@ static void tt_roam_purge(struct bat_priv *bat_priv) | |||
1591 | 1583 | ||
1592 | spin_lock_bh(&bat_priv->tt_roam_list_lock); | 1584 | spin_lock_bh(&bat_priv->tt_roam_list_lock); |
1593 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { | 1585 | list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { |
1594 | if (!is_out_of_time(node->first_time, | 1586 | if (!has_timed_out(node->first_time, |
1595 | ROAMING_MAX_TIME * 1000)) | 1587 | ROAMING_MAX_TIME * 1000)) |
1596 | continue; | 1588 | continue; |
1597 | 1589 | ||
1598 | list_del(&node->list); | 1590 | list_del(&node->list); |
@@ -1619,8 +1611,8 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv, | |||
1619 | if (!compare_eth(tt_roam_node->addr, client)) | 1611 | if (!compare_eth(tt_roam_node->addr, client)) |
1620 | continue; | 1612 | continue; |
1621 | 1613 | ||
1622 | if (is_out_of_time(tt_roam_node->first_time, | 1614 | if (has_timed_out(tt_roam_node->first_time, |
1623 | ROAMING_MAX_TIME * 1000)) | 1615 | ROAMING_MAX_TIME * 1000)) |
1624 | continue; | 1616 | continue; |
1625 | 1617 | ||
1626 | if (!atomic_dec_not_zero(&tt_roam_node->counter)) | 1618 | if (!atomic_dec_not_zero(&tt_roam_node->counter)) |