linkgraphschedule.h

Go to the documentation of this file.
00001 /* $Id: linkgraphschedule.h 25867 2013-10-15 17:32:31Z fonsinchen $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef LINKGRAPHSCHEDULE_H
00013 #define LINKGRAPHSCHEDULE_H
00014 
00015 #include "linkgraph.h"
00016 
00017 class LinkGraphJob;
00018 
00023 class ComponentHandler {
00024 public:
00028   virtual ~ComponentHandler() {}
00029 
00035   virtual void Run(LinkGraphJob &job) const = 0;
00036 };
00037 
00038 class LinkGraphSchedule {
00039 private:
00040   LinkGraphSchedule();
00041   ~LinkGraphSchedule();
00042   typedef std::list<LinkGraph *> GraphList;
00043   typedef std::list<LinkGraphJob *> JobList;
00044   friend const SaveLoad *GetLinkGraphScheduleDesc();
00045 
00046 protected:
00047   ComponentHandler *handlers[6]; 
00048   GraphList schedule;            
00049   JobList running;               
00050 
00051   void SpawnThread(LinkGraphJob *job);
00052   void JoinThread(LinkGraphJob *job);
00053 
00054 public:
00055   /* This is a tick where not much else is happening, so a small lag might go unnoticed. */
00056   static const uint SPAWN_JOIN_TICK = 21; 
00057 
00058   static LinkGraphSchedule *Instance();
00059   static void Run(void *j);
00060   static void Clear();
00061 
00062   void SpawnNext();
00063   void JoinNext();
00064   void SpawnAll();
00065   void ShiftDates(int interval);
00066 
00071   void Queue(LinkGraph *lg)
00072   {
00073     assert(LinkGraph::Get(lg->index) == lg);
00074     this->schedule.push_back(lg);
00075   }
00076 
00081   void Unqueue(LinkGraph *lg) { this->schedule.remove(lg); }
00082 };
00083 
00084 #endif /* LINKGRAPHSCHEDULE_H */