linux内核中spinlock_t的定义

时间:2017-01-19 08:34:33

标签: linux linux-kernel spinlock

在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;

有什么特别的含义吗?

谢谢

1 个答案:

答案 0 :(得分:0)

Because it is union of two structures and the other structure is enabled during debugging. What you are trying to do is creating structure members that are not needed at all.And you should understand in union of two structures we can use one at a time.

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;