Print this page
3373 gcc >= 4.5 concerns about offsetof()
Portions contributed by: Igor Pashev <pashev.igor@gmail.com>


  33 #define xen_mb()  mb()
  34 #define xen_rmb() rmb()
  35 #define xen_wmb() wmb()
  36 #endif
  37 
  38 typedef unsigned int RING_IDX;
  39 
  40 /* Round a 32-bit unsigned constant down to the nearest power of two. */
  41 #define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 0x1))
  42 #define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
  43 #define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
  44 #define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
  45 #define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
  46 
  47 /*
  48  * Calculate size of a shared ring, given the total available space for the
  49  * ring and indexes (_sz), and the name tag of the request/response structure.
  50  * A ring contains as many entries as will fit, rounded down to the nearest 
  51  * power of two (so we can mask with (size-1) to loop around).
  52  */






  53 #define __RING_SIZE(_s, _sz) \
  54     (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
  55 
  56 /*
  57  * Macros to make the correct C datatypes for a new kind of ring.
  58  * 
  59  * To make a new ring datatype, you need to have two message structures,
  60  * let's say request_t, and response_t already defined.
  61  *
  62  * In a header where you want the ring datatype declared, you then do:
  63  *
  64  *     DEFINE_RING_TYPES(mytag, request_t, response_t);
  65  *
  66  * These expand out to give you a set of types, as you can see below.
  67  * The most important of these are:
  68  * 
  69  *     mytag_sring_t      - The shared ring.
  70  *     mytag_front_ring_t - The 'front' half of the ring.
  71  *     mytag_back_ring_t  - The 'back' half of the ring.
  72  *




  33 #define xen_mb()  mb()
  34 #define xen_rmb() rmb()
  35 #define xen_wmb() wmb()
  36 #endif
  37 
  38 typedef unsigned int RING_IDX;
  39 
  40 /* Round a 32-bit unsigned constant down to the nearest power of two. */
  41 #define __RD2(_x)  (((_x) & 0x00000002) ? 0x2                  : ((_x) & 0x1))
  42 #define __RD4(_x)  (((_x) & 0x0000000c) ? __RD2((_x)>>2)<<2    : __RD2(_x))
  43 #define __RD8(_x)  (((_x) & 0x000000f0) ? __RD4((_x)>>4)<<4    : __RD4(_x))
  44 #define __RD16(_x) (((_x) & 0x0000ff00) ? __RD8((_x)>>8)<<8    : __RD8(_x))
  45 #define __RD32(_x) (((_x) & 0xffff0000) ? __RD16((_x)>>16)<<16 : __RD16(_x))
  46 
  47 /*
  48  * Calculate size of a shared ring, given the total available space for the
  49  * ring and indexes (_sz), and the name tag of the request/response structure.
  50  * A ring contains as many entries as will fit, rounded down to the nearest
  51  * power of two (so we can mask with (size-1) to loop around).
  52  */
  53 #define __CONST_RING_SIZE(_s, _sz) \
  54     (__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
  55        sizeof(((struct _s##_sring *)0)->ring[0])))
  56 /*
  57  * The same for passing in an actual pointer instead of a name tag.
  58  */
  59 #define __RING_SIZE(_s, _sz) \
  60     (__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
  61 
  62 /*
  63  * Macros to make the correct C datatypes for a new kind of ring.
  64  * 
  65  * To make a new ring datatype, you need to have two message structures,
  66  * let's say request_t, and response_t already defined.
  67  *
  68  * In a header where you want the ring datatype declared, you then do:
  69  *
  70  *     DEFINE_RING_TYPES(mytag, request_t, response_t);
  71  *
  72  * These expand out to give you a set of types, as you can see below.
  73  * The most important of these are:
  74  * 
  75  *     mytag_sring_t      - The shared ring.
  76  *     mytag_front_ring_t - The 'front' half of the ring.
  77  *     mytag_back_ring_t  - The 'back' half of the ring.
  78  *