summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '3rdParty/Boost/src/boost/thread/win32/once.hpp')
-rw-r--r--3rdParty/Boost/src/boost/thread/win32/once.hpp125
1 files changed, 74 insertions, 51 deletions
diff --git a/3rdParty/Boost/src/boost/thread/win32/once.hpp b/3rdParty/Boost/src/boost/thread/win32/once.hpp
index c25f9ab..e1b1843 100644
--- a/3rdParty/Boost/src/boost/thread/win32/once.hpp
+++ b/3rdParty/Boost/src/boost/thread/win32/once.hpp
@@ -34,42 +34,85 @@ namespace boost
{
long status;
long count;
- long throw_count;
- void* event_handle;
+ };
+
+#define BOOST_ONCE_INIT {0,0}
+
+ namespace detail
+ {
+#ifdef BOOST_NO_ANSI_APIS
+ typedef wchar_t once_char_type;
+#else
+ typedef char once_char_type;
+#endif
+ unsigned const once_mutex_name_fixed_length=54;
+ unsigned const once_mutex_name_length=once_mutex_name_fixed_length+
+ sizeof(void*)*2+sizeof(unsigned long)*2+1;
- ~once_flag()
+ template <class I>
+ void int_to_string(I p, once_char_type* buf)
{
- if(count)
+ for(unsigned i=0; i < sizeof(I)*2; ++i,++buf)
{
- BOOST_ASSERT(count==throw_count);
+#ifdef BOOST_NO_ANSI_APIS
+ once_char_type const a=L'A';
+#else
+ once_char_type const a='A';
+#endif
+ *buf = a + static_cast<once_char_type>((p >> (i*4)) & 0x0f);
}
+ *buf = 0;
+ }
+
+ inline void name_once_mutex(once_char_type* mutex_name,void* flag_address)
+ {
+#ifdef BOOST_NO_ANSI_APIS
+ static const once_char_type fixed_mutex_name[]=L"Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
+#else
+ static const once_char_type fixed_mutex_name[]="Local\\{C15730E2-145C-4c5e-B005-3BC753F42475}-once-flag";
+#endif
+ BOOST_STATIC_ASSERT(sizeof(fixed_mutex_name) ==
+ (sizeof(once_char_type)*(once_mutex_name_fixed_length+1)));
- void* const old_event=BOOST_INTERLOCKED_EXCHANGE_POINTER(&event_handle,0);
- if(old_event)
+ std::memcpy(mutex_name,fixed_mutex_name,sizeof(fixed_mutex_name));
+ detail::int_to_string(reinterpret_cast<std::ptrdiff_t>(flag_address),
+ mutex_name + once_mutex_name_fixed_length);
+ detail::int_to_string(win32::GetCurrentProcessId(),
+ mutex_name + once_mutex_name_fixed_length + sizeof(void*)*2);
+ }
+
+ inline void* open_once_event(once_char_type* mutex_name,void* flag_address)
+ {
+ if(!*mutex_name)
{
- ::boost::detail::win32::CloseHandle(old_event);
+ name_once_mutex(mutex_name,flag_address);
}
+
+#ifdef BOOST_NO_ANSI_APIS
+ return ::boost::detail::win32::OpenEventW(
+#else
+ return ::boost::detail::win32::OpenEventA(
+#endif
+ ::boost::detail::win32::synchronize |
+ ::boost::detail::win32::event_modify_state,
+ false,
+ mutex_name);
}
- };
-#define BOOST_ONCE_INIT {0,0,0,0}
-
- namespace detail
- {
- inline void* allocate_event_handle(void*& handle)
+ inline void* create_once_event(once_char_type* mutex_name,void* flag_address)
{
- void* const new_handle=::boost::detail::win32::create_anonymous_event(
- ::boost::detail::win32::manual_reset_event,
- ::boost::detail::win32::event_initially_reset);
-
- void* event_handle=BOOST_INTERLOCKED_COMPARE_EXCHANGE_POINTER(&handle,
- new_handle,0);
- if(event_handle)
+ if(!*mutex_name)
{
- ::boost::detail::win32::CloseHandle(new_handle);
- return event_handle;
+ name_once_mutex(mutex_name,flag_address);
}
- return new_handle;
+#ifdef BOOST_NO_ANSI_APIS
+ return ::boost::detail::win32::CreateEventW(
+#else
+ return ::boost::detail::win32::CreateEventA(
+#endif
+ 0,::boost::detail::win32::manual_reset_event,
+ ::boost::detail::win32::event_initially_reset,
+ mutex_name);
}
}
@@ -83,8 +126,9 @@ namespace boost
long const running_value=0x7f0725e3;
long status;
bool counted=false;
- void* event_handle=0;
- long throw_count=0;
+ detail::win32::handle_manager event_handle;
+ detail::once_char_type mutex_name[detail::once_mutex_name_length];
+ mutex_name[0]=0;
while((status=::boost::detail::interlocked_read_acquire(&flag.status))
!=function_complete_flag_value)
@@ -96,7 +140,7 @@ namespace boost
{
if(!event_handle)
{
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
+ event_handle=detail::open_once_event(mutex_name,&flag);
}
if(event_handle)
{
@@ -112,25 +156,20 @@ namespace boost
if(!event_handle &&
(::boost::detail::interlocked_read_acquire(&flag.count)>1))
{
- event_handle=::boost::detail::allocate_event_handle(flag.event_handle);
+ event_handle=detail::create_once_event(mutex_name,&flag);
}
if(event_handle)
{
::boost::detail::win32::SetEvent(event_handle);
}
- throw_count=::boost::detail::interlocked_read_acquire(&flag.throw_count);
break;
}
catch(...)
{
- if(counted)
- {
- BOOST_INTERLOCKED_INCREMENT(&flag.throw_count);
- }
BOOST_INTERLOCKED_EXCHANGE(&flag.status,0);
if(!event_handle)
{
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
+ event_handle=detail::open_once_event(mutex_name,&flag);
}
if(event_handle)
{
@@ -149,31 +188,15 @@ namespace boost
{
break;
}
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
if(!event_handle)
{
- event_handle=::boost::detail::allocate_event_handle(flag.event_handle);
+ event_handle=detail::create_once_event(mutex_name,&flag);
continue;
}
}
BOOST_VERIFY(!::boost::detail::win32::WaitForSingleObject(
event_handle,::boost::detail::win32::infinite));
}
- if(counted || throw_count)
- {
- if(!BOOST_INTERLOCKED_EXCHANGE_ADD(&flag.count,(counted?-1:0)-throw_count))
- {
- if(!event_handle)
- {
- event_handle=::boost::detail::interlocked_read_acquire(&flag.event_handle);
- }
- if(event_handle)
- {
- BOOST_INTERLOCKED_EXCHANGE_POINTER(&flag.event_handle,0);
- ::boost::detail::win32::CloseHandle(event_handle);
- }
- }
- }
}
}