Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Sep 2002 22:10:15 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Giorgos Keramidas <keramida@ceid.upatras.gr>
Cc:        Bruce Evans <bde@zeta.org.au>, Julian Elischer <julian@elischer.org>, arch@FreeBSD.ORG
Subject:   Re: Process/thread states.
Message-ID:  <3D76E737.B46FDA1E@mindspring.com>
References:  <Pine.BSF.4.21.0209032347000.26122-100000@InterJet.elischer.org> <20020904194643.H914-100000@gamplex.bde.org> <20020905042733.GE8069@hades.hell.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D76E737.B46FDA1E>