#ifndef __ShutdownRequested_h_ #define __ShutdownRequested_h_ #include "../shared/PipeConditionVar.h" // Some processes try to run forever. High level modules can request a // shutdown message, but it's harder for support modules, like the database. // By default the database module will retry a query until it succeeds. While // a thread is waiting on a result from the database, it won't request anything // new from its input queue. So it won't know that we are trying to shut down. // // The downside is that anyone using the database, or a similar resource, has // to accept that the database request might have aborted, rather than // succeeded, because of this flag. So the high level request is not in // full control. It should check for the shutdown condition before trying to // review any results from the database. And it can't give do any special // processing on shutdown which might require the database. // // But it's still an improvement. This way the abort requet has to make its // way out of low level routines up through high level routines. The // alternative is to have a two way communiction from the initial shutdown // request through the high level modules to the low level modules and // back, or to risk the process locking up because its lost in one of these // low level routines. // // There really isn't a happy medium. Do you usually do infinite retries, but // when attempting to shut down you allow retries for a minute? A minute for // each module? If you have a minute total, then you really have the same // problem all over again. If one of the items shutting down gets stuck until // the timeout, then everything after that will get no time to shut down. // // Ultimately we choose this route for its simplicity. One common data // structure controls everything. Without this we'd be likely to have almost // as many shutdown sequences as we have modules. // // This is intially false, but can be set to true. bool shutdownInProgress(); // This tells everyone that we are shutting down. // Handles the people polling and waiting. void requestShutdown(); // This will wait forever for a shutdown request. void waitForShutdown(); // These are set once when a shutdown is requested. // It makes no sense to clear these. PipeConditionVar *requestShutdownConditionVar(); void releaseShutdownConditionVar(PipeConditionVar *cond); #endif