X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fcompiler.h;h=cfe90666017bf4aeed4ab04aabb8b1c5724292dc;hb=ec988646afe6aee6a63d6894a3e9b50f715d5941;hp=0dbacbfccefd867864863c15f02670947a1518d3;hpb=ed2232fc7720ca482d3be097706e70588a31cb1f;p=sliver-openvswitch.git diff --git a/lib/compiler.h b/lib/compiler.h index 0dbacbfcc..cfe906660 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,8 +96,8 @@ * - OVS_REQUIRES(MUTEX) indicate that the function may only be called with * MUTEX held and that the function does not release MUTEX. * - * - OVS_LOCKS_EXCLUDED(MUTEX) indicates that the function may only be - * called when MUTEX is not held. + * - OVS_EXCLUDED(MUTEX) indicates that the function may only be called when + * MUTEX is not held. * * * The following variants, with the same syntax, apply to reader-writer locks: @@ -108,7 +108,7 @@ * OVS_RELEASES OVS_RELEASES OVS_RELEASES * OVS_TRY_LOCK OVS_TRY_RDLOCK OVS_TRY_WRLOCK * OVS_REQUIRES OVS_REQ_RDLOCK OVS_REQ_WRLOCK - * OVS_LOCKS_EXCLUDED OVS_LOCKS_EXCLUDED OVS_LOCKS_EXCLUDED + * OVS_EXCLUDED OVS_EXCLUDED OVS_EXCLUDED */ #define OVS_LOCKABLE __attribute__((lockable)) #define OVS_REQ_RDLOCK(...) __attribute__((shared_locks_required(__VA_ARGS__))) @@ -179,4 +179,45 @@ #define OVS_PACKED(DECL) __pragma(pack(push, 1)) DECL __pragma(pack(pop)) #endif +/* For defining a structure whose instances should aligned on an N-byte + * boundary. + * + * e.g. The following: + * OVS_ALIGNED_STRUCT(64, mystruct) { ... }; + * is equivalent to the following except that it specifies 64-byte alignment: + * struct mystruct { ... }; + */ +#ifndef _MSC_VER +#define OVS_ALIGNED_STRUCT(N, TAG) struct __attribute__((aligned(N))) TAG +#else +#define OVS_ALIGNED_STRUCT(N, TAG) __declspec(align(N)) struct TAG +#endif + +#ifdef _MSC_VER +#define CCALL __cdecl +#pragma section(".CRT$XCU",read) +#define OVS_CONSTRUCTOR(f) \ + static void __cdecl f(void); \ + __declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; \ + static void __cdecl f(void) +#else +#define OVS_CONSTRUCTOR(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) +#endif + +/* OVS_PREFETCH() can be used to instruct the CPU to fetch the cache + * line containing the given address to a CPU cache. + * OVS_PREFETCH_WRITE() should be used when the memory is going to be + * written to. Depending on the target CPU, this can generate the same + * instruction as OVS_PREFETCH(), or bring the data into the cache in an + * exclusive state. */ +#if __GNUC__ +#define OVS_PREFETCH(addr) __builtin_prefetch((addr)) +#define OVS_PREFETCH_WRITE(addr) __builtin_prefetch((addr), 1) +#else +#define OVS_PREFETCH(addr) +#define OVS_PREFETCH_WRITE(addr) +#endif + #endif /* compiler.h */