git-svn-id: svn://db.shs.com.ru/pip@308 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-01-23 07:35:59 +00:00
parent 3da003f4e0
commit 137a1e526b
2 changed files with 20 additions and 5 deletions

View File

@@ -113,6 +113,10 @@
*/
PIMutex PIIODevice::nfp_mutex;
PIMap<PIString, PIString> PIIODevice::nfp_cache;
PIIODevice::PIIODevice(): PIThread() {
mode_ = ReadOnly;
_init();
@@ -363,6 +367,7 @@ PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
if (prefix == ((const PIIODevice * )d)->fullPathPrefix()) {
PIIODevice * nd = ((const PIIODevice * )d)->copy();
if (nd) nd->configureFromFullPath(full_path.mid(prefix.length() + 3));
cacheFullPath(full_path, nd);
return nd;
}
}
@@ -371,22 +376,28 @@ PIIODevice * PIIODevice::createFromFullPath(const PIString & full_path) {
PIString PIIODevice::normalizeFullPath(const PIString & full_path) {
static PIMutex nfp_mutex;
static PIMap<PIString, PIString> nfp_cache;
PIMutexLocker nfp_ml(nfp_mutex);
nfp_mutex.lock();
PIString ret = nfp_cache.value(full_path);
if (!ret.isEmpty())
if (!ret.isEmpty()) {
nfp_mutex.unlock();
return ret;
}
nfp_mutex.unlock();
PIIODevice * d = createFromFullPath(full_path);
//piCout << "normalizeFullPath" << d;
if (d == 0) return PIString();
ret = d->constructFullPath();
delete d;
nfp_cache[full_path] = ret;
return ret;
}
void PIIODevice::cacheFullPath(const PIString & full_path, const PIIODevice * d) {
PIMutexLocker nfp_ml(nfp_mutex);
nfp_cache[full_path] = d->constructFullPath();
}
bool PIIODevice::threadedRead(uchar *readed, int size) {
// piCout << "iodevice threaded read";
if (ret_func_ != 0) return ret_func_(ret_data_, readed, size);

View File

@@ -356,6 +356,7 @@ private:
void begin();
void run();
void end() {terminate();}
static void cacheFullPath(const PIString & full_path, const PIIODevice * d);
PITimer timer;
PITimeMeasurer tm;
@@ -366,6 +367,9 @@ private:
int readed_;
bool init_, thread_started_, raise_threaded_read_;
static PIMutex nfp_mutex;
static PIMap<PIString, PIString> nfp_cache;
};
#endif // PIIODEVICE_H