From patchwork Thu May 28 11:36:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 5389 Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by open-mesh.net (8.14.3/8.13.4/Debian-3sarge3) with SMTP id n4SBs8V8004586 for ; Thu, 28 May 2009 11:54:09 GMT Received: (qmail invoked by alias); 28 May 2009 11:37:01 -0000 Received: from i59F6A01C.versanet.de (EHLO localhost) [89.246.160.28] by mail.gmx.net (mp070) with SMTP; 28 May 2009 13:37:01 +0200 X-Authenticated: #15668376 X-Provags-ID: V01U2FsdGVkX1+fClRkoNifNp6dHKc0AAjttaQj7D1dPnZ1TvKtzx zM1IUgOFDKAgao From: Sven Eckelmann To: b.a.t.m.a.n@open-mesh.net Date: Thu, 28 May 2009 13:36:58 +0200 Message-Id: <1243510619-10749-1-git-send-email-sven.eckelmann@gmx.de> X-Mailer: git-send-email 1.6.3.1 In-Reply-To: <4313f3060905190727x279f2d0boc4e74e4df6e821bc@mail.gmail.com> References: <4313f3060905190727x279f2d0boc4e74e4df6e821bc@mail.gmail.com> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.5 Subject: [B.A.T.M.A.N.] [PATCH 2/3] [batman] Make TYPE_OF_WORD the largest integral type X-BeenThere: b.a.t.m.a.n@open-mesh.net X-Mailman-Version: 2.1.11 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: Thu, 28 May 2009 11:54:09 -0000 Signed-off-by: Sven Eckelmann --- batman/allocate.c | 24 ++++++++++++++++++++---- batman/batman.h | 2 ++ batman/bitarray.h | 4 +--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/batman/allocate.c b/batman/allocate.c index a779504..5e28c71 100644 --- a/batman/allocate.c +++ b/batman/allocate.c @@ -68,16 +68,32 @@ struct memoryUsage static size_t getHeaderPad() { - size_t pad = sizeof(uintmax_t) - (sizeof(struct chunkHeader) % sizeof(uintmax_t)); - if (pad == sizeof(uintmax_t)) + size_t alignwith, pad; + + if (sizeof(TYPE_OF_WORD) > sizeof(void*)) + alignwith = sizeof(TYPE_OF_WORD); + else + alignwith = sizeof(void*); + + pad = alignwith - (sizeof(struct chunkHeader) % alignwith); + + if (pad == alignwith) return 0; else return pad; } static size_t getTrailerPad(size_t length) { - size_t pad = sizeof(uintmax_t) - (length % sizeof(uintmax_t)); - if (pad == sizeof(uintmax_t)) + size_t alignwith, pad; + + if (sizeof(TYPE_OF_WORD) > sizeof(void*)) + alignwith = sizeof(TYPE_OF_WORD); + else + alignwith = sizeof(void*); + + pad = alignwith - (length % alignwith); + + if (pad == alignwith) return 0; else return pad; diff --git a/batman/batman.h b/batman/batman.h index c02ce8d..1cc5896 100644 --- a/batman/batman.h +++ b/batman/batman.h @@ -31,6 +31,8 @@ #include #include +#define TYPE_OF_WORD uintmax_t /* you should choose something big, if you don't want to waste cpu */ + #include "list-batman.h" #include "bitarray.h" #include "hash.h" diff --git a/batman/bitarray.h b/batman/bitarray.h index 5472ef1..0bb0710 100644 --- a/batman/bitarray.h +++ b/batman/bitarray.h @@ -21,10 +21,8 @@ -#define TYPE_OF_WORD unsigned long /* you should choose something big, if you don't want to waste cpu */ -#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 ) #include "batman.h" - +#define WORD_BIT_SIZE ( sizeof(TYPE_OF_WORD) * 8 ) void bit_init( TYPE_OF_WORD *seq_bits );