Details
- Reviewers
kib markj - Group Reviewers
Src Committers
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Skipped - Unit
Tests Skipped - Build Status
Buildable 76649 Build 73532: arc lint + arc unit
Event Timeline
My reading of the documentation says it is not.
It will allow to pass pointer to any structure that starts with struct lock_object with calling conventions of struct lock_object.
But then you access it through the first member which is the pointer to lock_object. I believe that this still breaks the C aliasing rules.
More, I do not see why trying to use this ugly gcc extension. There is C-standard _Generic() facility, which allows to enumerate allowed types for an expression and do something specific to deduced type.
I suspect that uglyness predated C11.
And, I do not understand why you don't do simply
#define callout_init_mtx(c, mtx, flags) callout_init_lock((c), &(mtx)->lock_object, (flags))
and same for all other blocking locks.
I can't see how _Generic() can do the same. AFAIK, _Generic() implies multiple different functions. My goal is the opposite - have single function that accepts arguments of different (but compatible) types.
It can, and it can do even more.
But again, I do not see why do you need either the gcc union hack, or even _Generic, for the first-order implementation.
#define callout_init_lock(c, lk, flags) _callout_init_lock((c), &(lk)->lock_object, (flags))
does it already. It works for any structure that has the lock_object member.
With _Generic(), you can typecheck:
#define callout_init_lock1(c, lk, flags) _callout_init_lock((c), &(lk)->lock_object, (flags)) #define callout_init_lock(c, lk, flags) \ _Generic((lk), \ struct mtx: callout_init_lock1((c), (lk), (flags)), \ struct rmlock: callout_init_lock1((c), (lk), (flags)), \ struct rwlock: callout_init_lock1((c), (lk), (flags))) #undef callout_init_lock1
@glebius : I appreciate what you're trying to solve, but @kib brings up a very good point.
My concern with the change is that code (especially third-party/ports code) may naïvely assume a lock type is X, when in fact it's Y after the change. Anti-patterns like this seem ripe for improper memory accesses/potential scribblers..
| sys/sys/lock.h | ||
|---|---|---|
| 171 | ||
| sys/sys/lock.h | ||
|---|---|---|
| 171 | Bikeshedding, but can we call it lock2lo() instead? "lock" is the prefix used everywhere in this file. "lk" makes me think of lockmgr locks. Otherwise looks fine to me. | |
| sys/sys/lock.h | ||
|---|---|---|
| 171 | My main reason for the shorter macro was that in the _Generic() macros fit into single line :) Any opinion on NULLLOCK vs NOLOCK? | |