On Monday 12 March 2007 16:17, Attilio Rao wrote: > 2007/3/12, Pawel Jakub Dawidek <[EMAIL PROTECTED]>: > > On Mon, Mar 12, 2007 at 03:35:21PM -0400, John Baldwin wrote: > > > On Monday 12 March 2007 14:56, Pawel Jakub Dawidek wrote: > > > > On Mon, Mar 12, 2007 at 11:16:23AM -0400, John Baldwin wrote: > > > > > On Saturday 10 March 2007 15:52, Pawel Jakub Dawidek wrote: > > > > > > What about something like this: > > > > > > > > > > > > #define cv_wait(cv, lock) do { > > > > > > switch (LO_CLASSINDEX((struct lock_object *)(lock))) { > > > > > > > > > > The problem with a cast is you use type checking. Might as well do this: > > > > > > > > > > #define cv_wait(cv, lock) _cv_wait((cv), (struct lock_object *)(lock)) > > > > > > > > This will skip type checking and my version only cast to provide type > > > > checking, so when you pass some random variable it will give you an > > > > error. > > > > > > Not really, you may pass some garbage and the LO_CLASSINDEX turns out to be a > > > mutex. :) You only get a runtime error, not a compile-time one. > > > Type-checking by the compiler is nice because you get compile-time errors. > > > > I'll get compile-time error, because cv_wait_mtx() takes > > 'struct condvar *' and 'struct mtx *' as arguments. So even if some > > garbage returns 1, which turns out to be a mutex, call to cv_wait_mtx() > > will generate compile-time error. > > However, it has another kind of problem we were trying to avoid: the > first member of the lock you pass should be the struct lock_object. We > should not deal on the ordering of members for locks. > > > But it seems the solution may not be that good if it is not very obvious > > on a first look. If typeof() thing works, its fine by me, just give me > > condvar(9) that works with sx(9) locks:) > > I think problems with typeof() are 2: > 1) It requires a serie of if/else if before to call the cv_wait() > (increase of kernel .text, small slowness, etc.)
The compiler should optimize those out actually to a single call to _cv_wait(), just as it does with PCPU_*(). > 2) It is GCC dependant (but we have other of it inside the kernel > alredy, so this is a minor nit) That is the only really big nit. -- John Baldwin _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "[EMAIL PROTECTED]"