Re: help me.
- From: "H. S. Lahman" <h.lahman@xxxxxxxxxxx>
- Date: Fri, 22 Sep 2006 19:51:15 GMT
Responding to Wu...
If I post in wrong place. forgive me.
I hope some one can Refactor following code for me!
We have a system with 6 application. One application (Named it
ContrlPanel) is a control center, it get command from UI and order
other application do some work. All these application communicate with
each other through share memory. so now all job of ControlPanel is like
following.
1. poll the state of A.
2. according to the state of A order B to do something.
3. poll the state of C.
4. according to the state of C order E or F to do something.
because all this job with share memory need do again and again till
succeed.(try to lock it etc).
so we get some code like following
XXXXThread
{
while (!exit)
{
switch(state) {
case GETING_A_STATE:
if (GetAState()) {
state = DOING_SOMETHING_A;
}
break;
case DOING_SOMETHING_A:
if (DoSomeA()) {
state = GET_C_STATE;
}
break;
case GET_C_STATE:
....
}
}
}
How does 'exit' get set? Is that related to why the loop was done this way? (I assume it is just bound to a register that indicates whether shared memory is locked.)
It seems to me this is just overcomplicating things. It is also using 'state' to describe two different kinds of conditions and that sort of overloading is usually fragile. So I would try a simpler polling loop:
while (!exit)
{
if (GetAState())
DoSomeA()
if (GetCState())
DoSomeC()
...
}
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
hsl@xxxxxxxxxxxxxxxxx
Pathfinder Solutions
http://www.pathfindermda.com
blog: http://pathfinderpeople.blogs.com/hslahman
"Model-Based Translation: The Next Step in Agile Development". Email
info@xxxxxxxxxxxxxxxxx for your copy.
Pathfinder is hiring: http://www.pathfindermda.com/about_us/careers_pos3.php.
(888)OOA-PATH
.
- Follow-Ups:
- Re: help me.
- From: Leon Wu
- Re: help me.
- References:
- help me.
- From: Leon Wu
- help me.
- Prev by Date: Advice on finding more material
- Next by Date: Re: OO is not that great: many repeated codes
- Previous by thread: help me.
- Next by thread: Re: help me.
- Index(es):
Relevant Pages
|