Skip to content

Commit

Permalink
Thread: merge from trunk to fix 8070 and possibly 7461.
Browse files Browse the repository at this point in the history
[SVN r85815]
  • Loading branch information
viboes committed Sep 21, 2013
1 parent 325d8cf commit 8f06153
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 38 deletions.
13 changes: 13 additions & 0 deletions include/boost/thread/detail/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,19 @@ namespace boost
};

void BOOST_THREAD_DECL add_thread_exit_function(thread_exit_function_base*);
struct shared_state_base;
#if defined(BOOST_THREAD_PLATFORM_WIN32)
inline void make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
{
detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
if(current_thread_data)
{
current_thread_data->make_ready_at_thread_exit(as);
}
}
#else
void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as);
#endif
}

namespace this_thread
Expand Down
13 changes: 7 additions & 6 deletions include/boost/thread/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ namespace boost
{
throw_exception(promise_already_satisfied());
}
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());
}
#endif

Expand All @@ -431,7 +431,8 @@ namespace boost
}
exception=e;
this->is_constructed = true;
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());

}

bool has_value() const
Expand Down Expand Up @@ -688,7 +689,7 @@ namespace boost
result.reset(new T(result_));

this->is_constructed = true;
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());
}
//void set_value_at_thread_exit(BOOST_THREAD_RV_REF(T) result_)
void set_value_at_thread_exit(rvalue_source_type result_)
Expand All @@ -699,7 +700,7 @@ namespace boost
result.reset(new T(boost::move(result_)));
//future_traits<T>::init(result,static_cast<rvalue_source_type>(result_));
this->is_constructed = true;
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());
}


Expand Down Expand Up @@ -760,7 +761,7 @@ namespace boost
//future_traits<T>::init(result,result_);
result= &result_;
this->is_constructed = true;
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());
}

private:
Expand Down Expand Up @@ -806,7 +807,7 @@ namespace boost
throw_exception(promise_already_satisfied());
}
this->is_constructed = true;
get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
detail::make_ready_at_thread_exit(shared_from_this());
}
private:
shared_state(shared_state const&);
Expand Down
11 changes: 5 additions & 6 deletions include/boost/thread/win32/condition_variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,17 @@ namespace boost
struct entry_manager
{
entry_ptr const entry;
boost::mutex& internal_mutex;

BOOST_THREAD_NO_COPYABLE(entry_manager)
entry_manager(entry_ptr const& entry_):
entry(entry_)
entry_manager(entry_ptr const& entry_, boost::mutex& mutex_):
entry(entry_), internal_mutex(mutex_)
{}

~entry_manager()
{
//if(! entry->is_notified()) // several regression #7657
{
boost::lock_guard<boost::mutex> internal_lock(internal_mutex);
entry->remove_waiter();
}
}

list_entry* operator->()
Expand All @@ -218,7 +217,7 @@ namespace boost
{
relocker<lock_type> locker(lock);

entry_manager entry(get_wait_entry());
entry_manager entry(get_wait_entry(), internal_mutex);

locker.unlock();

Expand Down
27 changes: 13 additions & 14 deletions include/boost/thread/win32/mfc_thread_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@

// check if we use MFC
#ifdef _AFXDLL
# if defined(_AFXEXT)
# if defined(_AFXEXT)

// can't use ExtRawDllMain from afxdllx.h as it also defines the symbol _pRawDllMain
extern "C"
inline BOOL WINAPI ExtRawDllMain(HINSTANCE, DWORD dwReason, LPVOID)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
// save critical data pointers before running the constructors
AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
pModuleState->m_pClassInit = pModuleState->m_classList;
pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
pModuleState->m_classList.m_pHead = NULL;
pModuleState->m_factoryList.m_pHead = NULL;
}
return TRUE; // ok
if (dwReason == DLL_PROCESS_ATTACH)
{
// save critical data pointers before running the constructors
AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
pModuleState->m_pClassInit = pModuleState->m_classList;
pModuleState->m_pFactoryInit = pModuleState->m_factoryList;
pModuleState->m_classList.m_pHead = NULL;
pModuleState->m_factoryList.m_pHead = NULL;
}
return TRUE; // ok
}

extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &ExtRawDllMain;

# elif defined(_USRDLL)
# elif defined(_USRDLL)

extern "C" BOOL WINAPI RawDllMain(HANDLE, DWORD dwReason, LPVOID);
extern "C" __declspec(selectany) BOOL (WINAPI * const _pRawDllMainOrig)(HANDLE, DWORD, LPVOID) = &RawDllMain;

# endif
# endif
#endif


#endif
2 changes: 1 addition & 1 deletion include/boost/thread/win32/thread_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace boost

virtual void run()=0;

void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
virtual void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
{
notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
}
Expand Down
5 changes: 3 additions & 2 deletions include/boost/thread/win32/thread_primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
#include <boost/assert.hpp>
#include <boost/thread/exceptions.hpp>
#include <boost/detail/interlocked.hpp>
//#include <boost/detail/win/synchronization.hpp>
#include <algorithm>

#ifndef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
#if _WIN32_WINNT >= 0x0600
//#define BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
#if _WIN32_WINNT >= 0x0600 && ! defined _WIN32_WINNT_WS08
#define BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
#endif
#endif

Expand Down
37 changes: 29 additions & 8 deletions src/pthread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ namespace boost
return 0;
}
}

}
namespace detail
{
struct externally_launched_thread:
detail::thread_data_base
{
Expand All @@ -197,7 +199,12 @@ namespace boost
interrupt_enabled=false;
#endif
}

~externally_launched_thread() {
BOOST_ASSERT(notify.empty());
notify.clear();
BOOST_ASSERT(async_states_.empty());
async_states_.clear();
}
void run()
{}
void notify_all_at_thread_exit(condition_variable*, mutex*)
Expand All @@ -208,18 +215,18 @@ namespace boost
void operator=(externally_launched_thread&);
};

detail::thread_data_base* make_external_thread_data()
thread_data_base* make_external_thread_data()
{
detail::thread_data_base* const me(new externally_launched_thread());
thread_data_base* const me(new externally_launched_thread());
me->self.reset(me);
set_current_thread_data(me);
return me;
}


detail::thread_data_base* get_or_make_current_thread_data()
thread_data_base* get_or_make_current_thread_data()
{
detail::thread_data_base* current_thread_data(detail::get_current_thread_data());
thread_data_base* current_thread_data(get_current_thread_data());
if(!current_thread_data)
{
current_thread_data=make_external_thread_data();
Expand Down Expand Up @@ -701,8 +708,11 @@ namespace boost

void erase_tss_node(void const* key)
{
detail::thread_data_base* const current_thread_data(get_or_make_current_thread_data());
current_thread_data->tss_data.erase(key);
detail::thread_data_base* const current_thread_data(get_current_thread_data());
if(current_thread_data)
{
current_thread_data->tss_data.erase(key);
}
}

void set_tss_data(void const* key,
Expand Down Expand Up @@ -740,6 +750,17 @@ namespace boost
current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
}
}
namespace detail {

void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
{
detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
if(current_thread_data)
{
current_thread_data->make_ready_at_thread_exit(as);
}
}
}



Expand Down
19 changes: 18 additions & 1 deletion src/win32/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ namespace boost
interruption_enabled=false;
#endif
}
~externally_launched_thread() {
BOOST_ASSERT(notify.empty());
notify.clear();
BOOST_ASSERT(async_states_.empty());
async_states_.clear();
}

void run()
{}
Expand Down Expand Up @@ -430,7 +436,7 @@ namespace boost
LARGE_INTEGER due_time={{0,0}};
if(target_time.relative)
{
unsigned long const elapsed_milliseconds=GetTickCount()-target_time.start;
unsigned long const elapsed_milliseconds=detail::win32::GetTickCount64()-target_time.start;
LONGLONG const remaining_milliseconds=(target_time.milliseconds-elapsed_milliseconds);
LONGLONG const hundred_nanoseconds_in_one_millisecond=10000;

Expand Down Expand Up @@ -748,5 +754,16 @@ namespace boost
current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
}
}
//namespace detail {
//
// void BOOST_THREAD_DECL make_ready_at_thread_exit(shared_ptr<shared_state_base> as)
// {
// detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
// if(current_thread_data)
// {
// current_thread_data->make_ready_at_thread_exit(as);
// }
// }
//}
}

0 comments on commit 8f06153

Please sign in to comment.