svn commit: r201885 - head/sys/kern

Juli Mallett jmallett at FreeBSD.org
Sat Jan 9 06:14:48 UTC 2010


On Fri, Jan 8, 2010 at 22:05, David Xu <davidxu at freebsd.org> wrote:

>  #define TYPE_SIMPLE_WAIT       0
> -#define TYPE_CV                        1
> -#define TYPE_SIMPLE_LOCK       2
> -#define TYPE_NORMAL_UMUTEX     3
> -#define TYPE_PI_UMUTEX         4
> -#define TYPE_PP_UMUTEX         5
> -#define TYPE_RWLOCK            6
> +#define TYPE_CV                        (TYPE_SIMPLE_WAIT+1)
> +#define TYPE_SEM               (TYPE_CV+1)
> +#define TYPE_SIMPLE_LOCK       (TYPE_SEM+1)
> +#define TYPE_NORMAL_UMUTEX     (TYPE_SIMPLE_LOCK+1)
> +#define TYPE_PI_UMUTEX         (TYPE_NORMAL_UMUTEX+1)
> +#define TYPE_PP_UMUTEX         (TYPE_PI_UMUTEX+1)
> +#define TYPE_RWLOCK            (TYPE_PP_UMUTEX+1)
>

I am not sure I get the benefit of defining them this way.  Certainly it
does nothing to improve stability in the face of additions, removals or
re-sorting (in the latter case, it makes figuring out how to define a new
one exceptionally hard.)  I am not aware of a trend towards defining
constants this way in the kernel (there are none in sys/ that I see) and
find it kind of baffling and needlessly obtuse.  If there is a need to
define them in such an unusual manner, it would be nice to see a comment
that says why.  If you don't need to use #defines and have a dislike
assigning numbers by hand, why not simply use 'enum'?


More information about the svn-src-head mailing list