]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/interprocess for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
10 | #include <boost/interprocess/detail/config_begin.hpp> | |
11 | #include <boost/interprocess/detail/workaround.hpp> | |
12 | #include <boost/interprocess/sync/file_lock.hpp> | |
13 | #include <boost/interprocess/sync/scoped_lock.hpp> | |
14 | #include <boost/interprocess/file_mapping.hpp> | |
15 | #include <boost/date_time/posix_time/posix_time_types.hpp> | |
16 | #include "mutex_test_template.hpp" | |
17 | #include "sharable_mutex_test_template.hpp" | |
18 | #include "get_process_id_name.hpp" | |
19 | #include <fstream> | |
20 | #include <cstdio> //std::remove | |
21 | ||
22 | using namespace boost::interprocess; | |
23 | ||
24 | static const std::size_t FileSize = 1000; | |
25 | inline std::string get_filename() | |
26 | { | |
27 | std::string ret (ipcdetail::get_temporary_path()); | |
28 | ret += "/"; | |
29 | ret += test::get_process_id_name(); | |
30 | return ret; | |
31 | } | |
32 | ||
33 | //This wrapper is necessary to have a default constructor | |
34 | //in generic mutex_test_template functions | |
35 | class file_lock_lock_test_wrapper | |
36 | : public boost::interprocess::file_lock | |
37 | { | |
38 | public: | |
39 | file_lock_lock_test_wrapper() | |
40 | : boost::interprocess::file_lock(get_filename().c_str()) | |
41 | {} | |
42 | }; | |
43 | ||
44 | int main () | |
45 | { | |
46 | //Destroy and create file | |
47 | { | |
48 | std::remove(get_filename().c_str()); | |
49 | std::ofstream file(get_filename().c_str()); | |
50 | if(!file){ | |
51 | return 1; | |
52 | } | |
53 | file_lock flock(get_filename().c_str()); | |
54 | { | |
55 | scoped_lock<file_lock> sl(flock); | |
56 | } | |
57 | { | |
58 | scoped_lock<file_lock> sl(flock, try_to_lock); | |
59 | } | |
60 | { | |
61 | scoped_lock<file_lock> sl(flock, test::delay(1)); | |
62 | } | |
63 | } | |
64 | { | |
65 | //Now test move semantics | |
66 | file_lock mapping(get_filename().c_str()); | |
67 | file_lock move_ctor(boost::move(mapping)); | |
68 | file_lock move_assign; | |
69 | move_assign = boost::move(move_ctor); | |
70 | mapping.swap(move_assign); | |
71 | } | |
72 | ||
73 | //test::test_all_lock<file_lock_lock_test_wrapper>(); | |
74 | //test::test_all_mutex<file_lock_lock_test_wrapper>(); | |
75 | //test::test_all_sharable_mutex<file_lock_lock_test_wrapper>(); | |
76 | std::remove(get_filename().c_str()); | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | #include <boost/interprocess/detail/config_end.hpp> |