1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
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"
20 #include <cstdio> //std::remove
22 using namespace boost::interprocess
;
24 static const std::size_t FileSize
= 1000;
25 inline std::string
get_filename()
27 std::string
ret (ipcdetail::get_temporary_path());
29 ret
+= test::get_process_id_name();
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
39 file_lock_lock_test_wrapper()
40 : boost::interprocess::file_lock(get_filename().c_str())
46 //Destroy and create file
48 std::remove(get_filename().c_str());
49 std::ofstream
file(get_filename().c_str());
53 file_lock
flock(get_filename().c_str());
55 scoped_lock
<file_lock
> sl(flock
);
58 scoped_lock
<file_lock
> sl(flock
, try_to_lock
);
61 scoped_lock
<file_lock
> sl(flock
, test::delay(1));
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
);
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());
81 #include <boost/interprocess/detail/config_end.hpp>