// JobUpdater.h #ifndef dial__JobUpdater_H #define dial__JobUpdater_H // David Adams // October 2003 // // Class to update the jobs in a scheduler. // // Implementation uses a thread so that scheduler can be used // in parallel. #include class PThreadCondition; namespace dial { class Scheduler; class JobUpdater { public: // Embededed classes. class Imp; private: // data Imp* pimp; public: // functions // Constructor. // Argument is the minimum interval (in sec) between updates. JobUpdater(Scheduler& sch, int interval =1); // Destructor. ~JobUpdater(); // Return the implementation class. Imp& imp(); // Start updating. // This starts a new thread. // If lockit is true, the condition mutex is locked before update. int start(bool lockit =false); // Stop updating. // This is blocked until the end of the current loop. // The updating thread is signaled to end. // If locked, the condition mutex is unlocked to allow the thread // to terminate. // The inital condition mutex state is returned in was_locked. int stop(bool* pwas_locked =0); // Return the condition mutex. // This is locked at the start of each loop and unlocked and // signalled (broadcast) at the end of each loop. PThreadCondition& condition(); // Validity. // Scheduler must be valid. bool is_valid() const; // Is updating. bool is_updating() const; // Error status. // Zero for a valid updater. int error() const; // Return the scheduler. const Scheduler& scheduler() const; // Number of loops over scheduler jobs. unsigned long loop_count() const; }; } // end namespace // Output stream. std::ostream& operator<<(std::ostream& lhs, const dial::JobUpdater& rhs); #endif