diff options
| author | Remko Tronçon <git@el-tramo.be> | 2010-11-24 20:33:19 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2010-11-24 20:35:17 (GMT) | 
| commit | 332d60c56dfaa11fdd135088279d15cd5983b3d4 (patch) | |
| tree | dd77717a4e1732da929d5ff8a0471fa3f005e201 /3rdParty/Boost/src/boost/thread/win32 | |
| parent | 90c44a10fec26d2a0935b2d62e82b6a5be028373 (diff) | |
| download | swift-contrib-332d60c56dfaa11fdd135088279d15cd5983b3d4.zip swift-contrib-332d60c56dfaa11fdd135088279d15cd5983b3d4.tar.bz2 | |
Upgraded Boost to 1.45.0.
Diffstat (limited to '3rdParty/Boost/src/boost/thread/win32')
6 files changed, 152 insertions, 71 deletions
| diff --git a/3rdParty/Boost/src/boost/thread/win32/mutex.hpp b/3rdParty/Boost/src/boost/thread/win32/mutex.hpp index efe6241..d59fbfa 100644 --- a/3rdParty/Boost/src/boost/thread/win32/mutex.hpp +++ b/3rdParty/Boost/src/boost/thread/win32/mutex.hpp @@ -20,9 +20,11 @@ namespace boost      }      class mutex: -        boost::noncopyable,          public ::boost::detail::underlying_mutex      { +    private: +        mutex(mutex const&); +        mutex& operator=(mutex const&);      public:          mutex()          { @@ -40,9 +42,11 @@ namespace boost      typedef mutex try_mutex;      class timed_mutex: -        boost::noncopyable,          public ::boost::detail::basic_timed_mutex      { +    private: +        timed_mutex(timed_mutex const&); +        timed_mutex& operator=(timed_mutex const&);      public:          timed_mutex()          { 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); -                } -            } -        }      }  } diff --git a/3rdParty/Boost/src/boost/thread/win32/recursive_mutex.hpp b/3rdParty/Boost/src/boost/thread/win32/recursive_mutex.hpp index 2360a92..e83d3bc 100644 --- a/3rdParty/Boost/src/boost/thread/win32/recursive_mutex.hpp +++ b/3rdParty/Boost/src/boost/thread/win32/recursive_mutex.hpp @@ -20,9 +20,11 @@  namespace boost  {      class recursive_mutex: -        boost::noncopyable,          public ::boost::detail::basic_recursive_mutex      { +    private: +        recursive_mutex(recursive_mutex const&); +        recursive_mutex& operator=(recursive_mutex const&);              public:          recursive_mutex()          { @@ -40,9 +42,11 @@ namespace boost      typedef recursive_mutex recursive_try_mutex;      class recursive_timed_mutex: -        boost::noncopyable,          public ::boost::detail::basic_recursive_timed_mutex      { +    private: +        recursive_timed_mutex(recursive_timed_mutex const&); +        recursive_timed_mutex& operator=(recursive_timed_mutex const&);              public:          recursive_timed_mutex()          { diff --git a/3rdParty/Boost/src/boost/thread/win32/shared_mutex.hpp b/3rdParty/Boost/src/boost/thread/win32/shared_mutex.hpp index 58e8093..58fc622 100644 --- a/3rdParty/Boost/src/boost/thread/win32/shared_mutex.hpp +++ b/3rdParty/Boost/src/boost/thread/win32/shared_mutex.hpp @@ -19,10 +19,12 @@  namespace boost  { -    class shared_mutex: -        private boost::noncopyable +    class shared_mutex      {      private: +        shared_mutex(shared_mutex const&); +        shared_mutex& operator=(shared_mutex const&);         +    private:          struct state_data          {              unsigned shared_count:11, @@ -49,33 +51,35 @@ namespace boost              return *reinterpret_cast<T const*>(&res);          } +        enum +        { +            unlock_sem = 0, +            exclusive_sem = 1 +        }; +          state_data state;          detail::win32::handle semaphores[2]; -        detail::win32::handle &unlock_sem; -        detail::win32::handle &exclusive_sem;          detail::win32::handle upgrade_sem;          void release_waiters(state_data old_state)          {              if(old_state.exclusive_waiting)              { -                BOOST_VERIFY(detail::win32::ReleaseSemaphore(exclusive_sem,1,0)!=0); +                BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[exclusive_sem],1,0)!=0);              }              if(old_state.shared_waiting || old_state.exclusive_waiting)              { -                BOOST_VERIFY(detail::win32::ReleaseSemaphore(unlock_sem,old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0); +                BOOST_VERIFY(detail::win32::ReleaseSemaphore(semaphores[unlock_sem],old_state.shared_waiting + (old_state.exclusive_waiting?1:0),0)!=0);              }          }      public: -        shared_mutex(): -            unlock_sem(semaphores[0]), -            exclusive_sem(semaphores[1])  +        shared_mutex()          { -            unlock_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); -            exclusive_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX); +            semaphores[unlock_sem]=detail::win32::create_anonymous_semaphore(0,LONG_MAX); +            semaphores[exclusive_sem]=detail::win32::create_anonymous_semaphore(0,LONG_MAX);              upgrade_sem=detail::win32::create_anonymous_semaphore(0,LONG_MAX);              state_data state_={0};              state=state_; @@ -84,8 +88,8 @@ namespace boost          ~shared_mutex()          {              detail::win32::CloseHandle(upgrade_sem); -            detail::win32::CloseHandle(unlock_sem); -            detail::win32::CloseHandle(exclusive_sem); +            detail::win32::CloseHandle(semaphores[unlock_sem]); +            detail::win32::CloseHandle(semaphores[exclusive_sem]);          }          bool try_lock_shared() @@ -97,6 +101,10 @@ namespace boost                  if(!new_state.exclusive && !new_state.exclusive_waiting_blocked)                  {                      ++new_state.shared_count; +                    if(!new_state.shared_count) +                    { +                        return false; +                    }                  }                  state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); @@ -131,10 +139,18 @@ namespace boost                      if(new_state.exclusive || new_state.exclusive_waiting_blocked)                      {                          ++new_state.shared_waiting; +                        if(!new_state.shared_waiting) +                        { +                            boost::throw_exception(boost::lock_error()); +                        }                      }                      else                      {                          ++new_state.shared_count; +                        if(!new_state.shared_count) +                        { +                            boost::throw_exception(boost::lock_error()); +                        }                      }                      state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); @@ -150,7 +166,7 @@ namespace boost                      return true;                  } -                unsigned long const res=detail::win32::WaitForSingleObject(unlock_sem,::boost::detail::get_milliseconds_until(wait_until)); +                unsigned long const res=detail::win32::WaitForSingleObject(semaphores[unlock_sem],::boost::detail::get_milliseconds_until(wait_until));                  if(res==detail::win32::timeout)                  {                      for(;;) @@ -166,6 +182,10 @@ namespace boost                          else                          {                              ++new_state.shared_count; +                            if(!new_state.shared_count) +                            { +                                return false; +                            }                          }                          state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state); @@ -282,6 +302,11 @@ namespace boost                      if(new_state.shared_count || new_state.exclusive)                      {                          ++new_state.exclusive_waiting; +                        if(!new_state.exclusive_waiting) +                        { +                            boost::throw_exception(boost::lock_error()); +                        } +                                                  new_state.exclusive_waiting_blocked=true;                      }                      else @@ -374,10 +399,18 @@ namespace boost                      if(new_state.exclusive || new_state.exclusive_waiting_blocked || new_state.upgrade)                      {                          ++new_state.shared_waiting; +                        if(!new_state.shared_waiting) +                        { +                            boost::throw_exception(boost::lock_error()); +                        }                      }                      else                      {                          ++new_state.shared_count; +                        if(!new_state.shared_count) +                        { +                            boost::throw_exception(boost::lock_error()); +                        }                          new_state.upgrade=true;                      } @@ -394,7 +427,7 @@ namespace boost                      return;                  } -                BOOST_VERIFY(!detail::win32::WaitForSingleObject(unlock_sem,detail::win32::infinite)); +                BOOST_VERIFY(!detail::win32::WaitForSingleObject(semaphores[unlock_sem],detail::win32::infinite));              }          } @@ -411,6 +444,10 @@ namespace boost                  else                  {                      ++new_state.shared_count; +                    if(!new_state.shared_count) +                    { +                        return false; +                    }                      new_state.upgrade=true;                  } diff --git a/3rdParty/Boost/src/boost/thread/win32/thread_data.hpp b/3rdParty/Boost/src/boost/thread/win32/thread_data.hpp index 1a6a1e0..c86b0fa 100644 --- a/3rdParty/Boost/src/boost/thread/win32/thread_data.hpp +++ b/3rdParty/Boost/src/boost/thread/win32/thread_data.hpp @@ -144,6 +144,11 @@ namespace boost                  start(0),milliseconds(~uintmax_t(0)),relative(true)              {}          }; + +        inline unsigned long pin_to_zero(long value) +        { +            return (value<0)?0u:(unsigned long)value; +        }      }      namespace this_thread @@ -163,7 +168,7 @@ namespace boost          template<typename TimeDuration>          inline void sleep(TimeDuration const& rel_time)          { -            interruptible_wait(static_cast<unsigned long>(rel_time.total_milliseconds())); +            interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));          }          inline void sleep(system_time const& abs_time)          { diff --git a/3rdParty/Boost/src/boost/thread/win32/thread_primitives.hpp b/3rdParty/Boost/src/boost/thread/win32/thread_primitives.hpp index 2359c38..9b20e86 100644 --- a/3rdParty/Boost/src/boost/thread/win32/thread_primitives.hpp +++ b/3rdParty/Boost/src/boost/thread/win32/thread_primitives.hpp @@ -31,14 +31,18 @@ namespace boost              unsigned const infinite=INFINITE;              unsigned const timeout=WAIT_TIMEOUT;              handle const invalid_handle_value=INVALID_HANDLE_VALUE; +            unsigned const event_modify_state=EVENT_MODIFY_STATE; +            unsigned const synchronize=SYNCHRONIZE;  # ifdef BOOST_NO_ANSI_APIS              using ::CreateMutexW;              using ::CreateEventW; +            using ::OpenEventW;              using ::CreateSemaphoreW;  # else              using ::CreateMutexA;              using ::CreateEventA; +            using ::OpenEventA;              using ::CreateSemaphoreA;  # endif              using ::CloseHandle; @@ -100,6 +104,8 @@ namespace boost              unsigned const infinite=~0U;              unsigned const timeout=258U;              handle const invalid_handle_value=(handle)(-1); +            unsigned const event_modify_state=2; +            unsigned const synchronize=0x100000u;              extern "C"              { @@ -108,10 +114,12 @@ namespace boost                  __declspec(dllimport) void* __stdcall CreateMutexW(_SECURITY_ATTRIBUTES*,int,wchar_t const*);                  __declspec(dllimport) void* __stdcall CreateSemaphoreW(_SECURITY_ATTRIBUTES*,long,long,wchar_t const*);                  __declspec(dllimport) void* __stdcall CreateEventW(_SECURITY_ATTRIBUTES*,int,int,wchar_t const*); +                __declspec(dllimport) void* __stdcall OpenEventW(unsigned long,int,wchar_t const*);  # else                  __declspec(dllimport) void* __stdcall CreateMutexA(_SECURITY_ATTRIBUTES*,int,char const*);                  __declspec(dllimport) void* __stdcall CreateSemaphoreA(_SECURITY_ATTRIBUTES*,long,long,char const*);                  __declspec(dllimport) void* __stdcall CreateEventA(_SECURITY_ATTRIBUTES*,int,int,char const*); +                __declspec(dllimport) void* __stdcall OpenEventA(unsigned long,int,char const*);  # endif                  __declspec(dllimport) int __stdcall CloseHandle(void*);                  __declspec(dllimport) int __stdcall ReleaseMutex(void*); | 
 Swift
 Swift