Skip to content

Commit e5d1790

Browse files
committed
Merge pull request opencv#10018 from alalek:ocl_binary_cache
2 parents fed2a27 + 8e6280f commit e5d1790

File tree

7 files changed

+1471
-51
lines changed

7 files changed

+1471
-51
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ class CV_EXPORTS Context
261261
void setUseSVM(bool enabled);
262262

263263
struct Impl;
264+
inline Impl* getImpl() const { return (Impl*)p; }
265+
//protected:
264266
Impl* p;
265267
};
266268

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_UTILS_FILESYSTEM_HPP
6+
#define OPENCV_UTILS_FILESYSTEM_HPP
7+
8+
namespace cv { namespace utils { namespace fs {
9+
10+
11+
CV_EXPORTS bool exists(const cv::String& path);
12+
CV_EXPORTS bool isDirectory(const cv::String& path);
13+
14+
15+
CV_EXPORTS cv::String getcwd();
16+
17+
18+
CV_EXPORTS bool createDirectory(const cv::String& path);
19+
CV_EXPORTS bool createDirectories(const cv::String& path);
20+
21+
#ifdef __OPENCV_BUILD
22+
// TODO
23+
//CV_EXPORTS cv::String getTempDirectory();
24+
25+
/**
26+
* @brief Returns directory to store OpenCV cache files
27+
* Create sub-directory in common OpenCV cache directory if it doesn't exist.
28+
* @param sub_directory_name name of sub-directory. NULL or "" value asks to return root cache directory.
29+
* @param configuration_name optional name of configuration parameter name which overrides default behavior.
30+
* @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user.
31+
*/
32+
CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL);
33+
34+
#endif
35+
36+
}}} // namespace
37+
38+
#endif // OPENCV_UTILS_FILESYSTEM_HPP
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_UTILS_FILESYSTEM_PRIVATE_HPP
6+
#define OPENCV_UTILS_FILESYSTEM_PRIVATE_HPP
7+
8+
// TODO Move to CMake?
9+
#ifndef OPENCV_HAVE_FILESYSTEM_SUPPORT
10+
# if defined(__EMSCRIPTEN__) || defined(__native_client__)
11+
/* no support */
12+
# elif defined __ANDROID__ || defined __linux__ || defined _WIN32 || \
13+
defined __FreeBSD__ || defined __bsdi__
14+
# define OPENCV_HAVE_FILESYSTEM_SUPPORT 1
15+
# elif defined(__APPLE__)
16+
# include <TargetConditionals.h>
17+
# if (defined(TARGET_OS_OSX) && TARGET_OS_OSX) || (!defined(TARGET_OS_OSX) && !TARGET_OS_IPHONE)
18+
# define OPENCV_HAVE_FILESYSTEM_SUPPORT 1 // OSX only
19+
# endif
20+
# else
21+
/* unknown */
22+
# endif
23+
# ifndef OPENCV_HAVE_FILESYSTEM_SUPPORT
24+
# define OPENCV_HAVE_FILESYSTEM_SUPPORT 0
25+
# endif
26+
#endif
27+
28+
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
29+
namespace cv { namespace utils { namespace fs {
30+
31+
/**
32+
* File-based lock object.
33+
*
34+
* Provides interprocess synchronization mechanism.
35+
* Platform dependent.
36+
*
37+
* Supports multiple readers / single writer access pattern (RW / readers–writer / shared-exclusive lock).
38+
*
39+
* File must exist.
40+
* File can't be re-used (for example, I/O operations via std::fstream is not safe)
41+
*/
42+
class CV_EXPORTS FileLock {
43+
public:
44+
explicit FileLock(const char* fname);
45+
~FileLock();
46+
47+
void lock(); //< acquire exclusive (writer) lock
48+
void unlock(); //< release exclusive (writer) lock
49+
50+
void lock_shared(); //< acquire sharable (reader) lock
51+
void unlock_shared(); //< release sharable (reader) lock
52+
53+
struct Impl;
54+
protected:
55+
Impl* pImpl;
56+
57+
private:
58+
FileLock(const FileLock&); // disabled
59+
FileLock& operator=(const FileLock&); // disabled
60+
};
61+
62+
}}} // namespace
63+
#endif
64+
#endif // OPENCV_UTILS_FILESYSTEM_PRIVATE_HPP
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_UTILS_LOCK_HPP
6+
#define OPENCV_UTILS_LOCK_HPP
7+
8+
namespace cv { namespace utils {
9+
10+
11+
/** @brief A simple scoped lock (RAII-style locking for exclusive/write access).
12+
*
13+
* Emulate std::lock_guard (C++11), partially std::unique_lock (C++11),
14+
*/
15+
template <class _Mutex>
16+
class lock_guard {
17+
public:
18+
typedef _Mutex Mutex;
19+
20+
explicit inline lock_guard(Mutex &m) : mutex_(&m) { mutex_->lock(); }
21+
22+
inline ~lock_guard() { if (mutex_) mutex_->unlock(); }
23+
24+
inline void release()
25+
{
26+
CV_DbgAssert(mutex_);
27+
mutex_->unlock();
28+
mutex_ = NULL;
29+
}
30+
31+
private:
32+
Mutex* mutex_;
33+
34+
private:
35+
lock_guard(const lock_guard&); // disabled
36+
lock_guard& operator=(const lock_guard&); // disabled
37+
};
38+
39+
40+
/** @brief A shared scoped lock (RAII-style locking for shared/reader access).
41+
*
42+
* Emulate boost::shared_lock_guard, subset of std::shared_lock (C++14),
43+
*/
44+
template <class _Mutex>
45+
class shared_lock_guard {
46+
public:
47+
typedef _Mutex Mutex;
48+
49+
explicit inline shared_lock_guard(Mutex &m) : mutex_(&m) { mutex_->lock_shared(); }
50+
51+
inline ~shared_lock_guard() { if (mutex_) mutex_->unlock_shared(); }
52+
53+
inline void release()
54+
{
55+
CV_DbgAssert(mutex_);
56+
mutex_->unlock_shared();
57+
mutex_ = NULL;
58+
}
59+
60+
protected:
61+
Mutex* mutex_;
62+
63+
private:
64+
shared_lock_guard(const shared_lock_guard&); // disabled
65+
shared_lock_guard& operator=(const shared_lock_guard&); // disabled
66+
};
67+
68+
69+
/** @brief An optional simple scoped lock (RAII-style locking for exclusive/write access).
70+
*
71+
* Doesn't lock if mutex pointer is NULL.
72+
*
73+
* @sa lock_guard
74+
*/
75+
template <class _Mutex>
76+
class optional_lock_guard {
77+
public:
78+
typedef _Mutex Mutex;
79+
80+
explicit inline optional_lock_guard(Mutex* m) : mutex_(m) { if (mutex_) mutex_->lock(); }
81+
82+
inline ~optional_lock_guard() { if (mutex_) mutex_->unlock(); }
83+
84+
private:
85+
Mutex* mutex_;
86+
87+
private:
88+
optional_lock_guard(const optional_lock_guard&); // disabled
89+
optional_lock_guard& operator=(const optional_lock_guard&); // disabled
90+
};
91+
92+
93+
/** @brief An optional shared scoped lock (RAII-style locking for shared/reader access).
94+
*
95+
* Doesn't lock if mutex pointer is NULL.
96+
*
97+
* @sa shared_lock_guard
98+
*/
99+
template <class _Mutex>
100+
class optional_shared_lock_guard {
101+
public:
102+
typedef _Mutex Mutex;
103+
104+
explicit inline optional_shared_lock_guard(Mutex* m) : mutex_(m) { if (mutex_) mutex_->lock_shared(); }
105+
106+
inline ~optional_shared_lock_guard() { if (mutex_) mutex_->unlock_shared(); }
107+
108+
protected:
109+
Mutex* mutex_;
110+
111+
private:
112+
optional_shared_lock_guard(const optional_shared_lock_guard&); // disabled
113+
optional_shared_lock_guard& operator=(const optional_shared_lock_guard&); // disabled
114+
};
115+
116+
117+
}} // namespace
118+
119+
#endif // OPENCV_UTILS_LOCK_HPP

modules/core/src/glob.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#include "precomp.hpp"
4444

45+
#include "opencv2/core/utils/filesystem.hpp"
46+
4547
#if defined _WIN32 || defined WINCE
4648
# include <windows.h>
4749
const char dir_separators[] = "/\\";
@@ -169,6 +171,12 @@ static bool isDir(const cv::String& path, DIR* dir)
169171
#endif
170172
}
171173

174+
bool cv::utils::fs::isDirectory(const cv::String& path)
175+
{
176+
CV_INSTRUMENT_REGION()
177+
return isDir(path, NULL);
178+
}
179+
172180
static bool wildcmp(const char *string, const char *wild)
173181
{
174182
// Based on wildcmp written by Jack Handy - <A href="mailto:jakkhandy@hotmail.com">jakkhandy@hotmail.com</A>

0 commit comments

Comments
 (0)