Ticket #7283: 7283_80241.patch

File 7283_80241.patch, 10.2 KB (added by viboes, 10 years ago)

patch tested on only on Mac respect to [80241]. I will check it soon on Windows.

  • boost/thread/pthread/condition_variable_fwd.hpp

     
    229229            unique_lock<mutex>& lock,
    230230            struct timespec const &timeout);
    231231    };
     232
     233    void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
    232234}
    233235
     236
    234237#include <boost/config/abi_suffix.hpp>
    235238
    236239#endif
  • boost/thread/pthread/thread_data.hpp

     
    88
    99#include <boost/thread/detail/config.hpp>
    1010#include <boost/thread/exceptions.hpp>
     11#include <boost/thread/locks.hpp>
    1112#include <boost/shared_ptr.hpp>
    1213#include <boost/enable_shared_from_this.hpp>
    1314#include <boost/thread/mutex.hpp>
     
    117118            typedef pthread_t native_handle_type;
    118119
    119120            virtual void run()=0;
     121            virtual void notify_all_at_thread_exit(condition_variable*, mutex*)=0;
    120122        };
    121123
    122124        BOOST_THREAD_DECL thread_data_base* get_current_thread_data();
  • boost/thread/detail/thread.hpp

     
    2323#include <boost/bind.hpp>
    2424#include <stdlib.h>
    2525#include <memory>
     26#include <vector>
     27#include <utility>
    2628#include <boost/utility/enable_if.hpp>
    2729#include <boost/type_traits/remove_reference.hpp>
    2830#include <boost/io/ios_state.hpp>
     
    7375            {
    7476                f();
    7577            }
     78            typedef std::vector<std::pair<condition_variable*, mutex*>
     79            //, hidden_allocator<std::pair<condition_variable*, mutex*> >
     80            > notify_list_t;
     81            notify_list_t notify;
     82            void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
     83            {
     84              notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
     85            }
     86            ~thread_data()
     87            {
     88              for (notify_list_t::iterator i = notify.begin(), e = notify.end();
     89                      i != e; ++i)
     90              {
     91                  i->second->unlock();
     92                  i->first->notify_all();
     93              }
     94
     95            }
    7696        private:
    7797            F f;
    7898        };
     
    92112            {
    93113                f();
    94114            }
     115            typedef std::vector<std::pair<condition_variable*, mutex*>
     116            //, hidden_allocator<std::pair<condition_variable*, mutex*> >
     117            > notify_list_t;
     118            notify_list_t notify;
     119            void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
     120            {
     121              notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
     122            }
    95123        };
    96124
    97125        template<typename F>
     
    109137            {
    110138                f();
    111139            }
     140            typedef std::vector<std::pair<condition_variable*, mutex*>
     141            //, hidden_allocator<std::pair<condition_variable*, mutex*> >
     142            > notify_list_t;
     143            notify_list_t notify;
     144            void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
     145            {
     146              notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
     147            }
    112148        };
    113149    }
    114150
  • boost/thread/win32/condition_variable.hpp

     
    510510#endif
    511511    };
    512512
     513    void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
    513514}
    514515
    515516#include <boost/config/abi_suffix.hpp>
  • boost/thread/win32/thread_data.hpp

     
    1111#include <boost/thread/thread_time.hpp>
    1212#include <boost/thread/win32/thread_primitives.hpp>
    1313#include <boost/thread/win32/thread_heap_alloc.hpp>
     14#include <boost/thread/win32/condition_variable.hpp>
     15#include <boost/thread/locks.hpp>
    1416#include <map>
    1517#ifdef BOOST_THREAD_USES_CHRONO
    1618#include <boost/chrono/system_clocks.hpp>
     
    117119            typedef detail::win32::handle native_handle_type;
    118120
    119121            virtual void run()=0;
     122            virtual void notify_all_at_thread_exit(condition_variable*, mutex*)=0;
     123
    120124        };
    121125
    122126        typedef boost::intrusive_ptr<detail::thread_data_base> thread_data_ptr;
  • libs/thread/test/threads/thread/members/detach_pass.cpp

     
    1717
    1818// void detach();
    1919
     20#define BOOST_THREAD_VESRION 3
     21
    2022#include <boost/thread/thread.hpp>
    2123#include <new>
    2224#include <cstdlib>
  • libs/thread/test/sync/conditions/notify_all_at_thread_exit_pass.cpp

     
     1//===----------------------------------------------------------------------===//
     2//
     3//                     The LLVM Compiler Infrastructure
     4//
     5// This file is dual licensed under the MIT and the University of Illinois Open
     6// Source Licenses. See LICENSE.TXT for details.
     7//
     8//===----------------------------------------------------------------------===//
     9// Copyright (C) 2011 Vicente J. Botet Escriba
     10//
     11//  Distributed under the Boost Software License, Version 1.0. (See accompanying
     12//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     13
     14// <boost/thread/condition_variable.hpp>
     15
     16// void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
     17
     18#define BOOST_THREAD_USES_MOVE
     19#define BOOST_THREAD_VESRION 3
     20
     21#include <boost/thread/condition_variable.hpp>
     22#include <boost/thread/mutex.hpp>
     23#include <boost/thread/locks.hpp>
     24#include <boost/thread/thread.hpp>
     25#include <boost/chrono/chrono.hpp>
     26#include <boost/detail/lightweight_test.hpp>
     27
     28boost::condition_variable cv;
     29boost::mutex mut;
     30
     31typedef boost::chrono::milliseconds ms;
     32typedef boost::chrono::high_resolution_clock Clock;
     33
     34void func()
     35{
     36  boost::unique_lock < boost::mutex > lk(mut);
     37  boost::notify_all_at_thread_exit(cv, boost::move(lk));
     38  boost::this_thread::sleep_for(ms(300));
     39}
     40
     41int main()
     42{
     43  boost::unique_lock < boost::mutex > lk(mut);
     44  boost::thread(func).detach();
     45  Clock::time_point t0 = Clock::now();
     46  cv.wait(lk);
     47  Clock::time_point t1 = Clock::now();
     48  BOOST_TEST(t1 - t0 > ms(250));
     49  return boost::report_errors();
     50}
     51
  • libs/thread/test/Jamfile.v2

    Property changes on: libs/thread/test/sync/conditions/notify_all_at_thread_exit_pass.cpp
    ___________________________________________________________________
    Added: svn:mime-type
       + text/plain
    Added: svn:keywords
       + Id
    Added: svn:eol-style
       + native
    
     
    225225          [ thread-run2 ./sync/conditions/condition_variable_any/wait_until_pass.cpp : condition_variable_any__wait_until_p ]
    226226          [ thread-run2 ./sync/conditions/condition_variable_any/wait_until_pred_pass.cpp : condition_variable_any__wait_until_pred_p ]
    227227          [ thread-run2 ./sync/conditions/cv_status/cv_status_pass.cpp : cv_status__cv_status_p ]
     228          [ thread-run2 ./sync/conditions/notify_all_at_thread_exit_pass.cpp : notify_all_at_thread_exit_p ]
    228229    ;
    229230
    230231    explicit ts_async ;
  • libs/thread/src/win32/thread.cpp

     
    2020#include <stdio.h>
    2121#include <boost/thread/once.hpp>
    2222#include <boost/thread/tss.hpp>
     23#include <boost/thread/condition_variable.hpp>
    2324#include <boost/assert.hpp>
    2425#include <boost/throw_exception.hpp>
    2526#include <boost/thread/detail/tss_hooks.hpp>
     
    240241
    241242            void run()
    242243            {}
     244            void notify_all_at_thread_exit(condition_variable*, mutex*)
     245            {}
     246
    243247        private:
    244248            externally_launched_thread(externally_launched_thread&);
    245249            void operator=(externally_launched_thread&);
     
    682686        boost::run_thread_exit_callbacks();
    683687    }
    684688
     689    void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
     690    {
     691      detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
     692      if(current_thread_data)
     693      {
     694        current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
     695      }
     696    }
    685697}
    686698
    687699
  • libs/thread/src/pthread/thread.cpp

     
    1010
    1111#include <boost/thread/thread.hpp>
    1212#include <boost/thread/xtime.hpp>
    13 #include <boost/thread/condition.hpp>
     13#include <boost/thread/condition_variable.hpp>
    1414#include <boost/thread/locks.hpp>
    1515#include <boost/thread/once.hpp>
    1616#include <boost/thread/tss.hpp>
     
    175175
    176176            void run()
    177177            {}
     178            void notify_all_at_thread_exit(condition_variable*, mutex*)
     179            {}
    178180
    179181        private:
    180182            externally_launched_thread(externally_launched_thread&);
     
    677679            }
    678680        }
    679681    }
     682    void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
     683    {
     684      detail::thread_data_base* const current_thread_data(detail::get_current_thread_data());
     685      if(current_thread_data)
     686      {
     687        current_thread_data->notify_all_at_thread_exit(&cond, lk.release());
     688      }
     689    }
    680690
    681691
     692
    682693}