dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
tilecachequeue.cpp
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #include "tilecachequeue.h"
28 
29 
30 //#define DEBUG_TILECACHEQUEUE
31 
32 namespace core {
34 {
35 
36 }
38 {
39  // QThread::wait(10000);
40 }
41 
43 {
44 #ifdef DEBUG_TILECACHEQUEUE
45  qDebug()<<"DB Do I EnqueueCacheTask"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
46 #endif //DEBUG_TILECACHEQUEUE
47  if(!tileCacheQueue.contains(task))
48  {
49 #ifdef DEBUG_TILECACHEQUEUE
50  qDebug()<<"EnqueueCacheTask"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
51 #endif //DEBUG_TILECACHEQUEUE
52  mutex.lock();
53  tileCacheQueue.enqueue(task);
54  mutex.unlock();
55  if(this->isRunning())
56  {
57 #ifdef DEBUG_TILECACHEQUEUE
58  qDebug()<<"Wake Thread";
59 #endif //DEBUG_TILECACHEQUEUE
60  //this->start(QThread::NormalPriority);
61  //waitmutex.lock();
62  waitc.wakeAll();
63  //waitmutex.unlock();
64  }
65  else
66  {
67 #ifdef DEBUG_TILECACHEQUEUE
68  qDebug()<<"Start Thread";
69 #endif //DEBUG_TILECACHEQUEUE
70  this->start(QThread::NormalPriority);
71  }
72  }
73 
74 }
75 void TileCacheQueue::run()
76 {
77 #ifdef DEBUG_TILECACHEQUEUE
78  qDebug()<<"Cache Engine Start";
79 #endif //DEBUG_TILECACHEQUEUE
80  while(true)
81  {
82  CacheItemQueue *task;
83 #ifdef DEBUG_TILECACHEQUEUE
84  qDebug()<<"Cache";
85 #endif //DEBUG_TILECACHEQUEUE
86  if(tileCacheQueue.count()>0)
87  {
88  mutex.lock();
89  task=tileCacheQueue.dequeue();
90  mutex.unlock();
91 #ifdef DEBUG_TILECACHEQUEUE
92  qDebug()<<"Cache engine Put:"<<task->GetPosition().X()<<","<<task->GetPosition().Y();
93 #endif //DEBUG_TILECACHEQUEUE
95  usleep(44);
96  delete task;
97  }
98 
99  else
100  {
101 #ifdef DEBUG_TILECACHEQUEUE
102  qDebug()<<"Cache engine BEGIN WAIT";
103 #endif //DEBUG_TILECACHEQUEUE
104  waitmutex.lock();
105  int tout=4000;
106  if(!waitc.wait(&waitmutex,tout))
107  {
108  waitmutex.unlock();
109 #ifdef DEBUG_TILECACHEQUEUE
110  qDebug()<<"Cache Engine TimeOut";
111 #endif //DEBUG_TILECACHEQUEUE
112  mutex.lock();
113  if(tileCacheQueue.count()==0)
114  {
115  mutex.unlock();
116  break;
117  }
118  mutex.unlock();
119  }
120 #ifdef DEBUG_TILECACHEQUEUE
121  qDebug()<<"Cache Engine DID NOT TimeOut";
122 #endif //DEBUG_TILECACHEQUEUE
123  waitmutex.unlock();
124  }
125  }
126 #ifdef DEBUG_TILECACHEQUEUE
127  qDebug()<<"Cache Engine Stopped";
128 #endif //DEBUG_TILECACHEQUEUE
129 }
130 
131 
132 }
qint64 X() const
Definition: point.h:51
static Cache * Instance()
Definition: cache.cpp:34
core::Point GetPosition()
MapType::Types GetMapType()
PureImageCache ImageCache
Definition: cache.h:41
QQueue< CacheItemQueue * > tileCacheQueue
void EnqueueCacheTask(CacheItemQueue *task)
bool PutImageToCache(const QByteArray &tile, const MapType::Types &type, const core::Point &pos, const int &zoom)
qint64 Y() const
Definition: point.h:52