Wed Jul 27 23:10:41 2011 UTC ()
Make this use offsetof and __typeof__ to appease gcc4.5


(matt)
diff -r1.11 -r1.12 src/sys/arch/xen/include/xen3-public/io/ring.h

cvs diff -r1.11 -r1.12 src/sys/arch/xen/include/xen3-public/io/Attic/ring.h (expand / switch to unified diff)

--- src/sys/arch/xen/include/xen3-public/io/Attic/ring.h 2008/08/22 15:28:11 1.11
+++ src/sys/arch/xen/include/xen3-public/io/Attic/ring.h 2011/07/27 23:10:40 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ring.h,v 1.11 2008/08/22 15:28:11 cegger Exp $ */ 1/* $NetBSD: ring.h,v 1.12 2011/07/27 23:10:40 matt Exp $ */
2/****************************************************************************** 2/******************************************************************************
3 * ring.h 3 * ring.h
4 *  4 *
5 * Shared producer-consumer ring macros. 5 * Shared producer-consumer ring macros.
6 * 6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to 8 * of this software and associated documentation files (the "Software"), to
9 * deal in the Software without restriction, including without limitation the 9 * deal in the Software without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the Software is 11 * sell copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions: 12 * furnished to do so, subject to the following conditions:
13 * 13 *
14 * The above copyright notice and this permission notice shall be included in 14 * The above copyright notice and this permission notice shall be included in
@@ -50,27 +50,27 @@ typedef unsigned int RING_IDX; @@ -50,27 +50,27 @@ typedef unsigned int RING_IDX;
50#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1)) 50#define __RD2(_x) (((_x) & 0x00000002) ? 0x2 : ((_x) & 0x1))
51#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x)) 51#define __RD4(_x) (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2 : __RD2(_x))
52#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x)) 52#define __RD8(_x) (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4 : __RD4(_x))
53#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x)) 53#define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8 : __RD8(_x))
54#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x)) 54#define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
55 55
56/* 56/*
57 * Calculate size of a shared ring, given the total available space for the 57 * Calculate size of a shared ring, given the total available space for the
58 * ring and indexes (_sz), and the name tag of the request/response structure. 58 * ring and indexes (_sz), and the name tag of the request/response structure.
59 * A ring contains as many entries as will fit, rounded down to the nearest  59 * A ring contains as many entries as will fit, rounded down to the nearest
60 * power of two (so we can mask with (size-1) to loop around). 60 * power of two (so we can mask with (size-1) to loop around).
61 */ 61 */
62#define __RING_SIZE(_s, _sz) \ 62#define __RING_SIZE(_s, _sz) \
63 (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0]))) 63 (__RD32(((_sz) - offsetof(__typeof__(*(_s)), ring)) / sizeof((_s)->ring[0])))
64 64
65/* 65/*
66 * Macros to make the correct C datatypes for a new kind of ring. 66 * Macros to make the correct C datatypes for a new kind of ring.
67 *  67 *
68 * To make a new ring datatype, you need to have two message structures, 68 * To make a new ring datatype, you need to have two message structures,
69 * let's say request_t, and response_t already defined. 69 * let's say request_t, and response_t already defined.
70 * 70 *
71 * In a header where you want the ring datatype declared, you then do: 71 * In a header where you want the ring datatype declared, you then do:
72 * 72 *
73 * DEFINE_RING_TYPES(mytag, request_t, response_t); 73 * DEFINE_RING_TYPES(mytag, request_t, response_t);
74 * 74 *
75 * These expand out to give you a set of types, as you can see below. 75 * These expand out to give you a set of types, as you can see below.
76 * The most important of these are: 76 * The most important of these are: