在include/linux/spinlock_types.h中
spinlock_t的定义如下
typedef struct spinlock {
union {
struct raw_spinlock rlock;
struct {
u8 __padding[];
struct lockdep_map dep_map;
};
};
} spinlock_t;为什么"__padding[]“和"dep_map”变量应该放在没有名称的结构中
但不只是像下面这样吗?
typedef struct spinlock {
union {
struct raw_spinlock rlock;
u8 __padding[];
struct lockdep_map dep_map;
};
} spinlock_t;有什么特别的意思吗?
谢谢
发布于 2017-06-15 18:11:30
因为它是两个结构的联合,而另一个结构在调试期间被启用。你要做的是创建在all.And中不需要的结构成员,你应该理解,在两个结构的联合中,我们可以一次使用一个。
typedef struct spinlock {
union {
struct raw_spinlock rlock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
struct {
u8 __padding[LOCK_PADSIZE];
struct lockdep_map dep_map;
};
#endif
};
} spinlock_t;https://stackoverflow.com/questions/41737182
复制相似问题