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/sync/file_lock.hpp> |
11 | #include <boost/interprocess/sync/scoped_lock.hpp> |
12 | #include <boost/interprocess/file_mapping.hpp> |
13 | #include "util.hpp" |
14 | #include "mutex_test_template.hpp" |
15 | #include "sharable_mutex_test_template.hpp" |
16 | #include "get_process_id_name.hpp" |
17 | #include <fstream> |
18 | #include <cstdio> //std::remove |
19 | |
20 | using namespace boost::interprocess; |
21 | |
22 | //This wrapper is necessary to have a default constructor |
23 | //in generic mutex_test_template functions |
24 | class file_lock_lock_test_wrapper |
25 | : public boost::interprocess::file_lock |
26 | { |
27 | public: |
28 | file_lock_lock_test_wrapper() |
29 | : boost::interprocess::file_lock(get_filename().c_str()) |
30 | {} |
31 | }; |
32 | |
33 | int main () |
34 | { |
35 | //Destroy and create file |
36 | { |
37 | std::remove(filename: get_filename().c_str()); |
38 | std::ofstream file(get_filename().c_str()); |
39 | if(!file){ |
40 | return 1; |
41 | } |
42 | { |
43 | file_lock flock(get_filename().c_str()); |
44 | { |
45 | scoped_lock<file_lock> sl(flock); |
46 | } |
47 | { |
48 | scoped_lock<file_lock> sl(flock, try_to_lock); |
49 | } |
50 | { |
51 | scoped_lock<file_lock> sl(flock, test::ptime_delay_ms(msecs: 1)); |
52 | } |
53 | { |
54 | scoped_lock<file_lock> sl(flock, test::boost_systemclock_delay_ms(msecs: 1)); |
55 | } |
56 | { |
57 | scoped_lock<file_lock> sl(flock, test::std_systemclock_delay_ms(msecs: 1)); |
58 | } |
59 | } |
60 | #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) |
61 | file_lock flock(get_wfilename().c_str()); |
62 | #endif |
63 | } |
64 | { |
65 | //Now test move semantics |
66 | file_lock mapping(get_filename().c_str()); |
67 | file_lock move_ctor(boost::move(t&: mapping)); |
68 | file_lock move_assign; |
69 | move_assign = boost::move(t&: move_ctor); |
70 | mapping.swap(other&: 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(filename: get_filename().c_str()); |
77 | |
78 | return 0; |
79 | } |
80 | |
81 |