Page MenuHomeFreeBSD

locks: provide transparent union for all lock classes
Needs ReviewPublic

Authored by glebius on Sat, Sep 5, 5:49 PM.

Details

Reviewers
kib
markj
Group Reviewers
Src Committers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 76578
Build 73461: arc lint + arc unit

Event Timeline

I believe this directly breaks the aliasing rules for C.

In D59455#1363642, @kib wrote:

I believe this directly breaks the aliasing rules for C.

My reading of the documentation says it is not.

https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Type-Attributes.html#index-transparent_005funion-type-attribute

It will allow to pass pointer to any structure that starts with struct lock_object with calling conventions of struct lock_object.

In D59455#1363642, @kib wrote:

I believe this directly breaks the aliasing rules for C.

My reading of the documentation says it is not.

https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Common-Type-Attributes.html#index-transparent_005funion-type-attribute

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.