summaryrefslogtreecommitdiff
path: root/shared/check_exist.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:08:42 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:08:42 +0200
commitc32707148292d104c66276b43796d6057c8c7a5d (patch)
treebb83513f4aff24153e21a4ec92e34e4c27651b1f /shared/check_exist.cpp
parent3.9 (diff)
downloadFreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.gz
FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.tar.bz2
FreeFileSync-c32707148292d104c66276b43796d6057c8c7a5d.zip
3.10
Diffstat (limited to 'shared/check_exist.cpp')
-rw-r--r--shared/check_exist.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/shared/check_exist.cpp b/shared/check_exist.cpp
index fcb865fd..8bc629b5 100644
--- a/shared/check_exist.cpp
+++ b/shared/check_exist.cpp
@@ -1,34 +1,42 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2010 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+//
#include "check_exist.h"
#include "file_handling.h"
-#include <boost/thread.hpp>
+#include "boost_thread_wrap.h" //include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
+/*
#ifdef __MINGW32__
//oh well, nothing is for free...
//https://svn.boost.org/trac/boost/ticket/4258
-#warning fix this issue at some time...
-extern "C" void tss_cleanup_implemented() {}
+extern "C" void tss_cleanup_implemented() {};
#endif
-
+*/
namespace
{
+typedef Zbase<Zchar, StorageDeepCopy> BasicString; //thread safe string class
+
template <bool (*testExist)(const Zstring&)>
class ExistenceChecker
{
public:
- ExistenceChecker(const Zstring& filename, const boost::shared_ptr<bool>& isExisting) :
- filename_(filename.c_str()), //deep copy: worker thread may run longer than main! avoid shared data
- isExisting_(isExisting) {} //not accessed during thread run
+ ExistenceChecker(const BasicString& filename, const boost::shared_ptr<bool>& isExisting) :
+ filename_(filename), //deep copy: worker thread may run longer than main! avoid shared data
+ isExisting_(isExisting) {} //not accessed during thread run
void operator()()
{
- *isExisting_ = testExist(filename_); //throw()
+ *isExisting_ = testExist(filename_.c_str()); //throw()
}
private:
- const Zstring filename_; //no reference, lifetime not known
+ const BasicString filename_; //no referencing, 'cause lifetime not known!
boost::shared_ptr<bool> isExisting_;
};
@@ -40,8 +48,8 @@ util::ResultExist checkExistence(const Zstring& objName, size_t timeout) //timeo
boost::shared_ptr<bool> isExisting(new bool(false));
- ExistenceChecker<fun> task(objName, isExisting);
- boost::thread worker(task);
+ ExistenceChecker<fun> task(objName.c_str(), isExisting);
+ boost::thread worker(task); //note: task is copied => using thread safe string!
if (worker.timed_join(boost::posix_time::milliseconds(timeout)))
return *isExisting ? EXISTING_TRUE : EXISTING_FALSE;
@@ -56,7 +64,7 @@ util::ResultExist checkExistence(const Zstring& objName, size_t timeout) //timeo
#warning migrate this at some time...
#endif
/*
- unfortunately packaged_task/future is not mature enough to be used...
+ unfortunately packaged_task/future is not mature enough to be used...
boost::packaged_task<bool> pt(boost::bind(fun, objName.c_str())); //attention: Zstring is not thread-safe => make deep copy
boost::unique_future<bool> fut = pt.get_future();
bgstack15