From owner-freebsd-arch Wed Sep 4 22:11:33 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9722137B400 for ; Wed, 4 Sep 2002 22:11:29 -0700 (PDT) Received: from avocet.mail.pas.earthlink.net (avocet.mail.pas.earthlink.net [207.217.120.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 361F443E65 for ; Wed, 4 Sep 2002 22:11:29 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from pool0312.cvx40-bradley.dialup.earthlink.net ([216.244.43.57] helo=mindspring.com) by avocet.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 17movD-0003zU-00; Wed, 04 Sep 2002 22:11:16 -0700 Message-ID: <3D76E737.B46FDA1E@mindspring.com> Date: Wed, 04 Sep 2002 22:10:15 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Giorgos Keramidas Cc: Bruce Evans , Julian Elischer , arch@FreeBSD.ORG Subject: Re: Process/thread states. References: <20020904194643.H914-100000@gamplex.bde.org> <20020905042733.GE8069@hades.hell.gr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Giorgos Keramidas wrote: > if ((td->td_wchan == 0) && (td->td_state & TDS_RUNNING || > td->td_state & TDS_SUSPENDED)) > > It's not bad to know what is going on `within' the td struct, imho. if ((td->td_wchan == 0) && (td->td_state & (TDS_RUNNING|TDS_SUSPENDED))) is more natural. Neither one of these works properly if there is more than one bit hidden in either of these; you have to get a lot more complicated: if ((td->td_wchan == 0) && ((td->td_state & TDS_RUNNING) == TDS_RUNNING || (td->td_state & TDS_SUSPENDED) == TDS_SUSPENDED)) That *still* doesn't work if, say, TDS_XXX is a superset of the bits in TDS_SUSPENDED. I personally dislike the idea of combined bits, without explicit equality tests. The problem that's trying to be solved here is the one of how do you represent a combinatorial state in a single comparison, and the equivalency of one combinatorial state and another for the purposes of whether or not some code should be run (as in this specific case). Te reality is probably that this state should be explicitly multiplied out in the code, so that it becomes a single value compare. The overall impact on the code of doing this is large, so it seems that people are reluctant to take that step to get a single compare against an explicit state. I've often though it would be useful to have a "switch"-type statement that operated on bit fields in the C language, e.g.: bitset( foo) { case FOO_BIT_ONE: ... case FOO_BIT_TWO: ... case FOO_BIT_THREE: ... default: ... } Until something like that shows up, though, I think we will pretty much have to "lump it", and refactor the code. PS: If anyone adds this, I also vote for the inclusion of an "^^" operator... ;^). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message