4
4
// http://www.boost.org/LICENSE_1_0.txt)
5
5
6
6
#include < memory>
7
+ #include < thread>
7
8
#include < boost/network/include/http/server.hpp>
8
- #include < boost/thread.hpp>
9
9
#include < sys/mman.h>
10
10
#include < sys/types.h>
11
11
#include < sys/stat.h>
@@ -28,7 +28,7 @@ struct file_cache {
28
28
std::string doc_root_;
29
29
region_map regions;
30
30
meta_map file_headers;
31
- boost::shared_mutex cache_mutex;
31
+ std::mutex cache_mutex;
32
32
33
33
explicit file_cache (std::string doc_root) : doc_root_(std::move(doc_root)) {}
34
34
@@ -39,12 +39,12 @@ struct file_cache {
39
39
}
40
40
41
41
bool has (std::string const &path) {
42
- boost::shared_lock<boost::shared_mutex > lock (cache_mutex);
42
+ std::unique_lock<std::mutex > lock (cache_mutex);
43
43
return regions.find (doc_root_ + path) != regions.end ();
44
44
}
45
45
46
46
bool add (std::string const &path) {
47
- boost::upgrade_lock<boost::shared_mutex > lock (cache_mutex);
47
+ std::unique_lock<std::mutex > lock (cache_mutex);
48
48
std::string real_filename = doc_root_ + path;
49
49
if (regions.find (real_filename) != regions.end ()) return true ;
50
50
#ifdef O_NOATIME
@@ -60,7 +60,6 @@ struct file_cache {
60
60
return false ;
61
61
}
62
62
63
- boost::upgrade_to_unique_lock<boost::shared_mutex> unique_lock (lock);
64
63
regions.insert (std::make_pair (real_filename, std::make_pair (region, size)));
65
64
static server::response_header common_headers[] = {
66
65
{" Connection" , " close" }, {" Content-Type" , " x-application/octet-stream" },
@@ -73,7 +72,7 @@ struct file_cache {
73
72
}
74
73
75
74
std::pair<void *, std::size_t > get (std::string const &path) {
76
- boost::shared_lock<boost::shared_mutex > lock (cache_mutex);
75
+ std::unique_lock<std::mutex > lock (cache_mutex);
77
76
region_map::const_iterator region = regions.find (doc_root_ + path);
78
77
if (region != regions.end ())
79
78
return region->second ;
@@ -83,14 +82,12 @@ struct file_cache {
83
82
84
83
boost::iterator_range<std::vector<server::response_header>::iterator> meta (
85
84
std::string const &path) {
86
- boost::shared_lock<boost::shared_mutex > lock (cache_mutex);
85
+ std::unique_lock<std::mutex > lock (cache_mutex);
87
86
static std::vector<server::response_header> empty_vector;
88
87
auto headers = file_headers.find (doc_root_ + path);
89
88
if (headers != file_headers.end ()) {
90
- auto begin = headers->second
91
- .begin (),
92
- end =
93
- headers->second .end ();
89
+ auto begin = headers->second .begin (),
90
+ end = headers->second .end ();
94
91
return boost::make_iterator_range (begin, end);
95
92
} else
96
93
return boost::make_iterator_range (empty_vector);
0 commit comments