Merge branch 'master' of https://DennisOSRM@github.com/DennisOSRM/Project-OSRM.git
This commit is contained in:
commit
9c1caba2fa
@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
TemporaryStorage::TemporaryStorage() {
|
TemporaryStorage::TemporaryStorage() {
|
||||||
try {
|
try {
|
||||||
tempDirectory = boost::filesystem3::temp_directory_path();
|
tempDirectory = boost::filesystem::temp_directory_path();
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
ERR("could not retrieve location of temporary path: " << e.what());
|
ERR("could not retrieve location of temporary path: " << e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ void TemporaryStorage::removeAll() {
|
|||||||
for(int slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID)
|
for(int slotID = 0; slotID < vectorOfStreamDatas.size(); ++slotID)
|
||||||
deallocateSlot(slotID);
|
deallocateSlot(slotID);
|
||||||
|
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
ERR("could not retrieve location of temporary path: " << e.what());
|
ERR("could not retrieve location of temporary path: " << e.what());
|
||||||
}
|
}
|
||||||
vectorOfStreamDatas.clear();
|
vectorOfStreamDatas.clear();
|
||||||
@ -56,7 +56,7 @@ int TemporaryStorage::allocateSlot() {
|
|||||||
try {
|
try {
|
||||||
vectorOfStreamDatas.push_back(StreamData());
|
vectorOfStreamDatas.push_back(StreamData());
|
||||||
//INFO("created new temporary file: " << vectorOfStreamDatas.back().pathToTemporaryFile);
|
//INFO("created new temporary file: " << vectorOfStreamDatas.back().pathToTemporaryFile);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
return vectorOfStreamDatas.size() - 1;
|
return vectorOfStreamDatas.size() - 1;
|
||||||
@ -66,15 +66,15 @@ void TemporaryStorage::deallocateSlot(int slotID) {
|
|||||||
try {
|
try {
|
||||||
StreamData & data = vectorOfStreamDatas[slotID];
|
StreamData & data = vectorOfStreamDatas[slotID];
|
||||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||||
if(!boost::filesystem3::exists(data.pathToTemporaryFile)) {
|
if(!boost::filesystem::exists(data.pathToTemporaryFile)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(data.streamToTemporaryFile->is_open())
|
if(data.streamToTemporaryFile->is_open())
|
||||||
data.streamToTemporaryFile->close();
|
data.streamToTemporaryFile->close();
|
||||||
|
|
||||||
//INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile);
|
//INFO("deallocating slot " << slotID << " and its file: " << data.pathToTemporaryFile);
|
||||||
boost::filesystem3::remove(data.pathToTemporaryFile);
|
boost::filesystem::remove(data.pathToTemporaryFile);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ void TemporaryStorage::writeToSlot(int slotID, char * pointer, std::streamsize s
|
|||||||
if(!data.writeMode)
|
if(!data.writeMode)
|
||||||
ERR("Writing after first read is not allowed");
|
ERR("Writing after first read is not allowed");
|
||||||
data.streamToTemporaryFile->write(pointer, size);
|
data.streamToTemporaryFile->write(pointer, size);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,46 +99,46 @@ void TemporaryStorage::readFromSlot(int slotID, char * pointer, std::streamsize
|
|||||||
data.streamToTemporaryFile->seekg(0, data.streamToTemporaryFile->beg);
|
data.streamToTemporaryFile->seekg(0, data.streamToTemporaryFile->beg);
|
||||||
}
|
}
|
||||||
data.streamToTemporaryFile->read(pointer, size);
|
data.streamToTemporaryFile->read(pointer, size);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned TemporaryStorage::getFreeBytesOnTemporaryDevice() {
|
unsigned TemporaryStorage::getFreeBytesOnTemporaryDevice() {
|
||||||
boost::filesystem3::space_info tempSpaceInfo;
|
boost::filesystem::space_info tempSpaceInfo;
|
||||||
try {
|
try {
|
||||||
tempSpaceInfo = boost::filesystem3::space(tempDirectory);
|
tempSpaceInfo = boost::filesystem::space(tempDirectory);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
return tempSpaceInfo.available;
|
return tempSpaceInfo.available;
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::filesystem3::fstream::pos_type TemporaryStorage::tell(int slotID) {
|
boost::filesystem::fstream::pos_type TemporaryStorage::tell(int slotID) {
|
||||||
boost::filesystem3::fstream::pos_type position;
|
boost::filesystem::fstream::pos_type position;
|
||||||
try {
|
try {
|
||||||
StreamData & data = vectorOfStreamDatas[slotID];
|
StreamData & data = vectorOfStreamDatas[slotID];
|
||||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||||
position = data.streamToTemporaryFile->tellp();
|
position = data.streamToTemporaryFile->tellp();
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
// INFO("telling position: " << position);
|
// INFO("telling position: " << position);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemporaryStorage::abort(boost::filesystem3::filesystem_error& e) {
|
void TemporaryStorage::abort(boost::filesystem::filesystem_error& e) {
|
||||||
removeAll();
|
removeAll();
|
||||||
// ERR("I/O Error occured: " << e.what());
|
// ERR("I/O Error occured: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemporaryStorage::seek(int slotID, boost::filesystem3::fstream::pos_type position) {
|
void TemporaryStorage::seek(int slotID, boost::filesystem::fstream::pos_type position) {
|
||||||
try {
|
try {
|
||||||
StreamData & data = vectorOfStreamDatas[slotID];
|
StreamData & data = vectorOfStreamDatas[slotID];
|
||||||
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
boost::mutex::scoped_lock lock(*data.readWriteMutex);
|
||||||
data.streamToTemporaryFile->seekg(position);
|
data.streamToTemporaryFile->seekg(position);
|
||||||
// INFO("seeking to position: " << position);
|
// INFO("seeking to position: " << position);
|
||||||
} catch(boost::filesystem3::filesystem_error & e) {
|
} catch(boost::filesystem::filesystem_error & e) {
|
||||||
abort(e);
|
abort(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,31 @@
|
|||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
//This is one big workaround for latest boost renaming woes.
|
||||||
|
|
||||||
|
#ifndef BOOST_FILESYSTEM_VERSION
|
||||||
|
#warning Boost Installation with Filesystem3 (>=1.44) is required, activating workaround
|
||||||
|
#include <cstdio>
|
||||||
|
namespace boost {
|
||||||
|
namespace filesystem {
|
||||||
|
inline path temp_directory_path() {
|
||||||
|
char * buffer;
|
||||||
|
buffer = tmpnam (NULL);
|
||||||
|
|
||||||
|
return path(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline path unique_path(const path&) {
|
||||||
|
return temp_directory_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_FILESYSTEM_VERSION 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class implements a singleton file storage for temporary data.
|
* This class implements a singleton file storage for temporary data.
|
||||||
* temporary slots can be accessed by other objects through an int
|
* temporary slots can be accessed by other objects through an int
|
||||||
@ -39,7 +64,8 @@
|
|||||||
* Access is sequential, which means, that there is no random access
|
* Access is sequential, which means, that there is no random access
|
||||||
* -> Data is written in first phase and reread in second.
|
* -> Data is written in first phase and reread in second.
|
||||||
*/
|
*/
|
||||||
static boost::filesystem3::path tempDirectory;
|
|
||||||
|
static boost::filesystem::path tempDirectory;
|
||||||
static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%");
|
static std::string TemporaryFilePattern("OSRM-%%%%-%%%%-%%%%");
|
||||||
class TemporaryStorage {
|
class TemporaryStorage {
|
||||||
public:
|
public:
|
||||||
@ -52,8 +78,8 @@ public:
|
|||||||
void readFromSlot(int slotID, char * pointer, std::streamsize size);
|
void readFromSlot(int slotID, char * pointer, std::streamsize size);
|
||||||
//returns the number of free bytes
|
//returns the number of free bytes
|
||||||
unsigned getFreeBytesOnTemporaryDevice();
|
unsigned getFreeBytesOnTemporaryDevice();
|
||||||
boost::filesystem3::fstream::pos_type tell(int slotID);
|
boost::filesystem::fstream::pos_type tell(int slotID);
|
||||||
void seek(int slotID, boost::filesystem3::fstream::pos_type);
|
void seek(int slotID, boost::filesystem::fstream::pos_type);
|
||||||
void removeAll();
|
void removeAll();
|
||||||
private:
|
private:
|
||||||
TemporaryStorage();
|
TemporaryStorage();
|
||||||
@ -61,19 +87,19 @@ private:
|
|||||||
TemporaryStorage& operator=(TemporaryStorage const &) {
|
TemporaryStorage& operator=(TemporaryStorage const &) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void abort(boost::filesystem3::filesystem_error& e);
|
void abort(boost::filesystem::filesystem_error& e);
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
struct StreamData {
|
struct StreamData {
|
||||||
bool writeMode;
|
bool writeMode;
|
||||||
boost::filesystem3::path pathToTemporaryFile;
|
boost::filesystem::path pathToTemporaryFile;
|
||||||
boost::shared_ptr<boost::filesystem3::fstream> streamToTemporaryFile;
|
boost::shared_ptr<boost::filesystem::fstream> streamToTemporaryFile;
|
||||||
boost::shared_ptr<boost::mutex> readWriteMutex;
|
boost::shared_ptr<boost::mutex> readWriteMutex;
|
||||||
StreamData() :
|
StreamData() :
|
||||||
writeMode(true),
|
writeMode(true),
|
||||||
pathToTemporaryFile (boost::filesystem3::unique_path(tempDirectory.append(TemporaryFilePattern.begin(), TemporaryFilePattern.end()))),
|
pathToTemporaryFile (boost::filesystem::unique_path(tempDirectory.append(TemporaryFilePattern.begin(), TemporaryFilePattern.end()))),
|
||||||
streamToTemporaryFile(new boost::filesystem3::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
|
streamToTemporaryFile(new boost::filesystem::fstream(pathToTemporaryFile, std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary)),
|
||||||
readWriteMutex(new boost::mutex)
|
readWriteMutex(new boost::mutex)
|
||||||
{
|
{
|
||||||
if(streamToTemporaryFile->fail())
|
if(streamToTemporaryFile->fail())
|
||||||
|
Loading…
Reference in New Issue
Block a user