From patchwork Wed May 18 07:20:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1125 Return-Path: Received: from latitanza.investici.org (latitanza.investici.org [82.94.249.234]) by open-mesh.org (Postfix) with ESMTPS id EEE80154365 for ; Wed, 18 May 2011 09:20:47 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 4C966981DB; Wed, 18 May 2011 07:20:46 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org 4C966981DB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1305703246; bh=k/QenzHqVw541rG8R2SvoxAyPe0rOMAiz/IXjXNqnCw=; h=From:To:Cc:Subject:Date:Message-Id; b=gxNoYWx3DBN7kPhbYvaT4wiFQgkDncrDx9lncbcfj7xSe7FZ4g1arRAkk44FPdeAx KjgEAkHor0RNmXJO8vw7GI/sdl9jbbZHA5kjNzYd5fPDH2N+8CwYjLr92e2clZp9hU UFRCKxvhdc/0hHuYQNMsA+gtYUWP/Q1lzuL4f3/o= From: Antonio Quartulli To: "B.A.T.M.A.N" Date: Wed, 18 May 2011 09:20:50 +0200 Message-Id: <1305703250-23111-1-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: move smallest_signed_int(), seq_before() and seq_after() into main.h X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 May 2011 07:20:48 -0000 smallest_signed_int(), seq_before() and seq_after() are very useful functions that help to handle comparisons between sequence numbers. However they were only defined in vis.c. With this patch every batman-adv function will be able to use them. Signed-off-by: Antonio Quartulli Acked-by: Sven Eckelmann --- main.h | 16 ++++++++++++++++ vis.c | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.h b/main.h index 3ca3941..90db244 100644 --- a/main.h +++ b/main.h @@ -181,4 +181,20 @@ static inline int compare_eth(void *data1, void *data2) #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) +/* Returns the smallest signed integer in two's complement with the sizeof x */ +#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) + +/* Checks if a sequence number x is a predecessor/successor of y. + * they handle overflows/underflows and can correctly check for a + * predecessor/successor unless the variable sequence number has grown by + * more then 2**(bitwidth(x)-1)-1. + * This means that for a uint8_t with the maximum value 255, it would think: + * - when adding nothing - it is neither a predecessor nor a successor + * - before adding more than 127 to the starting value - it is a predecessor, + * - when adding 128 - it is neither a predecessor nor a successor, + * - after adding more than 127 to the starting value - it is a successor */ +#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \ + _dummy > smallest_signed_int(_dummy); }) +#define seq_after(x, y) seq_before(y, x) + #endif /* _NET_BATMAN_ADV_MAIN_H_ */ diff --git a/vis.c b/vis.c index c39f20c..e1ed552 100644 --- a/vis.c +++ b/vis.c @@ -30,22 +30,6 @@ #define MAX_VIS_PACKET_SIZE 1000 -/* Returns the smallest signed integer in two's complement with the sizeof x */ -#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u))) - -/* Checks if a sequence number x is a predecessor/successor of y. - * they handle overflows/underflows and can correctly check for a - * predecessor/successor unless the variable sequence number has grown by - * more then 2**(bitwidth(x)-1)-1. - * This means that for a uint8_t with the maximum value 255, it would think: - * - when adding nothing - it is neither a predecessor nor a successor - * - before adding more than 127 to the starting value - it is a predecessor, - * - when adding 128 - it is neither a predecessor nor a successor, - * - after adding more than 127 to the starting value - it is a successor */ -#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \ - _dummy > smallest_signed_int(_dummy); }) -#define seq_after(x, y) seq_before(y, x) - static void start_vis_timer(struct bat_priv *bat_priv); /* free the info */