From 137a1e526b083a9d3b8c82ed995247354af703f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Mon, 23 Jan 2017 07:35:59 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@308 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/io/piiodevice.cpp | 21 ++++++++++++++++----- src/io/piiodevice.h | 4 ++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/io/piiodevice.cpp b/src/io/piiodevice.cpp index 2b03f7d9..75d460f3 100755 --- a/src/io/piiodevice.cpp +++ b/src/io/piiodevice.cpp @@ -113,6 +113,10 @@ */ +PIMutex PIIODevice::nfp_mutex; +PIMap 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 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); diff --git a/src/io/piiodevice.h b/src/io/piiodevice.h index af2da378..50502678 100755 --- a/src/io/piiodevice.h +++ b/src/io/piiodevice.h @@ -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 nfp_cache; + }; #endif // PIIODEVICE_H