提交 b6308520 创建 作者: Austin Clements's avatar Austin Clements

Make spinlocks constructable without initlock

These locks can be statically constructed in the .data segment, since the constructor is constexpr. Currently this only works for locks that aren't tracked by lockstat.
上级 d0b095e0
...@@ -16,6 +16,31 @@ struct spinlock { ...@@ -16,6 +16,31 @@ struct spinlock {
#if LOCKSTAT #if LOCKSTAT
struct klockstat *stat; struct klockstat *stat;
#endif #endif
// Create a spinlock that will later be initialized by initlock.
// XXX(austin) Remove this and initlock in favor of the other ctor.
constexpr spinlock()
: locked(0)
#if SPINLOCK_DEBUG
, name(nullptr), cpu(nullptr), pcs{}
#endif
#if LOCKSTAT
, stat(nullptr)
#endif
{ }
// Create a spinlock without lockstat tracking. This is constexpr,
// so it can be used for global spinlocks without incurring a static
// constructor.
constexpr spinlock(const char *name)
: locked(0)
#if SPINLOCK_DEBUG
, name(name), cpu(nullptr), pcs{}
#endif
#if LOCKSTAT
, stat(nullptr)
#endif
{ }
}; };
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
......
...@@ -117,13 +117,7 @@ holding(struct spinlock *lock) ...@@ -117,13 +117,7 @@ holding(struct spinlock *lock)
#if LOCKSTAT #if LOCKSTAT
LIST_HEAD(lockstat_list, klockstat); LIST_HEAD(lockstat_list, klockstat);
static struct lockstat_list lockstat_list = { (struct klockstat*) nullptr }; static struct lockstat_list lockstat_list = { (struct klockstat*) nullptr };
static struct spinlock lockstat_lock = { static struct spinlock lockstat_lock("lockstat");
locked: 0,
#if SPINLOCK_DEBUG
name: "lockstat",
cpu: (struct cpu*) nullptr,
#endif
};
klockstat::klockstat(const char *name) : klockstat::klockstat(const char *name) :
rcu_freed("klockstat") rcu_freed("klockstat")
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论