virtual const void *buffer_with_init_data_to_file() = 0;
virtual void *buffer_to_store_init_data_from_file() = 0;
virtual bool open(create_enum_t creation_type, const char *id_name) = 0;
+ virtual bool open(create_enum_t creation_type, const wchar_t *id_name) = 0;
virtual void close() = 0;
virtual ~windows_named_sync_interface() = 0;
};
public:
windows_named_sync();
- void open_or_create(create_enum_t creation_type, const char *name, const permissions &perm, windows_named_sync_interface &sync_interface);
+ template <class CharT>
+ void open_or_create(create_enum_t creation_type, const CharT *name, const permissions &perm, windows_named_sync_interface &sync_interface);
void close(windows_named_sync_interface &sync_interface);
static bool remove(const char *name);
+ static bool remove(const wchar_t *name);
#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
private:
inline void windows_named_sync::close(windows_named_sync_interface &sync_interface)
{
const std::size_t buflen = sync_interface.get_data_size();
- const std::size_t sizeof_file_info = sizeof(sync_id::internal_type) + buflen;
winapi::interprocess_overlapped overlapped;
if(winapi::lock_file_ex
- (m_file_hnd, winapi::lockfile_exclusive_lock, 0, sizeof_file_info, 0, &overlapped)){
+ (m_file_hnd, winapi::lockfile_exclusive_lock, 0, 1, 0, &overlapped)){
if(winapi::set_file_pointer(m_file_hnd, sizeof(sync_id::internal_type), 0, winapi::file_begin)){
const void *buf = sync_interface.buffer_with_final_data_to_file();
}
}
sync_interface.close();
+ //close_handle unlocks the lock
if(m_file_hnd != winapi::invalid_handle_value){
winapi::close_handle(m_file_hnd);
m_file_hnd = winapi::invalid_handle_value;
}
}
+template <class CharT>
inline void windows_named_sync::open_or_create
( create_enum_t creation_type
- , const char *name
+ , const CharT *name
, const permissions &perm
, windows_named_sync_interface &sync_interface)
{
- std::string aux_str(name);
+ std::basic_string<CharT> aux_str(name);
m_file_hnd = winapi::invalid_handle_value;
//Use a file to emulate POSIX lifetime semantics. After this logic
//we'll obtain the ID of the native handle to open in aux_str
const std::size_t sizeof_file_info = sizeof(unique_id_type) + buflen;
winapi::interprocess_overlapped overlapped;
if(winapi::lock_file_ex
- (m_file_hnd, winapi::lockfile_exclusive_lock, 0, sizeof_file_info, 0, &overlapped)){
+ (m_file_hnd, winapi::lockfile_exclusive_lock, 0, 1, 0, &overlapped)){
__int64 filesize = 0;
//Obtain the unique id to open the native semaphore.
//If file size was created
}
if(success){
//Now create a global semaphore name based on the unique id
- char unique_id_name[sizeof(unique_id_val)*2+1];
+ CharT unique_id_name[sizeof(unique_id_val)*2+1];
std::size_t name_suffix_length = sizeof(unique_id_name);
bytes_to_str(&unique_id_val, sizeof(unique_id_val), &unique_id_name[0], name_suffix_length);
success = sync_interface.open(creation_type, unique_id_name);
}
//Obtain OS error in case something has failed
- err = system_error_code();
+ if(!success)
+ err = system_error_code();
//If this fails we have no possible rollback so don't check the return
- if(!winapi::unlock_file_ex(m_file_hnd, 0, sizeof_file_info, 0, &overlapped)){
+ if(!winapi::unlock_file_ex(m_file_hnd, 0, 1, 0, &overlapped)){
err = system_error_code();
}
}
inline bool windows_named_sync::remove(const char *name)
{
- try{
+ BOOST_TRY{
//Make sure a temporary path is created for shared memory
std::string semfile;
ipcdetail::shared_filepath(name, semfile);
return winapi::unlink_file(semfile.c_str());
}
- catch(...){
+ BOOST_CATCH(...){
return false;
+ } BOOST_CATCH_END
+}
+
+inline bool windows_named_sync::remove(const wchar_t *name)
+{
+ BOOST_TRY{
+ //Make sure a temporary path is created for shared memory
+ std::wstring semfile;
+ ipcdetail::shared_filepath(name, semfile);
+ return winapi::unlink_file(semfile.c_str());
}
+ BOOST_CATCH(...){
+ return false;
+ } BOOST_CATCH_END
}
} //namespace ipcdetail {