Re:Linus vs C++, again
by matthavener on Friday June 11, 2010 @09:25AM
(#1423759)
Could Linux explain spinlock.h then? Depending on which type you give to the PICK_OP macro, it performs a different operation. Its basically a C template. Seems a bit weird to complain about type context specific code and then use it in one of the most important parts of the kernel..
Here's the code:
#define TYPE_EQUAL(lock, type) \
__builtin_types_compatible_p(typeof(lock), type )
#define PICK_OP(op, lock) \
do { \
if (TYPE_EQUAL((lock), raw_spinlock_t)) \
__spin##op((raw_spinlock_t )(lock)); \
else if (TYPE_EQUAL(lock, spinlock_t)) \
_spin##op((spinlock_t *)(lock)); \
else __bad_spinlock_type(); \
} while (0)
Here's the code: #define TYPE_EQUAL(lock, type) \ __builtin_types_compatible_p(typeof(lock), type )
#define PICK_OP(op, lock) \ do { \ if (TYPE_EQUAL((lock), raw_spinlock_t)) \ __spin##op((raw_spinlock_t )(lock)); \ else if (TYPE_EQUAL(lock, spinlock_t)) \ _spin##op((spinlock_t *)(lock)); \ else __bad_spinlock_type(); \ } while (0)