utils: Introduce SWAP() helper to exchange two variables

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kirill Tkhai 2017-06-28 18:54:07 +03:00 committed by Andrei Vagin
parent f41a087891
commit bfbd7bbacb
2 changed files with 9 additions and 6 deletions

View file

@ -48,14 +48,10 @@ struct pid {
static inline bool equal_pid(struct pid *a, struct pid *b)
{
struct pid *t;
int i;
if (a->level > b->level) {
t = a;
a = b;
b = t;
}
if (a->level > b->level)
SWAP(a, b);
for(i = 0; i < b->level; i++) {
if (i < a->level) {

View file

@ -85,6 +85,13 @@
type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; })
#define SWAP(x, y) \
do { \
typeof(x) ____val = x; \
x = y; \
y = ____val; \
} while (0)
#define is_log2(v) (((v) & ((v) - 1)) == 0)
#endif /* __CR_COMPILER_H__ */