X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=CodingStyle;h=c6e1a6186f0f2692e983699cd70220dc1064b31e;hb=f263172c99fd0a72c3f6666ffbaeaab786a3f1a8;hp=55b37a1cbc67361786864e844f9955460079d152;hpb=7aaeab4df24b7e9460705b1dad1010eef0354c50;p=sliver-openvswitch.git diff --git a/CodingStyle b/CodingStyle index 55b37a1cb..c6e1a6186 100644 --- a/CodingStyle +++ b/CodingStyle @@ -298,6 +298,21 @@ the name of each enum. For example: }; +THREAD SAFETY ANNOTATIONS + + Use the macros in lib/compiler.h to annotate locking requirements. +For example: + + static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER; + static struct ovs_rwlock rwlock = OVS_RWLOCK_INITIALIZER; + + void function_require_plain_mutex(void) OVS_REQUIRES(mutex); + void function_require_rwlock(void) OVS_REQ_RDLOCK(rwlock); + + Pass lock objects, not their addresses, to the annotation macros. +(Thus we have OVS_REQUIRES(mutex) above, not OVS_REQUIRES(&mutex).) + + SOURCE FILES Each source file should state its license in a comment at the very @@ -379,7 +394,21 @@ from . integer types. Use the PRId, PRIu, and PRIx macros from for formatting them with printf() and related functions. - Use %zu to format size_t with printf(). + For compatibility with antique printf() implementations: + + - Instead of "%zu", use "%"PRIuSIZE. + + - Instead of "%td", use "%"PRIdPTR. + + - Instead of "%ju", use "%"PRIuMAX. + +Other variants exist for different radixes. For example, use +"%"PRIxSIZE instead of "%zx" or "%x" instead of "%hhx". + + Also, instead of "%hhd", use "%d". Be cautious substituting "%u", +"%x", and "%o" for the corresponding versions with "hh": cast the +argument to unsigned char if necessary, because printf("%hhu", -1) +prints 255 but printf("%u", -1) prints 4294967295. Use bit-fields sparingly. Do not use bit-fields for layout of network protocol fields or in other circumstances where the exact