Index: detail/os_file_functions.hpp =================================================================== --- detail/os_file_functions.hpp (revision 2612) +++ detail/os_file_functions.hpp (working copy) @@ -124,6 +124,14 @@ (name, (unsigned int)mode, winapi::open_existing, attr, 0); } +inline file_handle_t open_existing_file +(const wchar_t *name, mode_t mode, bool temporary = false) +{ + unsigned long attr = temporary ? winapi::file_attribute_temporary : 0; + return winapi::create_file + (name, (unsigned int)mode, winapi::open_existing, attr, 0); +} + inline bool delete_file(const char *name) { return winapi::unlink_file(name); } Index: detail/win32_api.hpp =================================================================== --- detail/win32_api.hpp (revision 2612) +++ detail/win32_api.hpp (working copy) @@ -914,6 +914,7 @@ extern "C" __declspec(dllimport) void * __stdcall MapViewOfFileEx (void *, unsigned long, unsigned long, unsigned long, std::size_t, void*); extern "C" __declspec(dllimport) void * __stdcall OpenFileMappingA (unsigned long, int, const char *); extern "C" __declspec(dllimport) void * __stdcall CreateFileA (const char *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *); +extern "C" __declspec(dllimport) void * __stdcall CreateFileW (const wchar_t *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *); extern "C" __declspec(dllimport) void __stdcall GetSystemInfo (struct system_info *); extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t); extern "C" __declspec(dllimport) int __stdcall VirtualUnlock (void *, std::size_t); @@ -1193,6 +1194,24 @@ return invalid_handle_value; } +inline void *create_file(const wchar_t *name, unsigned long access, unsigned long creation_flags, unsigned long attributes, interprocess_security_attributes *psec) +{ + for (unsigned int attempt(0); attempt < error_sharing_violation_tries; ++attempt) { + void * const handle = CreateFileW(name, access, + file_share_read | file_share_write | file_share_delete, + psec, creation_flags, attributes, 0); + bool const invalid(invalid_handle_value == handle); + if (!invalid) { + return handle; + } + if (error_sharing_violation != get_last_error()) { + return handle; + } + sleep(error_sharing_violation_sleep_ms); + } + return invalid_handle_value; +} + inline void get_system_info(system_info *info) { GetSystemInfo(info); } Index: sync/file_lock.hpp =================================================================== --- sync/file_lock.hpp (revision 2612) +++ sync/file_lock.hpp (working copy) @@ -53,6 +53,7 @@ //!Opens a file lock. Throws interprocess_exception if the file does not //!exist or there are no operating system resources. file_lock(const char *name); + file_lock(const wchar_t *name); //!Moves the ownership of "moved"'s file mapping object to *this. //!After the call, "moved" does not represent any file mapping object. @@ -211,6 +212,16 @@ } } +inline file_lock::file_lock(const wchar_t *name) +{ + m_file_hnd = ipcdetail::open_existing_file(name, read_write); + + if (m_file_hnd == ipcdetail::invalid_file()) { + error_info err(system_error_code()); + throw interprocess_exception(err); + } +} + inline file_lock::~file_lock() { if(m_file_hnd != ipcdetail::invalid_file()){