OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMultiThreadSequencer.h
Go to the documentation of this file.
1 //**************************************************************************************************
2 // OSSIM -- Open Source Software Image Map
3 //
4 // LICENSE: See top level LICENSE.txt file.
5 //
6 // AUTHOR: Oscar Kramer
7 //
8 // $Id$
9 //**************************************************************************************************
10 #ifndef ossimMultiThreadSequencer_HEADER
11 #define ossimMultiThreadSequencer_HEADER
12 
14 #include <ossim/base/ossimIpt.h>
18 #include <ossim/base/Thread.h>
19 #include <ossim/base/Block.h>
20 #include <mutex>
21 //*************************************************************************************************
25 //*************************************************************************************************
27 {
28 public:
30  ossim_uint32 num_threads=0,
31  ossimObject* owner=NULL);
32 
33  virtual ~ossimMultiThreadSequencer();
34 
37  virtual void setToStartOfSequence();
38 
42 
45  void setNumberOfThreads(ossim_uint32 num_threads);
46 
48  ossim_uint32 getNumberOfThreads() const { return m_numThreads; }
49 
51  ossim_uint32 maxCacheSize() const { return m_maxCacheSize; }
52  bool loadState(const ossimKeywordlist& kwl, const char* prefix);
53  void setUseSharedHandlers(bool use_shared_handlers);
54  void setCacheTileSize(ossim_uint32 cache_tile_size);
55  void setUseCache(bool use_cache);
56 
57  // FOR DEBUG:
60  double d_idleTime1;
61  double d_idleTime2;
62  double d_idleTime3;
63  double d_idleTime4;
64  double d_idleTime5;
65  double d_idleTime6;
66  double d_jobGetTileT;
67  double handlerGetTileT();
70  bool d_useCache;
71 
72 protected:
73 
74  // Associates a job with a tile ID for quick access to its tile data when finished:
75  typedef std::map<ossim_uint32 /*tile_ID*/, ossimRefPtr<ossimImageData> > TileCache;
76 
78  class ossimGetTileJob : public ossimJob
79  {
80  public:
82  : m_tileID(tile_id),
83  m_chainID(chain_id),
84  m_sequencer(sequencer),
85  t_launchNewJob(true) {}
86 protected:
87  virtual void run();
88 
89  private:
93 
94  bool t_launchNewJob; //### for experimental purposes
95  friend class ossimMultiThreadSequencer; //### for experimental purposes
96  };
97  friend class ossimGetTileJob;
98 
101  {
102  public:
104  virtual void finished(std::shared_ptr<ossimJob> job)
105  {
106  if (job != NULL)
107  job->finished();
108  }
109  };
110 
113  void initJobs();
114 
118  void setTileInCache(ossim_uint32 tile_id, ossimImageData* tile, ossim_uint32 chain_id, double dt /*for debug*/);
119 
122  void nextJob(ossim_uint32 chain_id);
123 
125  void print(ostringstream& msg) const;
126 
128  std::shared_ptr<ossimJobMultiThreadQueue> m_jobMtQueue;
130  std::shared_ptr<ossimGetTileCallback> m_callback;
135  mutable std::mutex m_cacheMutex;
136  mutable std::mutex m_jobMutex;
138  ossim::Block m_getTileBlock; //<! Blocks execution of main thread while waiting for tile to become available
139  ossim::Block m_nextJobBlock; //<! Blocks execution of worker threads
140 
141  // FOR DEBUG:
142  mutable std::mutex d_printMutex;
143  mutable std::mutex d_timerMutex;
147  double d_t1;
148 };
149 
150 #endif
ossim_uint32 getNumberOfThreads() const
Fetches the number of threads being used. Useful when this object decides the quantity.
ossim_uint32 m_nextTileID
ID of next tile to be threaded, different from base class&#39; theCurrentTileNumber.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
#define OSSIMDLLEXPORT
Represents serializable keyword/value map.
std::shared_ptr< ossimGetTileCallback > m_callback
Private class representing a getTile job.
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
ossimGetTileJob(ossim_uint32 tile_id, ossim_uint32 chain_id, ossimMultiThreadSequencer &sequencer)
ossimRefPtr< ossimImageChainMtAdaptor > m_inputChain
Same as base class&#39; theInputConnection.
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
Private class for getTile job callbacks.
ossim_uint32 maxCacheSize() const
Accessed for performance logging.
unsigned int ossim_uint32
This is a very simple block interface.
Definition: Block.h:45
std::map< ossim_uint32, ossimRefPtr< ossimImageData > > TileCache
std::shared_ptr< ossimJobMultiThreadQueue > m_jobMtQueue
bool loadState(const ossimKeywordlist &kwl, const char *prefix)
Method to the load (recreate) the state of an object from a keyword list.
TileCache m_tileCache
Saves tiles output by threaded jobs.
This class manages the sequencing of tile requests across multiple threads.
This is the job callback interface It allows one to attach and listen for different states of the job...
Definition: ossimJob.h:149
This is the job callback interface It allows one to attach and listen for different states of the job...
Definition: ossimJob.h:68
virtual void finished(std::shared_ptr< ossimJob > job)