Date: Mon, 26 Aug 2002 17:40:43 -0700 (PDT) From: Archie Cobbs <archie@dellroad.org> To: Julian Elischer <julian@elischer.org> Cc: arch@FreeBSD.ORG Subject: Re: Process/thread states. Message-ID: <200208270040.g7R0ehu36981@arch20m.dellroad.org> In-Reply-To: <Pine.BSF.4.21.0208261603020.83598-100000@InterJet.elischer.org> "from Julian Elischer at Aug 26, 2002 04:42:55 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
Julian Elischer writes:
> #define TD_ST_SUSPQ 0x01 /* uses runq field */
> #define TD_ST_RUNQ 0x02 /* uses runq field */
> #define TD_ST_RUNNING 0x03 /* uses no (virtual) field */
> #define TD_ST_MTX 0x04 /* uses mtx field */
> #define TD_ST_RQ_MASK 0x07 /* mask of non sleep states */
> #define TD_ST_SLPQ 0x08 /* uses slpq field */
> enum thread_state {
> TDS_UNQUEUED = 0x00,
> TDS_SLP = TD_ST_SLPQ,
> TDS_RUNQ = TD_ST_RUNQ,
> TDS_RUNNING = TD_ST_RUNNING,
> TDS_SUSPENDED = TD_ST_SUSPQ,
> TDS_MTX = TD_ST_MTX,
> TDS_SUSP_SLP = TD_ST_SUSPQ|TD_ST_SLPQ,
> TDS_RUN_SLP = TD_ST_RUNNING|TD_ST_SLPQ,
> TDS_RUNQ_SLP = TD_ST_RUNQ|TD_ST_SLPQ,
> TDS_MTX_SLP = TD_ST_MTX|TD_ST_SLPQ,
> TDS_SWAPPING = TD_ST_SLPQ|TD_ST_RQ_MASK + 1,
> TDS_IWAIT, /* needed? */
> TDS_SURPLUS /* needed? */
> };
I like your idea.. it makes things clearer because they are more
explicit. Whenever "implicit developer knowledge" is required to
do something correctly that's more opportunity for bugs.
If you comment those flags in the header file(s) really well,
that's even better. Especially all of the cases where there is
any duplicate or inter-dependent state, which can be evil.
E.g., if TDS_SLP always implies wchan != NULL, then that should be
commented somewhere.
That is, any 'trickiness' in an object's state like depedence between
fields or special invariants should either be very clearly documented
or else hidden behind an object-like functional interface (like Alfred
suggested).
-Archie
__________________________________________________________________________
Archie Cobbs * Packet Design * http://www.packetdesign.com
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?200208270040.g7R0ehu36981>
